-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.c
106 lines (90 loc) · 2.58 KB
/
resources.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "resources.h"
//obj_resources*
//resources_init(){
// return(calloc(1,sizeof(obj_resources)));}
obj_resources*
resourcesFinalize(obj_resources* this){
this->finalize=resourcesFinalize;
this->free=resourcesFree;
this->clean=resourcesClean;
//this->copy=resourcesCopy;
//CAT(obj,T)* (*copyDeep)(CAT(obj,T)* p_struct);
this->copyTo=NULL;
this->objSize=sizeof(obj_resources);
//uint16_t objName;
this->vers=1;
TEMPLATE3(arr,Finalize,obj_ship)(&this->shipTemplates);
OBJF(obj_map,finalize)(&this->map);
return(this);}
void
resourcesFree(obj_resources* this){
NULL_P_CHECK(this);
TEMPLATE3(arr,Clean,obj_ship)(&this->shipTemplates);
OBJF(obj_map,clean)(&this->map);
free(this);
return;}
void
resourcesClean(obj_resources* this){
NULL_P_CHECK(this);
TEMPLATE3(arr,Clean,obj_ship)(&this->shipTemplates);
OBJF(obj_map,clean)(&this->map);
return;}
obj_resources*
resourcesCopy(obj_resources* this){
NULL_P_CHECK(this);
obj_resources* ptr=calloc(1,sizeof(obj_resources));
NULL_P_CHECK(ptr);
TEMPLATE3(arr,Finalize,obj_ship)(&ptr->shipTemplates);
TEMPLATE3(arr,Copyto,obj_ship)(&this->shipTemplates,&ptr->shipTemplates);
return(ptr);}
int
resourcesParse(obj_resources* this, json_stream* js){
NULL_P_CHECK(this);
NULL_P_CHECK(js);
enum json_type type;
const char* str=json_get_string(js,NULL);
obj_ship* obj_ship=NULL;
bool value,arrloop=true,var=false;
//double number;
//bool loop=true;
type=json_next(js);
if(type!=JSON_OBJECT)return(2);
while(true){
type=json_next(js);
value=false;
switch(type){
case(JSON_DONE):
return(0);
case JSON_ERROR:
PARSE_EMSG(js,json_typename[type]);
fprintf(stderr,"json ERR %s\n",\
json_get_error(js));
exit(1);
case(JSON_STRING):
value=true;
break;
case(JSON_OBJECT_END):
if(json_peek(js)==JSON_OBJECT_END)json_next(js);
continue;
default:
PARSE_EMSG(js,json_typename[type]);
exit(1);
break;}
if(value){
parseVarINT(js,vers);
parseARRobj(js,shipTemplates,obj_ship,shipParse,&this->shipTemplates)
parseOBJ(js,mapParse,map);
fprintf(stderr,"json %s found invalid key %s\n",__func__,str);
type=json_next(js);
fprintf(stderr,"with value %s\n",str);
}}}
int
resources_Dump(obj_resources* this){
NULL_P_CHECK(this);
fprintf(stderr,"\n\ndumping obj_resources at %p :\n",(void*)this);
fprintf(stderr,"vers: %d\n",this->vers);
fprintf(stderr,"shipTemplates arr at %p:\n",(void*)&this->shipTemplates);
TEMPLATE3(arr,dump,obj_ship)(&this->shipTemplates);
OBJF(obj_map,print)(&this->map);
fprintf(stderr,"\nEND of obj_resources at %p :\n",(void*)this);
return(0);}