#include "data.h" #include #include "util.h" #include "loader.h" #include "datatypes.h" #include "doors.h" #include "terminals.h" #include "mazes.h" #include "chapters.h" #include "nodes.h" #include "walkthrough.h" /* Copyright (c) 2013-2021 Devine Lu Linvega 2018 web port by rezmason 2021 C89 port by rezmason Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ static char *sectionDelimeters = "/*"; int Data_Init() { int success = 1; char *data = NULL; if(Loader_LoadText(&data, "data/data.txt")) { char *sectionSave = NULL; char *headerSection; char *section; headerSection = getNextToken(data, sectionDelimeters, §ionSave); while(headerSection != NULL && success) { section = getNextToken(NULL, sectionDelimeters, §ionSave); if(strcmp(headerSection, "TERMINALS") == 0) { success &= Terminals_Init(section); } else if(strcmp(headerSection, "DOORS") == 0) { success &= Doors_Init(section); } else if(strcmp(headerSection, "MAZES") == 0) { success &= Mazes_Init(section); } else if(strcmp(headerSection, "NODES") == 0) { success &= Nodes_Init(section); } else if(strcmp(headerSection, "CHAPTERS") == 0) { success &= Chapters_Init(section); } else if(strcmp(headerSection, "WALKTHROUGH") == 0) { success &= Walkthrough_Init(section); } headerSection = getNextToken(NULL, sectionDelimeters, §ionSave); } } else { success = 0; } free(data); return success; } void Data_Quit() { Nodes_Quit(); Doors_Quit(); Terminals_Quit(); Mazes_Quit(); Chapters_Quit(); Walkthrough_Quit(); } void Data_ResetState(GameState *state) { int windowW = state->windowW; int windowH = state->windowH; memset(state, 0, sizeof(GameState)); state->windowW = windowW; state->windowH = windowH; state->audio = 1; Nodes_Reset(state); Terminals_Reset(state); Mazes_Reset(state); Chapters_Reset(state); }