110 lines
2.9 KiB
Plaintext
110 lines
2.9 KiB
Plaintext
/*
|
|
Copyright (c) 2018 Muresan Vlad Mihail
|
|
Contact Info muresanvladmihail@gmail.com murii@tilde.team
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
including commercial applications, and to alter it and redistribute it
|
|
freely, subject to the following restrictions:
|
|
|
|
The origin of this software must not be misrepresented; you must not
|
|
claim that you wrote the original software. Shall you use this software
|
|
in a product, an acknowledgment and the contact info(if there is any)
|
|
of the author(s) must be placed in the product documentation.
|
|
This notice may not be removed or altered from any source distribution.
|
|
|
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT.
|
|
IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT,
|
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
import libc {...}
|
|
|
|
|
|
priv data:char* = """[
|
|
player:{
|
|
player_x=200;
|
|
player_y=300;
|
|
minor:{
|
|
a=1;
|
|
b=3;
|
|
}
|
|
|
|
minor2:{
|
|
hah= vlad;
|
|
minor2_sub_minor1:{
|
|
heh=dalv;
|
|
}
|
|
minor2_sub_minor2:{
|
|
heha=lvda;
|
|
}
|
|
}
|
|
}
|
|
|
|
enemy:{
|
|
damage=10;
|
|
speed=120;
|
|
}
|
|
""";
|
|
|
|
|
|
priv func print_sub_parent(parent:save_data_parent*) {
|
|
for (i := 0; i < parent.sub_parents; i++) {
|
|
p:save_data_parent* = parent.sub_parent[i];
|
|
print_paires(p);
|
|
if (p.has_sub_parent) {
|
|
print_sub_parent(p);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
priv func print_paires(parent:save_data_parent*) {
|
|
for (i := 0; i < parent.total; i++) {
|
|
printf("Key: %s, Value: %s in parent: %s, id: %zu \n", parent.keys[i], parent.values[i], parent.name, parent.id);
|
|
}
|
|
}
|
|
|
|
|
|
priv func print_parent(parent:save_data_parent*) {
|
|
print_paires(parent);
|
|
if (parent.has_sub_parent) {
|
|
print_sub_parent(parent);
|
|
}
|
|
}
|
|
|
|
|
|
priv func print_all(save:save_data*) {
|
|
for (i := 0; i < save.total_parents; i++) {
|
|
p:save_data_parent* = save.parents[i];
|
|
print_parent(p);
|
|
}
|
|
}
|
|
|
|
|
|
func main(argc:int, argv:char**):int {
|
|
|
|
save:save_data;
|
|
save_data_init(&save, "player.stat"); //Creates and overrides file "player.stat"
|
|
|
|
manually:char* = save_data_serialize_parent("programatically1", "foo", "42", "", 32);
|
|
manually2:char* = save_data_serialize_parent("programatically2", "foo", "42", manually, 64);
|
|
|
|
save_data_write(&save, data, true);
|
|
save_data_write(&save, manually, false);
|
|
save_data_write(&save, manually2, false);
|
|
save_data_write(&save, "]", false);
|
|
|
|
// Read back what we have saved
|
|
save_data_read(&save);
|
|
|
|
printf("Total parents: %zu\n", save.total_parents);
|
|
|
|
print_all(&save);
|
|
|
|
save_data_free(&save);
|
|
free(manually);
|
|
free(manually2);
|
|
return 0;
|
|
}
|
|
|