Open borjasotomayor opened 3 years ago
Below is a summary of the existing WDL++/WDZ documentation and some proposed updates/clarifications to how the directory structure is handled such that it can be cleanly coupled with a revamped libobj object store. The following is subject to updates and review
The following is a compilation of all documentation for WDL++
Source code from- https://github.com/uchicago-cs/chiventure/tree/dev/src/wdl/sandbox
Characteristics:
"ROOMS"
, "GAME"
, etc defined directly in the fileReference- https://github.com/uchicago-cs/chiventure/wiki/What-WDL---will-look-like
Characteristics:
Reference- https://github.com/uchicago-cs/chiventure/wiki/WDL:-Looking-into-options-to-store-JSON-objects
Characteristics:
Characteristics
./ROOMS.json
gets translated to the "ROOMS"
component in the object store)./ITEMS/staff.json
gets translated to "ITEMS.staff"
)For determing how files in WDZ are translated into the object store, the following convention is proposed:
<filename>.json
- all definitions are translated into "<filename>.<definition>"
./<folder>/<filename>.json
- all definitions are translated into "<folder>.<filename>.<definition>"
DEFAULT.json
- all definitions are translated directly into the object store as is in the context of the file as "<definition>"
./<folder>/DEFAULT.json
- all definitions are translated directly into the object store as is in the context of the file as "<folder>.<definition>"
As an example, consider the following combination of files/folders
sample-game.wdz zip file structure
- DEFAULT.json
- ROOMS.json
- ITEMS/
- DEFAULT.json
- staff.json
- MEDIA/
- creak.mp4
default.json
{
"GAME":
{
"name": "sample-game"
}
}
ROOMS.json
{
"hall":
{
"name": "hall",
"items": "wood-staff"
}
}
ITEMS/default.json
{
"orb":
{
"name": "big-orb"
}
}
ITEMS/staff.json
{
"name": "wood-staff"
"sound": "creak.mp4"
}
The above WDZ file would then get parse into libobj 3.0 as the following:
GAME.name = sample-game
ROOMS.hall.name = hall
ROOMS.hall.items = wood-staff
ITEMS.orb.name = big-orb
ITEMS.staff.name = wood-staff
ITEMS.staff.sound = creak.mp4
The following is a sample proposed API for libobj 3.0 that is capable of tightly coupling with a folder/file JSON storage format. Key components are:
For more examples of dot notation for object retrieval, this is based on the original libobj style. See https://github.com/uchicago-cs/chiventure/blob/libobj/src/libobj/examples/obj.c
// All datatypes that can be encoded in an obj
typedef enum type
{
TYPE_ERROR = -1,
TYPE_NONE = 0,
TYPE_BOOL = 1,
TYPE_CHAR = 2,
TYPE_INT = 3,
TYPE_STR = 4,
TYPE_LUA = 5,
TYPE_LIST = 6,
} type_t;
/* A simple object model using strings as attribute identifiers */
typedef struct obj
{
// The identifier of the object- must be unique for the parent object
char id[MAXLEN_ID + 1];
// The type of the data
type_t type;
// The data associated with the object
union
{
bool b;
char c;
int i;
char *s;
char *lua;
} data;
// The object's attributes (a hash table)
struct obj *attr;
// For if the obj is part of a list
struct obj *next;
struct obj *prev;
// Required uthash identifier for making the hash table
UT_hash_handle hh;
} obj_t;
// Lists are just objects using utlist
typedef obj_t obj_list_t;
// Object creation/deletion
obj_t *obj_new(char *id);
int obj_init(obj_t *obj, char *id);
int obj_free(obj_t *obj);
int obj_free_all(obj_t *obj);
// Getters
obj_t *obj_get_attr(obj_t *obj, char *id, bool create);
type_t obj_get_type(obj_t *obj, char *id);
bool obj_get_bool(obj_t *obj, char *id);
char obj_get_char(obj_t *obj, char *id);
int obj_get_int (obj_t *obj, char *id);
char *obj_get_str (obj_t *obj, char *id);
obj_list_t *obj_get_list(obj_t *obj, char *id);
// Setters
int obj_add_attr(obj_t *obj, char *id, obj_t *attr);
int obj_set_bool(obj_t *obj, char *id, bool value);
int obj_set_char(obj_t *obj, char *id, char value);
int obj_set_int (obj_t *obj, char *id, int value);
int obj_set_str (obj_t *obj, char *id, char *value);
It might be worthwhile to see if some fancy macro stuff could be done to clean up the function calls (like OBJ_GET(objstore, "ROOMS.hall.name", str)
)
Notes from the first review of the above items:
Better way to designate object references:
"location":{
"__ref":"object",
"id":"ROOMS.purple room"
}
TYPE_ASSET
)TYPE_REFERENCE
)?TYPE_OBJECT
)data
unionTYPE_LUA
for now; will revisit how it can be incorporated laterobj_list_t
to the data
unionA sample wdz file has been produced incorporating the proposed changes. It can be found at: https://github.com/uchicago-cs/chiventure/tree/wdz_revamp/games/test_game
This is a translation of an older test game located at: https://github.com/uchicago-cs/chiventure/blob/dev/games/test_game.wdl
Based on the experiences from the last two years, it has become clear that chiventure needs a unified object store where all the various components can store their data. This will largely involve the following: