Allow for file location to be determined automatically.

This commit is contained in:
Steve 2015-12-02 23:20:19 +00:00
parent 21b68584b4
commit 65b62091d1
25 changed files with 80 additions and 37 deletions

View File

@ -37,7 +37,7 @@ OBJS += testMission.o textures.o text.o title.o transition.o
OBJS += util.o
OBJS += waypoints.o widgets.o
DIST_FILES = data gfx manual music sound src LICENSE makefile README.md CHANGELOG
DIST_FILES = data gfx manual music sound src LICENSE makefile* common.mk README.md CHANGELOG
# top-level rule to create the program.
all: $(TARGET)
@ -50,6 +50,19 @@ all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) -o $@ $(OBJS) $(LIBS)
install:
cp $(TARGET) $(BIN_DIR)
mkdir -p $(DATA_DIR)
cp -r data $(DATA_DIR)
cp -r gfx $(DATA_DIR)
cp -r manual $(DATA_DIR)
cp -r music $(DATA_DIR)
cp -r sound $(DATA_DIR)
uninstall:
$(RM) $(BIN_DIR)/$(TARGET)
$(RM) -rf $(DATA_DIR)
# prepare an archive for the program
dist:
$(RM) -rf $(PROG)-$(VERSION)
@ -58,7 +71,7 @@ dist:
git log --oneline --decorate >$(PROG)-$(VERSION)/CHANGELOG.raw
tar czf $(PROG)-$(VERSION).$(REVISION)-src.tar.gz $(PROG)-$(VERSION)
mkdir -p dist
$(RM) -rf dist
$(RM) -rf dist/*
mv $(PROG)-$(VERSION).$(REVISION)-src.tar.gz dist
$(RM) -rf $(PROG)-$(VERSION)

View File

@ -1,5 +1,7 @@
CC = gcc
EXEEXT =
BIN_DIR = /usr/bin
DATA_DIR = /opt/tbftss
SEARCHPATH += src/plat/unix
OBJS += unixInit.o

View File

@ -36,7 +36,7 @@ void initBulletDefs(void)
memset(&bulletDef, 0, sizeof(Bullet) * BT_MAX);
text = readFile("data/battle/bullets.json");
text = readFile(getFileLocation("data/battle/bullets.json"));
root = cJSON_Parse(text);

View File

@ -43,6 +43,7 @@ extern void addMissileExplosion(Bullet *b);
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
extern void playSound(int id);
extern char *getFileLocation(char *filename);
extern Battle battle;
extern Colors colors;

View File

@ -597,7 +597,7 @@ void loadFighterDefs(void)
cJSON *root, *node;
char *text;
text = readFile("data/fighters/list.json");
text = readFile(getFileLocation("data/fighters/list.json"));
root = cJSON_Parse(text);
memset(&defHead, 0, sizeof(Entity));
@ -621,7 +621,7 @@ static void loadFighterDef(char *filename)
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
text = readFile(filename);
text = readFile(getFileLocation(filename));
f = malloc(sizeof(Entity));
memset(f, 0, sizeof(Entity));

View File

@ -49,6 +49,7 @@ extern void addShieldSplinterEffect(Entity *ent);
extern void completeMission(void);
extern void drawShieldHitEffect(Entity *e);
extern void runScriptFunction(char *format, ...);
extern char *getFileLocation(char *filename);
extern App app;
extern Battle battle;

View File

@ -31,7 +31,7 @@ void loadItemDefs(void)
char *text;
Entity *e;
text = readFile("data/battle/items.json");
text = readFile(getFileLocation("data/battle/items.json"));
root = cJSON_Parse(text);

View File

@ -32,6 +32,7 @@ extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int
extern void playBattleSound(int id, int x, int y);
extern void addHudMessage(SDL_Color c, char *format, ...);
extern void updateObjective(char *name, int type);
extern char *getFileLocation(char *filename);
extern Battle battle;
extern Entity *self;

View File

@ -22,6 +22,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define REVISION 0
#endif
#ifndef DATA_DIR
#define DATA_DIR ""
#endif
#define PI 3.14159265358979323846
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

View File

@ -230,7 +230,7 @@ static void loadFont(int size)
{
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "loadFonts(%d)", size);
font[size] = TTF_OpenFont("data/fonts/Roboto-Medium.ttf", size);
font[size] = TTF_OpenFont(getFileLocation("data/fonts/Roboto-Medium.ttf"), size);
}
static unsigned long hashcode(const char *str, int size)

View File

@ -25,5 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../structs.h"
extern void blit(SDL_Texture *texture, int x, int y, int centered);
extern char *getFileLocation(char *filename);
extern App app;

View File

@ -38,7 +38,7 @@ void loadMission(char *filename)
stopMusic();
text = readFile(filename);
text = readFile(getFileLocation(filename));
srand(hashcode(filename));

View File

@ -44,6 +44,7 @@ extern void failIncompleteObjectives(void);
extern void completeConditions(void);
extern void retreatEnemies(void);
extern void initScript(cJSON *missionJSON);
extern char *getFileLocation(char *filename);
extern Battle battle;
extern Entity *player;

View File

@ -28,7 +28,7 @@ void initStarSystems(void)
cJSON *root, *node;
char *text;
text = readFile("data/galaxy/starSystems.json");
text = readFile(getFileLocation("data/galaxy/starSystems.json"));
root = cJSON_Parse(text);
for (node = cJSON_GetObjectItem(root, "starSystems")->child ; node != NULL ; node = node->next)
@ -81,7 +81,7 @@ static void loadMissionMeta(char *filename, StarSystem *starSystem)
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
text = readFile(filename);
text = readFile(getFileLocation(filename));
root = cJSON_Parse(text);

View File

@ -27,5 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern char *readFile(char *filename);
extern long lookup(char *name);
extern int isMissionAvailable(Mission *mission, Mission *prev);
extern char *getFileLocation(char *filename);
extern Game game;

View File

@ -151,7 +151,7 @@ static void loadConfig(void)
}
else
{
text = readFile("data/app/config.json");
text = readFile(getFileLocation("data/app/config.json"));
}
root = cJSON_Parse(text);

View File

@ -56,6 +56,7 @@ extern void destroyWidgets(void);
extern void expireTexts(void);
extern void initInput(void);
extern void createSaveFolder(void);
extern char *getFileLocation(char *filename);
extern App app;
extern Colors colors;

View File

@ -73,3 +73,17 @@ char *getSaveFilePath(char *filename)
return path;
}
char *getFileLocation(char *filename)
{
static char path[MAX_FILENAME_LENGTH];
if (fileExists(filename))
{
return filename;
}
sprintf(path, "%s/%s\n", DATA_DIR, filename);
return path;
}

View File

@ -91,28 +91,27 @@ void playBattleSound(int id, int x, int y)
static void loadSounds(void)
{
sounds[SND_ARMOUR_HIT] = Mix_LoadWAV("sound/275151__bird-man__gun-shot.ogg");
sounds[SND_SHIELD_HIT] = Mix_LoadWAV("sound/49678__ejfortin__energy-short-sword-7.ogg");
sounds[SND_PLASMA] = Mix_LoadWAV("sound/268344__julien-matthey__jm-noiz-laser-01.ogg");
sounds[SND_LASER] = Mix_LoadWAV("sound/18382__inferno__hvylas.ogg");
sounds[SND_MAG] = Mix_LoadWAV("sound/146725__fins__laser.ogg");
sounds[SND_SHIELD_BREAK] = Mix_LoadWAV("sound/322603__clippysounds__glass-break.ogg");
sounds[SND_PARTICLE] = Mix_LoadWAV("sound/77087__supraliminal__laser-short.ogg");
sounds[SND_MISSILE] = Mix_LoadWAV("sound/65787__iwilldstroyu__laserrocket.ogg");
sounds[SND_BOOST] = Mix_LoadWAV("sound/18380__inferno__hvrl.ogg");
/*sounds[SND_ECM] = Mix_LoadWAV("sound/18380__inferno__hvrl.ogg");*/
sounds[SND_RADIO] = Mix_LoadWAV("sound/321906__bruce965__walkie-talkie-roger-beep.ogg");
sounds[SND_INCOMING] = Mix_LoadWAV("sound/242856__plasterbrain__nuclear-alarm.ogg");
sounds[SND_GET_ITEM] = Mix_LoadWAV("sound/88275__s-dij__gbc-reload-06.ogg");
sounds[SND_EXPLOSION_1] = Mix_LoadWAV("sound/162265__qubodup__explosive.ogg");
sounds[SND_EXPLOSION_2] = Mix_LoadWAV("sound/207322__animationisaac__short-explosion.ogg");
sounds[SND_EXPLOSION_3] = Mix_LoadWAV("sound/254071__tb0y298__firework-explosion.ogg");
sounds[SND_EXPLOSION_4] = Mix_LoadWAV("sound/47252__nthompson__bad-explosion.ogg");
sounds[SND_ARMOUR_HIT] = Mix_LoadWAV(getFileLocation("sound/275151__bird-man__gun-shot.ogg"));
sounds[SND_SHIELD_HIT] = Mix_LoadWAV(getFileLocation("sound/49678__ejfortin__energy-short-sword-7.ogg"));
sounds[SND_PLASMA] = Mix_LoadWAV(getFileLocation("sound/268344__julien-matthey__jm-noiz-laser-01.ogg"));
sounds[SND_LASER] = Mix_LoadWAV(getFileLocation("sound/18382__inferno__hvylas.ogg"));
sounds[SND_MAG] = Mix_LoadWAV(getFileLocation("sound/146725__fins__laser.ogg"));
sounds[SND_SHIELD_BREAK] = Mix_LoadWAV(getFileLocation("sound/322603__clippysounds__glass-break.ogg"));
sounds[SND_PARTICLE] = Mix_LoadWAV(getFileLocation("sound/77087__supraliminal__laser-short.ogg"));
sounds[SND_MISSILE] = Mix_LoadWAV(getFileLocation("sound/65787__iwilldstroyu__laserrocket.ogg"));
sounds[SND_BOOST] = Mix_LoadWAV(getFileLocation("sound/18380__inferno__hvrl.ogg"));
sounds[SND_RADIO] = Mix_LoadWAV(getFileLocation("sound/321906__bruce965__walkie-talkie-roger-beep.ogg"));
sounds[SND_INCOMING] = Mix_LoadWAV(getFileLocation("sound/242856__plasterbrain__nuclear-alarm.ogg"));
sounds[SND_GET_ITEM] = Mix_LoadWAV(getFileLocation("sound/88275__s-dij__gbc-reload-06.ogg"));
sounds[SND_EXPLOSION_1] = Mix_LoadWAV(getFileLocation("sound/162265__qubodup__explosive.ogg"));
sounds[SND_EXPLOSION_2] = Mix_LoadWAV(getFileLocation("sound/207322__animationisaac__short-explosion.ogg"));
sounds[SND_EXPLOSION_3] = Mix_LoadWAV(getFileLocation("sound/254071__tb0y298__firework-explosion.ogg"));
sounds[SND_EXPLOSION_4] = Mix_LoadWAV(getFileLocation("sound/47252__nthompson__bad-explosion.ogg"));
sounds[SND_GUI_CLICK] = Mix_LoadWAV("sound/257786__xtrgamr__mouse-click.ogg");
sounds[SND_GUI_SELECT] = Mix_LoadWAV("sound/321104__nsstudios__blip2.ogg");
sounds[SND_GUI_CLOSE] = Mix_LoadWAV("sound/178064__jorickhoofd__slam-door-shut.ogg");
sounds[SND_GUI_DENIED] = Mix_LoadWAV("sound/249300__suntemple__access-denied.ogg");
sounds[SND_GUI_CLICK] = Mix_LoadWAV(getFileLocation("sound/257786__xtrgamr__mouse-click.ogg"));
sounds[SND_GUI_SELECT] = Mix_LoadWAV(getFileLocation("sound/321104__nsstudios__blip2.ogg"));
sounds[SND_GUI_CLOSE] = Mix_LoadWAV(getFileLocation("sound/178064__jorickhoofd__slam-door-shut.ogg"));
sounds[SND_GUI_DENIED] = Mix_LoadWAV(getFileLocation("sound/249300__suntemple__access-denied.ogg"));
}
void destroySounds(void)

View File

@ -28,5 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MAX_BATTLE_SOUND_DISTANCE 1500
extern int getDistance(int x1, int y1, int x2, int y2);
extern char *getFileLocation(char *filename);
extern Entity *player;

View File

@ -60,7 +60,7 @@ static SDL_Texture *loadTexture(char *filename)
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
texture = IMG_LoadTexture(app.renderer, filename);
texture = IMG_LoadTexture(app.renderer, getFileLocation(filename));
addTextureToCache(filename, texture);

View File

@ -23,4 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../defs.h"
#include "../structs.h"
extern char *getFileLocation(char *filename);
extern App app;

View File

@ -45,7 +45,7 @@ void initWidgets(void)
optionsLeft = getTexture("gfx/widgets/optionsLeft.png");
optionsRight = getTexture("gfx/widgets/optionsRight.png");
loadWidgets("data/widgets/list.json");
loadWidgets(getFileLocation("data/widgets/list.json"));
drawingWidgets = 0;
}
@ -231,12 +231,12 @@ static void loadWidgets(char *filename)
cJSON *root, *node;
char *text;
text = readFile(filename);
text = readFile(getFileLocation(filename));
root = cJSON_Parse(text);
for (node = root->child ; node != NULL ; node = node->next)
{
loadWidgetSet(node->valuestring);
loadWidgetSet(getFileLocation(node->valuestring));
}
cJSON_Delete(root);
@ -251,7 +251,7 @@ static void loadWidgetSet(char *filename)
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
text = readFile(filename);
text = readFile(getFileLocation(filename));
root = cJSON_Parse(text);
for (node = root->child ; node != NULL ; node = node->next)

View File

@ -32,6 +32,7 @@ extern void blit(SDL_Texture *texture, int x, int y, int centered);
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 void playSound(int id);
extern char *getFileLocation(char *filename);
extern App app;
extern Colors colors;