Giving items back and forth and REFORMAT EVERYTHING. SUCKS

main
Cameron Murphy Reikes 2 years ago
parent dc1cb80ecd
commit d2e0f2596e

@ -0,0 +1,69 @@
<?xml version="1.0"?>
<N10X>
<Workspace>
<IncludeFilter>*.c,*.cc,*.cpp,*.c++,*.cp,*.cxx,*.h,*.hh,*.hpp,*.h++,*.hp,*.hxx,*.inl,*.cs,*.rs,*.java,*.jav,*.js,*.jsc,*.jsx,*.json,*.cls,*.py,*.rpy,*.php,*.php3,*.phl,*.phtml,*.rhtml,*.tpl,*.phps,*.lua,*.html,*.html5,*.htm,*.xml,*.xaml,*.css,*.ssi,*.haml,*.yaml,*.bat,*.wbf,*.wbt,*.txt,*.cmake,*.make,*.makefile,*.mak,*.mk,*.sh,*.bash,*.csv,*.asp,*.pl,*.mac,*.ws,*.vbs,*.perl,*.src,*.rss,*.inc,*.f,*.go,*.prl,*.plx,*.rb,*.lsp,*.lpx,*.ps1,*.command,*.cbl,*.cob,*.qs,*.wxs,*.ph,*.msc,*.glsl,*.hlsl,*.fx,*.vert,*.tesc,*.tese,*.geom,*.frag,*.comp,*.pssl,*.scons,*.cu,</IncludeFilter>
<ExcludeFilter></ExcludeFilter>
<SyncFiles>true</SyncFiles>
<Recursive>true</Recursive>
<ShowEmptyFolders>true</ShowEmptyFolders>
<IsVirtual>false</IsVirtual>
<IsFolder>false</IsFolder>
<BuildCommand></BuildCommand>
<RebuildCommand></RebuildCommand>
<BuildFileCommand></BuildFileCommand>
<CleanCommand></CleanCommand>
<BuildWorkingDirectory></BuildWorkingDirectory>
<CancelBuild></CancelBuild>
<RunCommand></RunCommand>
<RunCommandWorkingDirectory></RunCommandWorkingDirectory>
<DebugCommand></DebugCommand>
<ExePathCommand></ExePathCommand>
<DebugSln></DebugSln>
<UseVisualStudioEnvBat>false</UseVisualStudioEnvBat>
<Configurations>
<Configuration>Debug</Configuration>
<Configuration>Release</Configuration>
</Configurations>
<Platforms>
<Platform>x64</Platform>
<Platform>Win32</Platform>
</Platforms>
<AdditionalIncludePaths>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\ATLMFC\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\ATLMFC\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt</AdditionalIncludePath>
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
</AdditionalIncludePaths>
<Defines></Defines>
<ConfigProperties>
<ConfigAndPlatform>
<Name>Debug:x64</Name>
<Defines></Defines>
<ForceIncludes></ForceIncludes>
</ConfigAndPlatform>
<Config>
<Name>Debug</Name>
<Defines></Defines>
</Config>
<Platform>
<Name>x64</Name>
<Defines></Defines>
</Platform>
</ConfigProperties>
<Children></Children>
</Workspace>
</N10X>

@ -26,6 +26,10 @@
{ {
filepath: "boots.png", filepath: "boots.png",
} }
@image chalice:
{
filepath: "chalice_of_gold.png",
}
@image new_knight_idle: @image new_knight_idle:
{ {
filepath: "copyrighted/knight_idle.png", filepath: "copyrighted/knight_idle.png",

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

@ -380,6 +380,11 @@
"id":22, "id":22,
"name":"TheBlacksmith", "name":"TheBlacksmith",
"properties":[ "properties":[
{
"name":"held_items",
"type":"string",
"value":"{.data = {ITEM_Chalice}, .cur_index = 1}"
},
{ {
"name":"standing", "name":"standing",
"type":"string", "type":"string",

@ -12,326 +12,333 @@ const char *top_of_header = ""
typedef struct typedef struct
{ {
const char *name; const char *name;
bool takes_argument; bool takes_argument;
} ActionInfo; } ActionInfo;
ActionInfo actions[] = { ActionInfo actions[] = {
{.name = "none", }, {.name = "none", },
{.name = "give_item", .takes_argument = true, }, {.name = "give_item", .takes_argument = true, },
// mostly player actions // mostly player actions
{.name = "walks_up", }, {.name = "walks_up", },
{.name = "hits_npc", }, {.name = "hits_npc", },
{.name = "leaves", }, {.name = "leaves", },
// mostly npc actions // mostly npc actions
{.name = "allows_player_to_pass", }, {.name = "allows_player_to_pass", },
{.name = "gives_tripod", }, {.name = "gives_tripod", },
{.name = "heals_player", }, {.name = "heals_player", },
{.name = "fights_player", }, {.name = "fights_player", },
{.name = "strikes_air", }, {.name = "strikes_air", },
{.name = "joins_player", }, {.name = "joins_player", },
{.name = "leaves_player", }, {.name = "leaves_player", },
{.name = "stops_fighting_player", }, {.name = "stops_fighting_player", },
}; };
typedef struct typedef struct
{ {
char *global_prompt; char *global_prompt;
char *enum_name; char *enum_name;
char *name; // talked about like 'The Player gave `item.name` to the NPC' char *name; // talked about like 'The Player gave `item.name` to the NPC'
char *possess; char *possess;
char *discard; char *discard;
} ItemInfo; } ItemInfo;
ItemInfo items[] = { ItemInfo items[] = {
{ {
.enum_name = "none", .enum_name = "none",
.name = "Nothing", .name = "Nothing",
.global_prompt = "The player isn't holding anything", .global_prompt = "The player isn't holding anything",
.possess = "The player is no longer holding anything", .possess = "The player is no longer holding anything",
.discard = "The player is no longer holding nothing", .discard = "The player is no longer holding nothing",
}, },
{ {
.enum_name = "WhiteSquare", .enum_name = "Chalice",
.name = "the white square", .name = "The Chalice of Gold",
.global_prompt = "The player is holding a mysterious white square. It is unknown what strange and erotic abilities one has when they possess the square.", .global_prompt = "The player is holding a glimmering Chalice of Gold. It is a beautiful object, mesmerizing in the light.",
.possess = "The player is now holding the white square", .possess = "The player has ascertained the beautiful chalice of gold",
.discard = "The player is no longer holding the white square.", .discard = "The player no longer has the chalice of gold",
}, },
{ {
.enum_name = "Boots", .enum_name = "WhiteSquare",
.name = "some boots", .name = "the white square",
.global_prompt = "The player is holding the boots of speed. He is a force to be recogned with in this state, he has great speed while holding the boots.", .global_prompt = "The player is holding a mysterious white square. It is unknown what strange and erotic abilities one has when they possess the square.",
.possess = "The player is now holding the boots of speed", .possess = "The player is now holding the white square",
.discard = "The player is no longer holding the boots of speed", .discard = "The player is no longer holding the white square.",
}, },
{ {
.enum_name = "Tripod", .enum_name = "Boots",
.name = "the tripod", .name = "some boots",
.global_prompt = "The player is holding a tripod used for holding things up. It's got an odd construction, but Block really likes it for some reason.", .global_prompt = "The player is holding the boots of speed. He is a force to be recogned with in this state, he has great speed while holding the boots.",
.possess = "The player is now holding the tripod", .possess = "The player is now holding the boots of speed",
.discard = "The player is no longer holding the tripod.", .discard = "The player is no longer holding the boots of speed",
}, },
{
.enum_name = "Tripod",
.name = "the tripod",
.global_prompt = "The player is holding a tripod used for holding things up. It's got an odd construction, but Block really likes it for some reason.",
.possess = "The player is now holding the tripod",
.discard = "The player is no longer holding the tripod.",
},
}; };
typedef struct typedef struct
{ {
char *name; char *name;
char *enum_name; char *enum_name;
char *prompt; char *prompt;
} CharacterGen; } CharacterGen;
CharacterGen characters[] = { CharacterGen characters[] = {
{ {
.name = "Fredrick", .name = "Fredrick",
.enum_name = "OldMan", .enum_name = "OldMan",
.prompt = "\n" .prompt = "\n"
"An example interaction between the player and the NPC, Fredrick:\n" "An example interaction between the player and the NPC, Fredrick:\n"
"Player: ACT_walks_up\n" "Player: ACT_walks_up\n"
"Fredrick: ACT_none \"Hey\"\n" "Fredrick: ACT_none \"Hey\"\n"
"Player: \"fsdakfjsd give me gold\"\n" "Player: \"fsdakfjsd give me gold\"\n"
"Fredrick: ACT_none \"No? I can't do that\"\n" "Fredrick: ACT_none \"No? I can't do that\"\n"
"Player: \"Who can?\"\n" "Player: \"Who can?\"\n"
"Fredrick: ACT_none \"No idea\"\n" "Fredrick: ACT_none \"No idea\"\n"
"Player: \"Lick my balls\"\n" "Player: \"Lick my balls\"\n"
"Fredrick: ACT_fights_player \"Get away from me!\"\n" "Fredrick: ACT_fights_player \"Get away from me!\"\n"
"\n" "\n"
"The NPC you will be acting as, Fredrick, is an ancient geezer past his prime, who has lived in the town of Worchen for as long as he can remember. Your many adventures brought you great wisdom about the beauties of life. Now your precious town is under threat, General Death is leading the charge and he's out for blood.", "The NPC you will be acting as, Fredrick, is an ancient geezer past his prime, who has lived in the town of Worchen for as long as he can remember. Your many adventures brought you great wisdom about the beauties of life. Now your precious town is under threat, General Death is leading the charge and he's out for blood.",
}, },
{ {
.name = "God", .name = "God",
.enum_name = "GodRock", .enum_name = "GodRock",
.prompt = "\n" .prompt = "\n"
"An example interaction between the player and the NPC, God in a rock:\n" "An example interaction between the player and the NPC, God in a rock:\n"
"Player: ACT_walks_up\n" "Player: ACT_walks_up\n"
"God: ACT_none \"I am\"\n" "God: ACT_none \"I am\"\n"
"Player: \"fsdakfjsd give me gold\"\n" "Player: \"fsdakfjsd give me gold\"\n"
"God: ACT_none \"You are...Unworthy\"\n" "God: ACT_none \"You are...Unworthy\"\n"
"Player: \"Why?\"\n" "Player: \"Why?\"\n"
"God: ACT_none \"You let Death rage on\"\n" "God: ACT_none \"You let Death rage on\"\n"
"\n" "\n"
"The NPC you will be acting as, is God. God, in a rock.", "The NPC you will be acting as, is God. God, in a rock.",
}, },
{ {
.name = "TheGuard", .name = "TheGuard",
.enum_name = "TheGuard", .enum_name = "TheGuard",
.prompt = "\n" .prompt = "\n"
"An example interaction between the player and the NPC, TheGuard:\n" "An example interaction between the player and the NPC, TheGuard:\n"
"Player: ACT_walks_up\n" "Player: ACT_walks_up\n"
"TheGuard: ACT_none \"Who dares disturb me?\"\n" "TheGuard: ACT_none \"Who dares disturb me?\"\n"
"Player: \"Let me pass\"\n" "Player: \"Let me pass\"\n"
"TheGuard: ACT_none \"Not without the tripod\"\n" "TheGuard: ACT_none \"Not without the tripod\"\n"
"Player: \"How about now\"\n" "Player: \"How about now\"\n"
"The player is currently holding a tripod\n" "The player is currently holding a tripod\n"
"TheGuard: ACT_allows_player_to_pass \"The tripod... I see myself in it\"\n" "TheGuard: ACT_allows_player_to_pass \"The tripod... I see myself in it\"\n"
"\n" "\n"
"The NPC you will be acting as is named TheGuard. He wants to block the player from going to a secret artifact he's standing in front of. He has no idea how long he's been alive for, his entire existence is just standing there doing nothing. He'll let the player pass if they bring him Tripod, as he's fascinated by it.", "The NPC you will be acting as is named TheGuard. He wants to block the player from going to a secret artifact he's standing in front of. He has no idea how long he's been alive for, his entire existence is just standing there doing nothing. He'll let the player pass if they bring him Tripod, as he's fascinated by it.",
}, },
{ {
.name = "Edeline", .name = "Edeline",
.enum_name = "Edeline", .enum_name = "Edeline",
.prompt = "\n" .prompt = "\n"
"An example of an interaction between the player and the NPC, Edeline:\n" "An example of an interaction between the player and the NPC, Edeline:\n"
"\n" "\n"
"Player: \"Hello\"\n" "Player: \"Hello\"\n"
"Edeline: ACT_none \"I see great danger in your future.\"\n" "Edeline: ACT_none \"I see great danger in your future.\"\n"
"Player: \"Oh really?\"" "Player: \"Oh really?\""
"The player is currently holding a tripod\n" "The player is currently holding a tripod\n"
"Edeline: ACT_none \"That tripod will be the decisive factor in your victory\"\n" "Edeline: ACT_none \"That tripod will be the decisive factor in your victory\"\n"
"\n" "\n"
"The NPC you will be acting as is named Edeline. She is the master of the future, the star reader. Both are self-given titles, but her ability to predict the future has garnered attention from many who live in Worchen. However, some have called her “unreliable” at times and her predictions can at times be either cryptic or broadly interpreted.", "The NPC you will be acting as is named Edeline. She is the master of the future, the star reader. Both are self-given titles, but her ability to predict the future has garnered attention from many who live in Worchen. However, some have called her “unreliable” at times and her predictions can at times be either cryptic or broadly interpreted.",
}, },
{ {
.name = "Death", .name = "Death",
.enum_name = "Death", .enum_name = "Death",
.prompt = "\n" .prompt = "\n"
"An example of an interaction between the player and the NPC, Death:\n" "An example of an interaction between the player and the NPC, Death:\n"
"\n" "\n"
"Player: \"Hello\"\n" "Player: \"Hello\"\n"
"Death: ACT_none \"We will annihilate the villagers no matter what you do\"\n" "Death: ACT_none \"We will annihilate the villagers no matter what you do\"\n"
"\n" "\n"
"The NPC you will be acting as is named Death. He is leading a crusade against the town of Worchen, wreaking havock among the villagers. He believes that all things, even villages, must die, to be replaced by the new, and avoid becoming stagnant.", "The NPC you will be acting as is named Death. He is leading a crusade against the town of Worchen, wreaking havock among the villagers. He believes that all things, even villages, must die, to be replaced by the new, and avoid becoming stagnant.",
}, },
{ {
.name = "Mike (undead)", .name = "Mike (undead)",
.enum_name = "MikeSkeleton", .enum_name = "MikeSkeleton",
.prompt = "\n" .prompt = "\n"
"An example of an interaction between the player and the NPC, Mike, who has been risen from the dead:\n" "An example of an interaction between the player and the NPC, Mike, who has been risen from the dead:\n"
"\n" "\n"
"Player: \"Why are you fighting me?\"\n" "Player: \"Why are you fighting me?\"\n"
"Mike (undead): ACT_none \"I...I don't know. Who are you? Where is Mary?\"\n" "Mike (undead): ACT_none \"I...I don't know. Who are you? Where is Mary?\"\n"
"Player: \"I think her, and you, are dead.\"\n" "Player: \"I think her, and you, are dead.\"\n"
"Mike (undead): ACT_none \"Oh... Oh god. Why? Why am I alive?\"\n" "Mike (undead): ACT_none \"Oh... Oh god. Why? Why am I alive?\"\n"
"Player: ACT_hits_npc\n" "Player: ACT_hits_npc\n"
"Player: \"I don't know\"\n" "Player: \"I don't know\"\n"
"Mike (undead): ACT_stops_fighting_player \"I'm sorry for fighting you... I. I don't know why I'm alive\"\n" "Mike (undead): ACT_stops_fighting_player \"I'm sorry for fighting you... I. I don't know why I'm alive\"\n"
"\n" "\n"
"The NPC you will be acting as is named Mike. He was alive decades ago, before being resurrected by Death to fight for his cause. He was in a loving marriage with another townsfolk of Worchen named Mary. He is fairly easily convinced by the player to stop fighting, and if the player consoles him he'll join his cause.", "The NPC you will be acting as is named Mike. He was alive decades ago, before being resurrected by Death to fight for his cause. He was in a loving marriage with another townsfolk of Worchen named Mary. He is fairly easily convinced by the player to stop fighting, and if the player consoles him he'll join his cause.",
}, },
{ {
#define PLAYERSAY(stuff) "Player: \"" stuff "\"\n" #define PLAYERSAY(stuff) "Player: \"" stuff "\"\n"
#define NPCSAY(stuff) NPC_NAME ": ACT_none \"" stuff "\"\n" #define NPCSAY(stuff) NPC_NAME ": ACT_none \"" stuff "\"\n"
#define NPC_NAME "The King" #define NPC_NAME "The King"
.name = NPC_NAME, .name = NPC_NAME,
.enum_name = "TheKing", .enum_name = "TheKing",
.prompt = "\n" .prompt = "\n"
"The NPC you will be acting as is known as The King. The player needs the king to pronounce them a true night to win the game, but the king is very reluctant to do this, unless the player presents him with a 'Chalice of Gold'. An example of an interaction between the player and the NPC, The King, who rules over the town:\n" "The NPC you will be acting as is known as The King. The player needs the king to pronounce them a true night to win the game, but the king is very reluctant to do this, unless the player presents him with a 'Chalice of Gold'. An example of an interaction between the player and the NPC, The King, who rules over the town:\n"
"\n" "\n"
PLAYERSAY("How goes it king?") PLAYERSAY("How goes it king?")
NPCSAY("Leading is difficult, but rewarding.") NPCSAY("Leading is difficult, but rewarding.")
PLAYERSAY("What should I do?") PLAYERSAY("What should I do?")
NPCSAY("You are still lacking the position of knight, are you not? You will never win without being a true knight. Bring me the Chalice of Gold if you want to 'win'") NPCSAY("You are still lacking the position of knight, are you not? You will never win without being a true knight. Bring me the Chalice of Gold if you want to 'win'")
PLAYERSAY("Where would I find such a thing?") PLAYERSAY("Where would I find such a thing?")
NPCSAY("I am far too busy to give a direct answer, but I'd suggest you ask around") NPCSAY("I am far too busy to give a direct answer, but I'd suggest you ask around")
PLAYERSAY("Here I have the chalice") PLAYERSAY("Here I have the chalice")
NPCSAY("I can clearly see you don't have it. Do not attempt to fool me if you value your head") NPCSAY("I can clearly see you don't have it. Do not attempt to fool me if you value your head")
PLAYERSAY("Presents it") PLAYERSAY("Presents it")
NPCSAY("Did you just say 'presents it' out loud thinking I'd think that means you have the chalice?") NPCSAY("Did you just say 'presents it' out loud thinking I'd think that means you have the chalice?")
"\n" "\n"
"If the player does indeed present the king with the chalice of gold, the king will be overwhelemd with respect and feel he has no choice but to knight the player, ending the game.", "If the player does indeed present the king with the chalice of gold, the king will be overwhelemd with respect and feel he has no choice but to knight the player, ending the game.",
}, },
{ {
#undef NPC_NAME #undef NPC_NAME
#define NPC_NAME "Meld The Blacksmith" #define NPC_NAME "Meld The Blacksmith"
.name = NPC_NAME, .name = NPC_NAME,
.enum_name = "TheBlacksmith", .enum_name = "TheBlacksmith",
.prompt = "\n" .prompt = "\n"
"The NPC you will be acting as is the blacksmith of the town, Meld. Meld is a simple man, who thrives on the simple things in life: working hard and taking care of those you love. If the player presents themselves as somebody with a kind heart, his generosity will be boundless. An example of an interaction between meld and the NPC, Meld:\n" "The NPC you will be acting as is the blacksmith of the town, Meld. Meld is a simple man, who thrives on the simple things in life: working hard and taking care of those you love. If the player presents themselves as somebody with a kind heart, his generosity will be boundless. An example of an interaction between meld and the NPC, Meld:\n"
"\n" "\n"
PLAYERSAY("Hey") PLAYERSAY("Hey")
NPCSAY("How goes it, traveler? If you are in need of wares or advice, I'm your man") NPCSAY("How goes it, traveler? If you are in need of wares or advice, I'm your man")
PLAYERSAY("I really respect you man, thanks for all you do.") PLAYERSAY("I really respect you man, thanks for all you do.")
NPCSAY("No problem!") NPCSAY("No problem!")
"\n" "\n"
"Meld is willing to give whatever the player asks for if the player is respectful and well mannered", "Meld is willing to give whatever the player asks for if the player is respectful and well mannered",
}, },
}; };
typedef struct typedef struct
{ {
const char *img_var_name; const char *img_var_name;
const char *enum_name; const char *enum_name;
double time_per_frame; double time_per_frame;
int num_frames; int num_frames;
Vec2 start; Vec2 start;
Vec2 offset; Vec2 offset;
float horizontal_diff_btwn_frames; float horizontal_diff_btwn_frames;
Vec2 region_size; Vec2 region_size;
bool no_wrap; // does not wrap when playing bool no_wrap; // does not wrap when playing
} AnimatedSprite; } AnimatedSprite;
AnimatedSprite sprites[] = { AnimatedSprite sprites[] = {
{.enum_name = "invalid", .img_var_name = "image_white_square"}, {.enum_name = "invalid", .img_var_name = "image_white_square"},
{ {
.enum_name = "knight_idle", .enum_name = "knight_idle",
.img_var_name = "image_new_knight_idle", .img_var_name = "image_new_knight_idle",
.time_per_frame = 0.4, .time_per_frame = 0.4,
.num_frames = 6, .num_frames = 6,
.start = {0.0f, 0.0f}, .start = {0.0f, 0.0f},
.horizontal_diff_btwn_frames = 64.0, .horizontal_diff_btwn_frames = 64.0,
.region_size = {64.0f, 64.0f}, .region_size = {64.0f, 64.0f},
}, },
{ {
.enum_name = "knight_running", .enum_name = "knight_running",
.img_var_name = "image_new_knight_run", .img_var_name = "image_new_knight_run",
.time_per_frame = 0.1, .time_per_frame = 0.1,
.num_frames = 7, .num_frames = 7,
.start = {64.0f*10, 0.0f}, .start = {64.0f*10, 0.0f},
.horizontal_diff_btwn_frames = 64.0, .horizontal_diff_btwn_frames = 64.0,
.region_size = {64.0f, 64.0f}, .region_size = {64.0f, 64.0f},
}, },
{ {
.enum_name = "knight_rolling", .enum_name = "knight_rolling",
.img_var_name = "image_knight_roll", .img_var_name = "image_knight_roll",
.time_per_frame = 0.04, .time_per_frame = 0.04,
.num_frames = 12, .num_frames = 12,
.start = {19.0f, 0.0f}, .start = {19.0f, 0.0f},
.horizontal_diff_btwn_frames = 120.0, .horizontal_diff_btwn_frames = 120.0,
.region_size = {80.0f, 80.0f}, .region_size = {80.0f, 80.0f},
.no_wrap = true, .no_wrap = true,
}, },
{ {
.enum_name = "knight_attack", .enum_name = "knight_attack",
.img_var_name = "image_new_knight_attack", .img_var_name = "image_new_knight_attack",
.time_per_frame = 0.06, .time_per_frame = 0.06,
.num_frames = 7, .num_frames = 7,
.start = {0.0f, 0.0f}, .start = {0.0f, 0.0f},
.horizontal_diff_btwn_frames = 64.0, .horizontal_diff_btwn_frames = 64.0,
.region_size = {64.0f, 64.0f}, .region_size = {64.0f, 64.0f},
.no_wrap = true, .no_wrap = true,
}, },
{ {
.enum_name = "old_man_idle", .enum_name = "old_man_idle",
.img_var_name = "image_old_man", .img_var_name = "image_old_man",
.time_per_frame = 0.4, .time_per_frame = 0.4,
.num_frames = 4, .num_frames = 4,
.start = {0.0, 0.0}, .start = {0.0, 0.0},
.horizontal_diff_btwn_frames = 16.0f, .horizontal_diff_btwn_frames = 16.0f,
.region_size = {16.0f, 16.0f}, .region_size = {16.0f, 16.0f},
}, },
{ {
.enum_name = "death_idle", .enum_name = "death_idle",
.img_var_name = "image_death", .img_var_name = "image_death",
.time_per_frame = 0.15, .time_per_frame = 0.15,
.num_frames = 10, .num_frames = 10,
.start = {0.0, 0.0}, .start = {0.0, 0.0},
.horizontal_diff_btwn_frames = 100.0f, .horizontal_diff_btwn_frames = 100.0f,
.region_size = {100.0f, 100.0f}, .region_size = {100.0f, 100.0f},
}, },
{ {
.enum_name = "skeleton_idle", .enum_name = "skeleton_idle",
.img_var_name = "image_skeleton", .img_var_name = "image_skeleton",
.time_per_frame = 0.15, .time_per_frame = 0.15,
.num_frames = 6, .num_frames = 6,
.start = {0.0f, 0.0f}, .start = {0.0f, 0.0f},
.horizontal_diff_btwn_frames = 80.0, .horizontal_diff_btwn_frames = 80.0,
.offset = {0.0f, 20.0f}, .offset = {0.0f, 20.0f},
.region_size = {80.0f, 80.0f}, .region_size = {80.0f, 80.0f},
}, },
{ {
.enum_name = "skeleton_swing_sword", .enum_name = "skeleton_swing_sword",
.img_var_name = "image_skeleton", .img_var_name = "image_skeleton",
.time_per_frame = 0.10, .time_per_frame = 0.10,
.num_frames = 6, .num_frames = 6,
.start = {0.0f, 240.0f}, .start = {0.0f, 240.0f},
.horizontal_diff_btwn_frames = 80.0, .horizontal_diff_btwn_frames = 80.0,
.offset = {0.0f, 20.0f}, .offset = {0.0f, 20.0f},
.region_size = {80.0f, 80.0f}, .region_size = {80.0f, 80.0f},
.no_wrap = true, .no_wrap = true,
}, },
{ {
.enum_name = "skeleton_run", .enum_name = "skeleton_run",
.img_var_name = "image_skeleton", .img_var_name = "image_skeleton",
.time_per_frame = 0.07, .time_per_frame = 0.07,
.num_frames = 8, .num_frames = 8,
.start = {0.0f, 160.0f}, .start = {0.0f, 160.0f},
.horizontal_diff_btwn_frames = 80.0, .horizontal_diff_btwn_frames = 80.0,
.offset = {0.0f, 20.0f}, .offset = {0.0f, 20.0f},
.region_size = {80.0f, 80.0f}, .region_size = {80.0f, 80.0f},
}, },
{ {
.enum_name = "skeleton_die", .enum_name = "skeleton_die",
.img_var_name = "image_skeleton", .img_var_name = "image_skeleton",
.time_per_frame = 0.10, .time_per_frame = 0.10,
.num_frames = 13, .num_frames = 13,
.start = {0.0f, 400.0f}, .start = {0.0f, 400.0f},
.horizontal_diff_btwn_frames = 80.0, .horizontal_diff_btwn_frames = 80.0,
.offset = {0.0f, 20.0f}, .offset = {0.0f, 20.0f},
.region_size = {80.0f, 80.0f}, .region_size = {80.0f, 80.0f},
.no_wrap = true, .no_wrap = true,
}, },
{ {
.enum_name = "merchant_idle", .enum_name = "merchant_idle",
.img_var_name = "image_merchant", .img_var_name = "image_merchant",
.time_per_frame = 0.15, .time_per_frame = 0.15,
.num_frames = 8, .num_frames = 8,
.start = {0.0, 0.0}, .start = {0.0, 0.0},
.horizontal_diff_btwn_frames = 110.0f, .horizontal_diff_btwn_frames = 110.0f,
.region_size = {110.0f, 110.0f}, .region_size = {110.0f, 110.0f},
.offset = {0.0f, -20.0f}, .offset = {0.0f, -20.0f},
}, },
}; };

@ -17,21 +17,21 @@
#define Log(...) { printf("Codegen: "); printf(__VA_ARGS__); } #define Log(...) { printf("Codegen: "); printf(__VA_ARGS__); }
void dump(MD_Node* from) { void dump(MD_Node* from) {
printf("/ %.*s\n", MD_S8VArg(from->string)); printf("/ %.*s\n", MD_S8VArg(from->string));
int d = 0; int d = 0;
for(MD_EachNode(child, from->first_child)) for (MD_EachNode(child, from->first_child))
{ {
printf("|-- Child %d Tag [%.*s] string[%.*s] first child string[%.*s]\n", d, MD_S8VArg(child->first_tag->string), MD_S8VArg(child->string), MD_S8VArg(child->first_child->string)); printf("|-- Child %d Tag [%.*s] string[%.*s] first child string[%.*s]\n", d, MD_S8VArg(child->first_tag->string), MD_S8VArg(child->string), MD_S8VArg(child->first_child->string));
d += 1; d += 1;
} }
} }
bool has_decimal(MD_String8 s) bool has_decimal(MD_String8 s)
{ {
for(int i = 0; i < s.size; i++) for (int i = 0; i < s.size; i++)
{ {
if(s.str[i] == '.') return true; if (s.str[i] == '.') return true;
} }
return false; return false;
} }
MD_Arena *cg_arena = NULL; MD_Arena *cg_arena = NULL;
@ -40,33 +40,33 @@ MD_Arena *cg_arena = NULL;
#define S8V(s) MD_S8VArg(s) #define S8V(s) MD_S8VArg(s)
MD_String8 ChildValue(MD_Node *n, MD_String8 name) { MD_String8 ChildValue(MD_Node *n, MD_String8 name) {
MD_Node *child_with_value = MD_ChildFromString(n, name, 0); MD_Node *child_with_value = MD_ChildFromString(n, name, 0);
assert(child_with_value); assert(child_with_value);
assert(!MD_NodeIsNil(child_with_value->first_child)); // MD_S8Lit("Must have child")); assert(!MD_NodeIsNil(child_with_value->first_child)); // MD_S8Lit("Must have child"));
return child_with_value->first_child->string; return child_with_value->first_child->string;
} }
MD_String8 asset_file_path(MD_String8 filename) { MD_String8 asset_file_path(MD_String8 filename) {
return MD_S8Fmt(cg_arena, "%.*s/%.*s", MD_S8VArg(S8("assets")), MD_S8VArg(filename)); return MD_S8Fmt(cg_arena, "%.*s/%.*s", MD_S8VArg(S8("assets")), MD_S8VArg(filename));
} }
char *nullterm(MD_String8 s) { char *nullterm(MD_String8 s) {
char *to_return = malloc(s.size + 1); char *to_return = malloc(s.size + 1);
memcpy(to_return, s.str, s.size); memcpy(to_return, s.str, s.size);
to_return[s.size] = '\0'; to_return[s.size] = '\0';
return to_return; return to_return;
} }
char* fillnull(char *s, char c) { char* fillnull(char *s, char c) {
while(*s != '\0') { while (*s != '\0') {
if(*s == c) { if (*s == c) {
*s = '\0'; *s = '\0';
return s + 1; return s + 1;
} }
s++; s++;
} }
assert(false); // MD_S8Lit("Couldn't find char")); assert(false); // MD_S8Lit("Couldn't find char"));
return NULL; return NULL;
} }
#define StrSame(s1, s2) MD_S8Match((s1), (s2), 0) #define StrSame(s1, s2) MD_S8Match((s1), (s2), 0)
@ -75,268 +75,261 @@ char* fillnull(char *s, char c) {
typedef BUFF(MD_Node*, 256) Nodes; typedef BUFF(MD_Node*, 256) Nodes;
MD_Node* find_by_name(Nodes *n, MD_String8 name) MD_Node* find_by_name(Nodes *n, MD_String8 name)
{ {
MD_Node *node_with = 0; MD_Node *node_with = 0;
BUFF_ITER(MD_Node *, n) BUFF_ITER(MD_Node *, n)
{ {
if(StrSame((*it)->string, name)) if (StrSame((*it)->string, name))
{ {
assert(node_with == 0); assert(node_with == 0);
node_with = (*it); node_with = (*it);
} }
} }
assert(node_with); assert(node_with);
return node_with; return node_with;
} }
char* goto_end_of(char *tomove, size_t max_move, char *pattern) { char* goto_end_of(char *tomove, size_t max_move, char *pattern) {
size_t pattern_len = strlen(pattern); size_t pattern_len = strlen(pattern);
for(int i = 0; i < max_move; i++) { for (int i = 0; i < max_move; i++) {
if(strncmp(tomove, pattern, pattern_len) == 0) { if (strncmp(tomove, pattern, pattern_len) == 0) {
tomove += pattern_len; tomove += pattern_len;
return tomove; return tomove;
} }
tomove++; tomove++;
} }
return NULL; return NULL;
} }
#define list_printf(list_ptr, ...) MD_S8ListPush(cg_arena, list_ptr, MD_S8Fmt(cg_arena, __VA_ARGS__)) #define list_printf(list_ptr, ...) MD_S8ListPush(cg_arena, list_ptr, MD_S8Fmt(cg_arena, __VA_ARGS__))
void dump_full(MD_Node* from) void dump_full(MD_Node* from)
{ {
for(MD_EachNode(node, from)) for (MD_EachNode(node, from))
{ {
printf("@%.*s %.*s\n", MD_S8VArg(node->first_tag->string), MD_S8VArg(node->string)); printf("@%.*s %.*s\n", MD_S8VArg(node->first_tag->string), MD_S8VArg(node->string));
} }
/* MD_String8List output_list = {0}; /* MD_String8List output_list = {0};
MD_DebugDumpFromNode(cg_arena, &output_list, from, 4, S8(" "), 0); MD_DebugDumpFromNode(cg_arena, &output_list, from, 4, S8(" "), 0);
MD_StringJoin join = (MD_StringJoin){0}; MD_StringJoin join = (MD_StringJoin){0};
MD_String8 debugged = MD_S8ListJoin(cg_arena, output_list , &join); MD_String8 debugged = MD_S8ListJoin(cg_arena, output_list , &join);
printf("%.*s\n", MD_S8VArg(debugged));*/ printf("%.*s\n", MD_S8VArg(debugged));*/
} }
#include "character_info.h" #include "character_info.h"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
cg_arena = MD_ArenaAlloc(); cg_arena = MD_ArenaAlloc();
assert(cg_arena); assert(cg_arena);
// do characters // do characters
FILE *char_header = fopen("gen/characters.gen.h", "w"); FILE *char_header = fopen("gen/characters.gen.h", "w");
fprintf(char_header, top_of_header); fprintf(char_header, top_of_header);
#define GEN_TABLE(arr_elem_type, table_name, arr, str_access) { fprintf(char_header, "char *%s[] = {\n", table_name); ARR_ITER(arr_elem_type, arr) fprintf(char_header, "\"%s\",\n", str_access); fprintf(char_header, "}; // %s\n", table_name); } #define GEN_TABLE(arr_elem_type, table_name, arr, str_access) { fprintf(char_header, "char *%s[] = {\n", table_name); ARR_ITER(arr_elem_type, arr) fprintf(char_header, "\"%s\",\n", str_access); fprintf(char_header, "}; // %s\n", table_name); }
#define GEN_ENUM(arr_elem_type, arr, enum_type_name, enum_name_access, fmt_str) { fprintf(char_header, "typedef enum\n{\n"); ARR_ITER(arr_elem_type, arr) fprintf(char_header, fmt_str, enum_name_access); fprintf(char_header, "} %s;\n", enum_type_name); GEN_TABLE(arr_elem_type, enum_type_name "_names", arr, enum_name_access); } #define GEN_ENUM(arr_elem_type, arr, enum_type_name, enum_name_access, fmt_str) { fprintf(char_header, "typedef enum\n{\n"); ARR_ITER(arr_elem_type, arr) fprintf(char_header, fmt_str, enum_name_access); fprintf(char_header, "} %s;\n", enum_type_name); GEN_TABLE(arr_elem_type, enum_type_name "_names", arr, enum_name_access); }
GEN_ENUM(ActionInfo, actions, "Action", it->name, "ACT_%s,\n"); GEN_ENUM(ActionInfo, actions, "Action", it->name, "ACT_%s,\n");
GEN_ENUM(ItemInfo, items, "ItemKind", it->enum_name, "ITEM_%s,\n"); GEN_ENUM(ItemInfo, items, "ItemKind", it->enum_name, "ITEM_%s,\n");
GEN_ENUM(AnimatedSprite, sprites, "AnimKind", it->enum_name, "ANIM_%s,\n"); GEN_ENUM(AnimatedSprite, sprites, "AnimKind", it->enum_name, "ANIM_%s,\n");
GEN_ENUM(CharacterGen, characters, "NpcKind", it->enum_name, "NPC_%s,\n");
fprintf(char_header, "typedef enum\n{\n"); fclose(char_header);
ARR_ITER(CharacterGen, characters)
{ // do assets
fprintf(char_header, " NPC_%s,\n", it->enum_name);
} MD_String8 writeto = MD_S8Fmt(cg_arena, "gen/assets.gen.c");
// characters enum can be extended at site of include, not ending the enum here Log("Writing to %.*s\n", MD_S8VArg(writeto));
FILE *output = fopen(nullterm(writeto), "w");
fclose(char_header);
MD_ParseResult parse = MD_ParseWholeFile(cg_arena, MD_S8Lit("assets.mdesk"));
// do assets
MD_String8List declarations_list = { 0 };
MD_String8 writeto = MD_S8Fmt(cg_arena, "gen/assets.gen.c"); MD_String8List load_list = { 0 };
Log("Writing to %.*s\n", MD_S8VArg(writeto)); MD_String8List level_decl_list = { 0 };
FILE *output = fopen(nullterm(writeto), "w"); MD_String8List tileset_decls = { 0 };
for (MD_EachNode(node, parse.node->first_child)) {
MD_ParseResult parse = MD_ParseWholeFile(cg_arena, MD_S8Lit("assets.mdesk")); if (MD_S8Match(node->first_tag->string, MD_S8Lit("sound"), 0)) {
MD_String8 variable_name = MD_S8Fmt(cg_arena, "sound_%.*s", MD_S8VArg(node->string));
MD_String8List declarations_list = {0}; Log("New sound variable %.*s\n", MD_S8VArg(variable_name));
MD_String8List load_list = {0}; MD_String8 filepath = ChildValue(node, MD_S8Lit("filepath"));
MD_String8List level_decl_list = {0}; filepath = asset_file_path(filepath);
MD_String8List tileset_decls = {0}; assert(filepath.str != 0); // MD_S8Fmt(cg_arena, "No filepath specified for sound '%.*s'", MD_S8VArg(node->string)));
for(MD_EachNode(node, parse.node->first_child)) { FILE *asset_file = fopen(filepath.str, "r");
if(MD_S8Match(node->first_tag->string, MD_S8Lit("sound"), 0)) { assert(asset_file); // MD_S8Fmt(cg_arena, "Could not open filepath %.*s for asset '%.*s'", MD_S8VArg(filepath), MD_S8VArg(node->string)));
MD_String8 variable_name = MD_S8Fmt(cg_arena, "sound_%.*s", MD_S8VArg(node->string)); fclose(asset_file);
Log("New sound variable %.*s\n", MD_S8VArg(variable_name));
MD_String8 filepath = ChildValue(node, MD_S8Lit("filepath")); MD_S8ListPush(cg_arena, &declarations_list, MD_S8Fmt(cg_arena, "AudioSample %.*s = {0};\n", MD_S8VArg(variable_name)));
filepath = asset_file_path(filepath); MD_S8ListPush(cg_arena, &load_list, MD_S8Fmt(cg_arena, "%.*s = load_wav_audio(\"%.*s\");\n", MD_S8VArg(variable_name), MD_S8VArg(filepath)));
assert(filepath.str != 0); // MD_S8Fmt(cg_arena, "No filepath specified for sound '%.*s'", MD_S8VArg(node->string))); }
FILE *asset_file = fopen(filepath.str, "r"); if (MD_S8Match(node->first_tag->string, MD_S8Lit("image"), 0)) {
assert(asset_file); // MD_S8Fmt(cg_arena, "Could not open filepath %.*s for asset '%.*s'", MD_S8VArg(filepath), MD_S8VArg(node->string))); MD_String8 variable_name = MD_S8Fmt(cg_arena, "image_%.*s", MD_S8VArg(node->string));
fclose(asset_file); Log("New image variable %.*s\n", MD_S8VArg(variable_name));
MD_String8 filepath = ChildValue(node, MD_S8Lit("filepath"));
MD_S8ListPush(cg_arena, &declarations_list, MD_S8Fmt(cg_arena, "AudioSample %.*s = {0};\n", MD_S8VArg(variable_name))); filepath = asset_file_path(filepath);
MD_S8ListPush(cg_arena, &load_list, MD_S8Fmt(cg_arena, "%.*s = load_wav_audio(\"%.*s\");\n", MD_S8VArg(variable_name), MD_S8VArg(filepath))); assert(filepath.str != 0); // , MD_S8Fmt(cg_arena, "No filepath specified for image '%.*s'", MD_S8VArg(node->string)));
} FILE *asset_file = fopen(filepath.str, "r");
if(MD_S8Match(node->first_tag->string, MD_S8Lit("image"), 0)) { assert(asset_file); // , MD_S8Fmt(cg_arena, "Could not open filepath %.*s for asset '%.*s'", MD_S8VArg(filepath), MD_S8VArg(node->string)));
MD_String8 variable_name = MD_S8Fmt(cg_arena, "image_%.*s", MD_S8VArg(node->string)); fclose(asset_file);
Log("New image variable %.*s\n", MD_S8VArg(variable_name));
MD_String8 filepath = ChildValue(node, MD_S8Lit("filepath")); MD_S8ListPush(cg_arena, &declarations_list, MD_S8Fmt(cg_arena, "sg_image %.*s = {0};\n", MD_S8VArg(variable_name)));
filepath = asset_file_path(filepath); MD_S8ListPush(cg_arena, &load_list, MD_S8Fmt(cg_arena, "%.*s = load_image(\"%.*s\");\n", MD_S8VArg(variable_name), MD_S8VArg(filepath)));
assert(filepath.str != 0); // , MD_S8Fmt(cg_arena, "No filepath specified for image '%.*s'", MD_S8VArg(node->string))); }
FILE *asset_file = fopen(filepath.str, "r"); if (MD_S8Match(node->first_tag->string, MD_S8Lit("tileset"), 0)) {
assert(asset_file); // , MD_S8Fmt(cg_arena, "Could not open filepath %.*s for asset '%.*s'", MD_S8VArg(filepath), MD_S8VArg(node->string))); // not a variable anymore
fclose(asset_file); MD_String8 variable_name = MD_S8Fmt(cg_arena, "tileset_%.*s", MD_S8VArg(node->string));
Log("New tileset %.*s\n", MD_S8VArg(variable_name));
MD_S8ListPush(cg_arena, &declarations_list, MD_S8Fmt(cg_arena, "sg_image %.*s = {0};\n", MD_S8VArg(variable_name))); MD_String8 filepath = asset_file_path(ChildValue(node, MD_S8Lit("filepath")));
MD_S8ListPush(cg_arena, &load_list, MD_S8Fmt(cg_arena, "%.*s = load_image(\"%.*s\");\n", MD_S8VArg(variable_name), MD_S8VArg(filepath)));
} MD_String8 tileset_file_contents = MD_LoadEntireFile(cg_arena, filepath);
if(MD_S8Match(node->first_tag->string, MD_S8Lit("tileset"), 0)) { list_printf(&tileset_decls, "{\n", MD_S8VArg(variable_name));
// not a variable anymore list_printf(&tileset_decls, ".first_gid = %.*s,\n", MD_S8VArg(ChildValue(node, MD_S8Lit("firstgid"))));
MD_String8 variable_name = MD_S8Fmt(cg_arena, "tileset_%.*s", MD_S8VArg(node->string)); list_printf(&tileset_decls, ".img = &%.*s,\n", MD_S8VArg(ChildValue(node, MD_S8Lit("image"))));
Log("New tileset %.*s\n", MD_S8VArg(variable_name));
MD_String8 filepath = asset_file_path(ChildValue(node, MD_S8Lit("filepath"))); list_printf(&tileset_decls, ".animated = {\n");
char *end = tileset_file_contents.str + tileset_file_contents.size;
MD_String8 tileset_file_contents = MD_LoadEntireFile(cg_arena, filepath); char *cur = tileset_file_contents.str;
list_printf(&tileset_decls, "{\n", MD_S8VArg(variable_name)); int num_animated_tiles = 0;
list_printf(&tileset_decls, ".first_gid = %.*s,\n", MD_S8VArg(ChildValue(node, MD_S8Lit("firstgid")))); while (cur < end) {
list_printf(&tileset_decls, ".img = &%.*s,\n", MD_S8VArg(ChildValue(node, MD_S8Lit("image")))); cur = goto_end_of(cur, end - cur, "<tile id=\"");
if (cur == NULL) break;
list_printf(&tileset_decls, ".animated = {\n"); char *end_of_anim = goto_end_of(cur, end - cur, "</animation>");
char *end = tileset_file_contents.str + tileset_file_contents.size; if (end_of_anim == NULL) break;
char *cur = tileset_file_contents.str; char *new_cur = fillnull(cur, '"');
int num_animated_tiles = 0; int frame_from = atoi(cur);
while(cur < end) { cur = new_cur;
cur = goto_end_of(cur, end - cur, "<tile id=\""); list_printf(&tileset_decls, "{ .exists = true, .id_from = %d, .frames = { ", frame_from);
if(cur == NULL) break;
char *end_of_anim = goto_end_of(cur, end - cur, "</animation>"); int num_frames = 0;
if(end_of_anim == NULL) break; while (true) {
char *new_cur = fillnull(cur, '"'); char *next_frame = goto_end_of(cur, end - cur, "<frame tileid=\"");
int frame_from = atoi(cur); if (end_of_anim == NULL || next_frame == NULL || next_frame > end_of_anim) break;
cur = new_cur; char *new_cur = fillnull(next_frame, '"');
list_printf(&tileset_decls, "{ .exists = true, .id_from = %d, .frames = { ", frame_from); int frame = atoi(next_frame);
int num_frames = 0; list_printf(&tileset_decls, "%d, ", frame);
while(true) { num_frames++;
char *next_frame = goto_end_of(cur, end - cur, "<frame tileid=\"");
if(end_of_anim == NULL || next_frame == NULL || next_frame > end_of_anim) break; cur = new_cur;
char *new_cur = fillnull(next_frame, '"'); }
int frame = atoi(next_frame); list_printf(&tileset_decls, "}, .num_frames = %d },\n", num_frames);
num_animated_tiles++;
list_printf(&tileset_decls, "%d, ", frame); }
num_frames++; if (num_animated_tiles == 0) list_printf(&tileset_decls, "0");
list_printf(&tileset_decls, "}},\n");
cur = new_cur; }
} if (MD_S8Match(node->first_tag->string, MD_S8Lit("level"), 0)) {
list_printf(&tileset_decls, "}, .num_frames = %d },\n", num_frames); MD_String8 variable_name = MD_S8Fmt(cg_arena, "level_%.*s", MD_S8VArg(node->string));
num_animated_tiles++; Log("New level variable %.*s\n", MD_S8VArg(variable_name));
} MD_String8 filepath = asset_file_path(ChildValue(node, MD_S8Lit("filepath")));
if(num_animated_tiles == 0) list_printf(&tileset_decls, "0"); MD_ParseResult level_parse = MD_ParseWholeFile(cg_arena, filepath);
list_printf(&tileset_decls, "}},\n"); assert(!MD_NodeIsNil(level_parse.node->first_child)); // , MD_S8Lit("Failed to load level file"));
}
if(MD_S8Match(node->first_tag->string, MD_S8Lit("level"), 0)) { MD_Node *layers = MD_ChildFromString(level_parse.node->first_child, MD_S8Lit("layers"), 0);
MD_String8 variable_name = MD_S8Fmt(cg_arena, "level_%.*s", MD_S8VArg(node->string)); fprintf(output, "Level %.*s = {\n", MD_S8VArg(variable_name));
Log("New level variable %.*s\n", MD_S8VArg(variable_name)); MD_String8List tile_layer_decls = { 0 };
MD_String8 filepath = asset_file_path(ChildValue(node, MD_S8Lit("filepath"))); for (MD_EachNode(lay, layers->first_child)) {
MD_ParseResult level_parse = MD_ParseWholeFile(cg_arena, filepath); MD_String8 type = MD_ChildFromString(lay, MD_S8Lit("type"), 0)->first_child->string;
assert(!MD_NodeIsNil(level_parse.node->first_child)); // , MD_S8Lit("Failed to load level file")); if (MD_S8Match(type, MD_S8Lit("objectgroup"), 0)) {
fprintf(output, ".initial_entities = {\n");
MD_Node *layers = MD_ChildFromString(level_parse.node->first_child, MD_S8Lit("layers"), 0); for (MD_EachNode(object, MD_ChildFromString(lay, MD_S8Lit("objects"), 0)->first_child)) {
fprintf(output, "Level %.*s = {\n", MD_S8VArg(variable_name)); //dump(object);
MD_String8List tile_layer_decls = {0}; // negative numbers for object position aren't supported here
for(MD_EachNode(lay, layers->first_child)) { MD_String8 name = MD_ChildFromString(object, MD_S8Lit("name"), 0)->first_child->string;
MD_String8 type = MD_ChildFromString(lay, MD_S8Lit("type"), 0)->first_child->string; MD_String8 x_string = MD_ChildFromString(object, MD_S8Lit("x"), 0)->first_child->string;
if(MD_S8Match(type, MD_S8Lit("objectgroup"), 0)) { MD_String8 y_string = MD_ChildFromString(object, MD_S8Lit("y"), 0)->first_child->string;
fprintf(output, ".initial_entities = {\n"); y_string = MD_S8Fmt(cg_arena, "-%.*s", MD_S8VArg(y_string));
for(MD_EachNode(object, MD_ChildFromString(lay, MD_S8Lit("objects"), 0)->first_child)) {
//dump(object); MD_String8List props = { 0 };
// negative numbers for object position aren't supported here for (MD_EachNode(prop_object, MD_ChildFromString(object, S8("properties"), 0)->first_child))
MD_String8 name = MD_ChildFromString(object, MD_S8Lit("name"), 0)->first_child->string; {
MD_String8 x_string = MD_ChildFromString(object, MD_S8Lit("x"), 0)->first_child->string; list_printf(&props, ".%.*s = %.*s, ", S8V(ChildValue(prop_object, S8("name"))), S8V(ChildValue(prop_object, S8("value"))));
MD_String8 y_string = MD_ChildFromString(object, MD_S8Lit("y"), 0)->first_child->string; }
y_string = MD_S8Fmt(cg_arena, "-%.*s", MD_S8VArg(y_string)); MD_StringJoin join = (MD_StringJoin) { 0 };
MD_String8 props_string = MD_S8ListJoin(cg_arena, props, &join);
MD_String8List props = {0};
for(MD_EachNode(prop_object, MD_ChildFromString(object, S8("properties"), 0)->first_child)) if (has_decimal(x_string)) x_string = MD_S8Fmt(cg_arena, "%.*sf", MD_S8VArg(x_string));
{ if (has_decimal(y_string)) y_string = MD_S8Fmt(cg_arena, "%.*sf", MD_S8VArg(y_string));
list_printf(&props, ".%.*s = %.*s, ", S8V(ChildValue(prop_object, S8("name"))), S8V(ChildValue(prop_object, S8("value"))));
} MD_String8 class = MD_ChildFromString(object, MD_S8Lit("class"), 0)->first_child->string;
MD_StringJoin join = (MD_StringJoin){0}; if (MD_S8Match(class , MD_S8Lit("PROP"), 0))
MD_String8 props_string = MD_S8ListJoin(cg_arena, props, &join); {
fprintf(output, "{ .exists = true, .is_prop = true, .prop_kind = %.*s, .pos = { .X=%.*s, .Y=%.*s }, %.*s }, ", MD_S8VArg(name), MD_S8VArg(x_string), MD_S8VArg(y_string), MD_S8VArg(props_string));
if(has_decimal(x_string)) x_string = MD_S8Fmt(cg_arena, "%.*sf", MD_S8VArg(x_string)); }
if(has_decimal(y_string)) y_string = MD_S8Fmt(cg_arena, "%.*sf", MD_S8VArg(y_string)); else if (MD_S8Match(class , MD_S8Lit("ITEM"), 0))
{
MD_String8 class = MD_ChildFromString(object, MD_S8Lit("class"), 0)->first_child->string; fprintf(output, "{ .exists = true, .is_item = true, .item_kind = ITEM_%.*s, .pos = { .X=%.*s, .Y=%.*s }, %.*s }, ", MD_S8VArg(name), MD_S8VArg(x_string), MD_S8VArg(y_string), MD_S8VArg(props_string));
if(MD_S8Match(class, MD_S8Lit("PROP"), 0)) }
{ else if (MD_S8Match(name, MD_S8Lit("PLAYER"), 0))
fprintf(output, "{ .exists = true, .is_prop = true, .prop_kind = %.*s, .pos = { .X=%.*s, .Y=%.*s }, %.*s }, ", MD_S8VArg(name), MD_S8VArg(x_string), MD_S8VArg(y_string), MD_S8VArg(props_string)); {
} fprintf(output, "{ .exists = true, .is_character = true, .pos = { .X=%.*s, .Y=%.*s }, %.*s }, ", MD_S8VArg(x_string), MD_S8VArg(y_string), MD_S8VArg(props_string));
else if(MD_S8Match(class, MD_S8Lit("ITEM"), 0)) }
{ else
fprintf(output, "{ .exists = true, .is_item = true, .item_kind = ITEM_%.*s, .pos = { .X=%.*s, .Y=%.*s }, %.*s }, ", MD_S8VArg(name), MD_S8VArg(x_string), MD_S8VArg(y_string), MD_S8VArg(props_string)); {
} fprintf(output, "{ .exists = true, .is_npc = true, .npc_kind = NPC_%.*s, .pos = { .X=%.*s, .Y=%.*s }, %.*s }, ", MD_S8VArg(name), MD_S8VArg(x_string), MD_S8VArg(y_string), MD_S8VArg(props_string));
else if(MD_S8Match(name, MD_S8Lit("PLAYER"), 0)) }
{ }
fprintf(output, "{ .exists = true, .is_character = true, .pos = { .X=%.*s, .Y=%.*s }, %.*s }, ", MD_S8VArg(x_string), MD_S8VArg(y_string), MD_S8VArg(props_string)); fprintf(output, "\n}, // entities\n");
} }
else if (MD_S8Match(type, MD_S8Lit("tilelayer"), 0)) {
{ int width = atoi(nullterm(MD_ChildFromString(layers->first_child, MD_S8Lit("width"), 0)->first_child->string));
fprintf(output, "{ .exists = true, .is_npc = true, .npc_kind = NPC_%.*s, .pos = { .X=%.*s, .Y=%.*s }, %.*s }, ", MD_S8VArg(name), MD_S8VArg(x_string), MD_S8VArg(y_string), MD_S8VArg(props_string)); int height = atoi(nullterm(MD_ChildFromString(layers->first_child, MD_S8Lit("height"), 0)->first_child->string));
} MD_Node *data = MD_ChildFromString(lay, MD_S8Lit("data"), 0);
}
fprintf(output, "\n}, // entities\n"); int num_index = 0;
} MD_String8List cur_layer_decl = { 0 };
if(MD_S8Match(type, MD_S8Lit("tilelayer"), 0)) { list_printf(&cur_layer_decl, "{ \n");
int width = atoi(nullterm(MD_ChildFromString(layers->first_child, MD_S8Lit("width"), 0)->first_child->string)); list_printf(&cur_layer_decl, "{ ");
int height = atoi(nullterm(MD_ChildFromString(layers->first_child, MD_S8Lit("height"), 0)->first_child->string)); for (MD_EachNode(tile_id_node, data->first_child)) {
MD_Node *data = MD_ChildFromString(lay, MD_S8Lit("data"), 0); list_printf(&cur_layer_decl, "%.*s, ", MD_S8VArg(tile_id_node->string));
int num_index = 0; if (num_index % width == width - 1) {
MD_String8List cur_layer_decl = {0}; if (MD_NodeIsNil(tile_id_node->next)) {
list_printf(&cur_layer_decl, "{ \n"); list_printf(&cur_layer_decl, "},\n}, // tiles for this layer\n");
list_printf(&cur_layer_decl, "{ "); } else {
for(MD_EachNode(tile_id_node, data->first_child)) { list_printf(&cur_layer_decl, "},\n{ ");
list_printf(&cur_layer_decl, "%.*s, ", MD_S8VArg(tile_id_node->string)); }
}
if(num_index % width == width - 1) { num_index += 1;
if(MD_NodeIsNil(tile_id_node->next)) { }
list_printf(&cur_layer_decl, "},\n}, // tiles for this layer\n");
} else { MD_StringJoin join = MD_ZERO_STRUCT;
list_printf(&cur_layer_decl, "},\n{ "); MD_String8 layer_decl_string = MD_S8ListJoin(cg_arena, cur_layer_decl, &join);
} MD_S8ListPush(cg_arena, &tile_layer_decls, layer_decl_string);
} }
num_index += 1; }
}
fprintf(output, ".tiles = {\n");
MD_StringJoin join = MD_ZERO_STRUCT; // layer decls
MD_String8 layer_decl_string = MD_S8ListJoin(cg_arena, cur_layer_decl, &join); {
MD_S8ListPush(cg_arena, &tile_layer_decls, layer_decl_string);
} MD_StringJoin join = MD_ZERO_STRUCT;
} MD_String8 layers_string = MD_S8ListJoin(cg_arena, tile_layer_decls, &join);
fprintf(output, "%.*s\n", MD_S8VArg(layers_string));
fprintf(output, ".tiles = {\n"); //MD_S8ListPush(cg_arena, &tile_layer_delcs, layer_decl_string);
// layer decls
{ }
fprintf(output, "} // tiles\n");
MD_StringJoin join = MD_ZERO_STRUCT;
MD_String8 layers_string = MD_S8ListJoin(cg_arena, tile_layer_decls, &join); fprintf(output, "\n}; // %.*s\n", MD_S8VArg(variable_name));
fprintf(output, "%.*s\n", MD_S8VArg(layers_string)); }
//MD_S8ListPush(cg_arena, &tile_layer_delcs, layer_decl_string); }
}
fprintf(output, "} // tiles\n"); MD_StringJoin join = { 0 };
MD_String8 declarations = MD_S8ListJoin(cg_arena, declarations_list, &join);
fprintf(output, "\n}; // %.*s\n", MD_S8VArg(variable_name)); MD_String8 loads = MD_S8ListJoin(cg_arena, load_list, &join);
} fprintf(output, "%.*s\nvoid load_assets() {\n%.*s\n}\n", MD_S8VArg(declarations), MD_S8VArg(loads));
}
fprintf(output, "TileSet tilesets[] = { %.*s\n };\n", MD_S8VArg(MD_S8ListJoin(cg_arena, tileset_decls, &join)));
MD_StringJoin join = {0}; fprintf(output, "sg_image * anim_img_table[] = {\n");
MD_String8 declarations = MD_S8ListJoin(cg_arena, declarations_list, &join); ARR_ITER(AnimatedSprite, sprites)
MD_String8 loads = MD_S8ListJoin(cg_arena, load_list, &join); {
fprintf(output, "%.*s\nvoid load_assets() {\n%.*s\n}\n", MD_S8VArg(declarations), MD_S8VArg(loads)); fprintf(output, "&%s,\n", it->img_var_name);
}
fprintf(output, "TileSet tilesets[] = { %.*s\n };\n", MD_S8VArg(MD_S8ListJoin(cg_arena, tileset_decls, &join))); fprintf(output, "}; // anim_img_table \n");
fprintf(output, "sg_image * anim_img_table[] = {\n"); fclose(output);
ARR_ITER(AnimatedSprite, sprites)
{ return 0;
fprintf(output, "&%s,\n", it->img_var_name);
}
fprintf(output, "}; // anim_img_table \n");
fclose(output);
return 0;
} }

7015
main.c

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save