Load data from files found in directory, rather than using a text file.

This commit is contained in:
Steve 2016-02-27 16:14:14 +00:00
parent 266088f764
commit 2c33041344
11 changed files with 44 additions and 89 deletions

View File

@ -1,8 +0,0 @@
[
"data/capitalShips/csnCorvette01.json",
"data/capitalShips/csnCorvette02.json",
"data/capitalShips/unfCorvette01.json",
"data/capitalShips/unfCorvette02.json",
"data/capitalShips/infCorvette01.json",
"data/capitalShips/infCorvette02.json"
]

View File

@ -1,7 +0,0 @@
[
"data/craft/civilian.json",
"data/craft/tug.json",
"data/craft/shuttle.json",
"data/craft/supplyShip.json",
"data/craft/munitionsTransport.json"
]

View File

@ -1,26 +0,0 @@
[
"data/fighters/ataf.json",
"data/fighters/dart.json",
"data/fighters/jackal.json",
"data/fighters/simpleDart.json",
"data/fighters/sphinx.json",
"data/fighters/staticDart.json",
"data/fighters/taf.json",
"data/fighters/unarmedDart.json",
"data/fighters/ray.json",
"data/fighters/nymph.json",
"data/fighters/firefly.json",
"data/fighters/hyenaA.json",
"data/fighters/hyenaB.json",
"data/fighters/leopard.json",
"data/fighters/kingfisher.json",
"data/fighters/mantis.json",
"data/fighters/rook.json",
"data/fighters/thunderhead.json",
"data/fighters/scarab.json",
"data/fighters/hammerhead.json",
"data/fighters/khepri.json",
"data/fighters/cannonDart.json",
"data/fighters/missileDart.json",
"data/fighters/lynx.json"
]

View File

@ -1,4 +0,0 @@
[
"data/turrets/rocketTurret.json",
"data/turrets/plasmaTurret.json"
]

View File

@ -1,12 +0,0 @@
[
"data/widgets/galacticMap.json",
"data/widgets/modal.json",
"data/widgets/startBattle.json",
"data/widgets/inBattle.json",
"data/widgets/battleWon.json",
"data/widgets/battleLost.json",
"data/widgets/title.json",
"data/widgets/options.json",
"data/widgets/stats.json",
"data/widgets/starSystem.json"
]

View File

@ -310,22 +310,25 @@ static void die(void)
void loadCapitalShipDefs(void) void loadCapitalShipDefs(void)
{ {
cJSON *root, *node; char **filenames;
char *text; char path[MAX_FILENAME_LENGTH];
int count, i;
text = readFile(getFileLocation("data/capitalShips/list.json"));
root = cJSON_Parse(text);
memset(&defHead, 0, sizeof(Entity)); memset(&defHead, 0, sizeof(Entity));
defTail = &defHead; defTail = &defHead;
for (node = root->child ; node != NULL ; node = node->next) filenames = getFileList("data/capitalShips", &count);
for (i = 0 ; i < count ; i++)
{ {
loadCapitalShipDef(node->valuestring); sprintf(path, "data/capitalShips/%s", filenames[i]);
loadCapitalShipDef(path);
free(filenames[i]);
} }
cJSON_Delete(root); free(filenames);
free(text);
} }
static void loadCapitalShipDef(char *filename) static void loadCapitalShipDef(char *filename)

View File

@ -46,6 +46,7 @@ extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern void addDebris(int x, int y, int amount); extern void addDebris(int x, int y, int amount);
extern void runScriptFunction(char *format, ...); extern void runScriptFunction(char *format, ...);
extern void updateObjective(char *name, int type); extern void updateObjective(char *name, int type);
extern char **getFileList(char *dir, int *count);
extern Battle battle; extern Battle battle;
extern Entity *self; extern Entity *self;

View File

@ -611,26 +611,29 @@ void loadFighterDefs(void)
memset(&defHead, 0, sizeof(Entity)); memset(&defHead, 0, sizeof(Entity));
defTail = &defHead; defTail = &defHead;
loadFighterDefList("data/fighters/list.json"); loadFighterDefList("data/fighters");
loadFighterDefList("data/craft/list.json"); loadFighterDefList("data/craft");
loadFighterDefList("data/turrets/list.json"); loadFighterDefList("data/turrets");
} }
static void loadFighterDefList(char *filename) static void loadFighterDefList(char *dir)
{ {
cJSON *root, *node; char **filenames;
char *text; char path[MAX_FILENAME_LENGTH];
int count, i;
text = readFile(getFileLocation(filename)); filenames = getFileList(dir, &count);
root = cJSON_Parse(text);
for (node = root->child ; node != NULL ; node = node->next) for (i = 0 ; i < count ; i++)
{ {
loadFighterDef(node->valuestring); sprintf(path, "%s/%s", dir, filenames[i]);
loadFighterDef(path);
free(filenames[i]);
} }
cJSON_Delete(root); free(filenames);
free(text);
} }
static void loadFighterDef(char *filename) static void loadFighterDef(char *filename)

View File

@ -45,6 +45,7 @@ extern void completeMission(void);
extern void runScriptFunction(char *format, ...); extern void runScriptFunction(char *format, ...);
extern char *getFileLocation(char *filename); extern char *getFileLocation(char *filename);
extern void addDebris(int x, int y, int amount); extern void addDebris(int x, int y, int amount);
extern char **getFileList(char *dir, int *count);
extern App app; extern App app;
extern Battle battle; extern Battle battle;

View File

@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "widgets.h" #include "widgets.h"
static void loadWidgets(char *filename); static void loadWidgets(void);
static void loadWidgetSet(char *filename); static void loadWidgetSet(char *filename);
static void handleMouse(void); static void handleMouse(void);
static void handleKeyboard(void); static void handleKeyboard(void);
@ -46,7 +46,7 @@ void initWidgets(void)
optionsLeft = getTexture("gfx/widgets/optionsLeft.png"); optionsLeft = getTexture("gfx/widgets/optionsLeft.png");
optionsRight = getTexture("gfx/widgets/optionsRight.png"); optionsRight = getTexture("gfx/widgets/optionsRight.png");
loadWidgets("data/widgets/list.json"); loadWidgets();
drawingWidgets = 0; drawingWidgets = 0;
} }
@ -249,21 +249,24 @@ static void handleKeyboard(void)
} }
} }
static void loadWidgets(char *filename) static void loadWidgets()
{ {
cJSON *root, *node; char **filenames;
char *text; char path[MAX_FILENAME_LENGTH];
int count, i;
text = readFile(getFileLocation(filename)); filenames = getFileList("data/widgets", &count);
root = cJSON_Parse(text);
for (node = root->child ; node != NULL ; node = node->next) for (i = 0 ; i < count ; i++)
{ {
loadWidgetSet(node->valuestring); sprintf(path, "data/widgets/%s", filenames[i]);
loadWidgetSet(path);
free(filenames[i]);
} }
cJSON_Delete(root); free(filenames);
free(text);
} }
static void loadWidgetSet(char *filename) static void loadWidgetSet(char *filename)

View File

@ -31,6 +31,7 @@ extern SDL_Texture *getTexture(char *filename);
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
extern void playSound(int id); extern void playSound(int id);
extern char *getFileLocation(char *filename); extern char *getFileLocation(char *filename);
extern char **getFileList(char *dir, int *count);
extern App app; extern App app;
extern Colors colors; extern Colors colors;