Modified tile_editor and engine for OS X to change the cwd to the directory of the app bundle. Also lightly modified the engine to check modules/ and ../modules for... modules

vashram
kts 2014-11-18 12:56:44 -08:00
parent 59beaa02ba
commit d252677df2
5 changed files with 65 additions and 7 deletions

View File

@ -1,8 +1,32 @@
#include "globals.h"
#include "interfaces.h"
#include "../common/fio.h"
#ifdef __APPLE__
#include "CoreFoundation/CoreFoundation.h"
#endif
int main(int argc, char *argv[]) {
#ifdef __APPLE__
char path[PATH_MAX];
CFURLRef res = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
CFURLGetFileSystemRepresentation(res, TRUE, (UInt8 *)path, PATH_MAX);
CFRelease(res);
// there's likely a better way to do this!
size_t path_len = strlen(path);
int i = path_len;
int p_c = 0;
while (i > 0) {
if (path[i] == '/') {
p_c++;
}
if (p_c == 3) break;
i--;
}
char bundle_path[i+1];
memcpy(bundle_path, path, i);
bundle_path[i] = '\0';
chdir(bundle_path);
#endif
// let's load in our config file
int buffer_size = 0;
char *memory;
@ -22,8 +46,12 @@ int main(int argc, char *argv[]) {
addTablePairInt(g_settings, "clock", 0);
}
// let's search for modules!
if ((g_modules_list = dirToLList("../modules", F_DIRS)) == NULL)
printf("ERR: no modules found\n");
if ((g_modules_list = dirToLList("modules", F_DIRS)) == NULL) {
printf("ERR: no modules found in \"modules/\"\n");
if ((g_modules_list = dirToLList("../modules", F_DIRS)) == NULL) {
printf("ERR: no modules found in \"../modules\"\n");
}
}
/*printf("modules:\n");
struct LList *llist = g_modules_list;
while (llist) {

@ -1 +1 @@
Subproject commit 00b4a72fd839de33e545795696fd8c71236a589a
Subproject commit 90a0b3b4846cd3a761acf34b900c4a0ee8848624

View File

@ -4,6 +4,7 @@
#include "state_test.h"
#include "../../common/fio.h"
#include "../sdl/spritesheets.h" // FIXME: implicit declaration problems.
#include <unistd.h> // access()
/* allocate memory for menu */
void initModulesState() {
@ -11,6 +12,12 @@ void initModulesState() {
s_modules_elements->user = g_screen;
s_active_element = NULL;
if (access("modules", F_OK) != -1) {
strcpy(s_modules_dir, "modules");
} else if (access("../modules", F_OK) != -1) {
strcpy(s_modules_dir, "../modules");
}
struct Dimension dimen = { 0, 0, 128, 32};
struct Element *element;
struct LList *llist = g_modules_list;
@ -143,7 +150,7 @@ void ModulesState_loadModule(struct Element *element) {
int size = 0;
/* load module/CONF */
sprintf(temp, "../modules/%s/CONF", module_name);
sprintf(temp, "%s/%s/CONF", s_modules_dir, module_name);
printf("attempting to load %s\n", temp);
if (g_module_conf == NULL) {
g_module_conf = newTable(16);
@ -168,7 +175,7 @@ void ModulesState_loadModule(struct Element *element) {
} else {
struct Table *sprites_conf = NULL;
// Load our spritesheet CONF
sprintf(temp, "../modules/%s/sprites/CONF", module_name);
sprintf(temp, "%s/%s/sprites/CONF", s_modules_dir, module_name);
printf("attempting to load %s\n", temp);
if (sprites_conf == NULL) {
sprites_conf = newTable(16);
@ -197,7 +204,7 @@ void ModulesState_loadModule(struct Element *element) {
// i should be equal to spritesheet count
g_module_spritesheets = malloc(sizeof(struct Spritesheet*)*i);
while(i > 0) {
sprintf(temp, "../modules/%s/sprites/%s", module_name, (char*)sprites_table->pair[i-1]->value);
sprintf(temp, "%s/%s/sprites/%s", s_modules_dir, module_name, (char*)sprites_table->pair[i-1]->value);
printf(" attempting to load %s\n", temp);
g_module_spritesheets[i-1] = newSpritesheet();
struct Table *sheet_conf = getTablePairValueTable(sprites_conf, (char*)sprites_table->pair[i-1]->value);
@ -222,7 +229,7 @@ void ModulesState_loadModule(struct Element *element) {
}
}
sprintf(temp, "../modules/%s/%s.tsd", module_name, module_name);
sprintf(temp, "%s/%s/%s.tsd", s_modules_dir, module_name, module_name);
printf("attempting to load %s\n", temp);
size = fileToMemory(&buffer, temp);
if (size > 0) {

View File

@ -17,6 +17,7 @@ struct ElementList *s_modules_elements;
struct Element *s_active_element;
char s_modules_dir[128];
/* local functions */
void ModulesState_loadModule(struct Element *element);

View File

@ -3,6 +3,7 @@
#include <SDL/SDL_image.h>
#else
#include <SDL_image.h>
#include "CoreFoundation/CoreFoundation.h" // yee apple path rubbish
#endif
#include <SDL/SDL_syswm.h> // for wm hints
@ -19,6 +20,27 @@
#include "../common/fio.h"
int interfaceInit() {
#ifdef __APPLE__
char path[PATH_MAX];
CFURLRef res = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
CFURLGetFileSystemRepresentation(res, TRUE, (UInt8 *)path, PATH_MAX);
CFRelease(res);
// there's likely a better way to do this!
size_t path_len = strlen(path);
int p_i = path_len;
int p_c = 0;
while (p_i > 0) {
if (path[p_i] == '/') {
p_c++;
}
if (p_c == 3) break;
p_i--;
}
char bundle_path[p_i+1];
memcpy(bundle_path, path, p_i);
bundle_path[p_i] = '\0';
chdir(bundle_path);
#endif
// TODO: move to newData function
tiles_data = malloc(sizeof(struct Data));
tiles_data->size = SET_SIZE;