project loads in surf
This commit is contained in:
parent
46e62e4eb2
commit
6970c90979
|
@ -62,8 +62,6 @@ static struct
|
|||
.fast = false,
|
||||
};
|
||||
|
||||
static const char CartExt[] = ".tic";
|
||||
|
||||
static const char DefaultLuaTicPath[] = TIC_LOCAL "default.tic";
|
||||
static const char DefaultMoonTicPath[] = TIC_LOCAL "default_moon.tic";
|
||||
static const char DefaultJSTicPath[] = TIC_LOCAL "default_js.tic";
|
||||
|
@ -85,7 +83,7 @@ static const char* getName(const char* name, const char* ext)
|
|||
|
||||
static const char* getCartName(const char* name)
|
||||
{
|
||||
return getName(name, CartExt);
|
||||
return getName(name, CART_EXT);
|
||||
}
|
||||
|
||||
static void scrollBuffer(char* buffer)
|
||||
|
@ -342,12 +340,12 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
|
|||
|
||||
for(s32 i = 0; i < COUNT_OF(Sections); i++)
|
||||
{
|
||||
sprintf(buf, "%s %s", CartExt, Sections[i]);
|
||||
sprintf(buf, "%s %s", CART_EXT, Sections[i]);
|
||||
char* pos = SDL_strstr(param, buf);
|
||||
|
||||
if(pos)
|
||||
{
|
||||
pos[sizeof(CartExt) - 1] = 0;
|
||||
pos[sizeof(CART_EXT) - 1] = 0;
|
||||
const char* name = getCartName(param);
|
||||
s32 size = 0;
|
||||
void* data = fsLoadFile(console->fs, name, &size);
|
||||
|
@ -1564,11 +1562,9 @@ static void onConsoleExportCommand(Console* console, const char* param)
|
|||
|
||||
#if defined(TIC80_PRO)
|
||||
|
||||
static const char ProjectExt[] = ".ticp";
|
||||
|
||||
static const char* getProjectName(const char* name)
|
||||
{
|
||||
return getName(name, ProjectExt);
|
||||
return getName(name, PROJECT_EXT);
|
||||
}
|
||||
|
||||
static void buf2str(const void* data, s32 size, char* ptr, bool flip)
|
||||
|
@ -2671,7 +2667,7 @@ static void cmdLoadCart(Console* console, const char* name)
|
|||
if(data)
|
||||
{
|
||||
#if defined(TIC80_PRO)
|
||||
if(strstr(name, ProjectExt) == name + strlen(name) - strlen(ProjectExt))
|
||||
if(strstr(name, PROJECT_EXT) == name + strlen(name) - strlen(PROJECT_EXT))
|
||||
{
|
||||
loadProject(console, data, size, &embed.file);
|
||||
}
|
||||
|
@ -2820,6 +2816,13 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
|
|||
.tic = tic,
|
||||
.config = config,
|
||||
.load = onConsoleLoadCommandConfirmed,
|
||||
|
||||
#if defined(TIC80_PRO)
|
||||
.loadProject = loadProject,
|
||||
#else
|
||||
.loadProject = NULL,
|
||||
#endif
|
||||
|
||||
.error = error,
|
||||
.trace = trace,
|
||||
.tick = tick,
|
||||
|
|
|
@ -90,6 +90,7 @@ struct Console
|
|||
bool showGameMenu;
|
||||
|
||||
void(*load)(Console*, const char* name);
|
||||
bool(*loadProject)(Console*, const char* data, s32 size, tic_cartridge* dst);
|
||||
void(*error)(Console*, const char*);
|
||||
void(*trace)(Console*, const char*, u8 color);
|
||||
void(*tick)(Console*);
|
||||
|
|
|
@ -60,6 +60,9 @@
|
|||
#define KEYMAP_DAT "keymap.dat"
|
||||
#define KEYMAP_DAT_PATH TIC_LOCAL KEYMAP_DAT
|
||||
|
||||
#define CART_EXT ".tic"
|
||||
#define PROJECT_EXT ".ticp"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct
|
||||
|
|
57
src/surf.c
57
src/surf.c
|
@ -155,6 +155,7 @@ struct MenuItem
|
|||
s32 id;
|
||||
tic_screen* cover;
|
||||
bool dir;
|
||||
bool project;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
|
@ -372,13 +373,29 @@ static void replace(char* src, const char* what, const char* with)
|
|||
}
|
||||
}
|
||||
|
||||
static bool hasExt(const char* name, const char* ext)
|
||||
{
|
||||
return strstr(name, ext) == name + strlen(name) - strlen(ext);
|
||||
}
|
||||
|
||||
static void cutExt(char* name, const char* ext)
|
||||
{
|
||||
name[strlen(name)-strlen(ext)] = '\0';
|
||||
}
|
||||
|
||||
static bool addMenuItem(const char* name, const char* info, s32 id, void* ptr, bool dir)
|
||||
{
|
||||
AddMenuItem* data = (AddMenuItem*)ptr;
|
||||
|
||||
static const char CartExt[] = ".tic";
|
||||
static const char CartExt[] = CART_EXT;
|
||||
static const char ProjectExt[] = PROJECT_EXT;
|
||||
|
||||
if(dir || (strstr(name, CartExt) == name + strlen(name) - sizeof(CartExt)+1))
|
||||
if(dir
|
||||
|| hasExt(name, CartExt)
|
||||
#if defined(TIC80_PRO)
|
||||
|| hasExt(name, ProjectExt)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
MenuItem* item = &data->items[data->count++];
|
||||
|
||||
|
@ -394,7 +411,15 @@ static bool addMenuItem(const char* name, const char* info, s32 id, void* ptr, b
|
|||
{
|
||||
|
||||
item->label = SDL_strdup(name);
|
||||
item->label[strlen(item->label)-sizeof(CartExt)+1] = '\0';
|
||||
|
||||
if(hasExt(name, CartExt))
|
||||
cutExt(item->label, CartExt);
|
||||
else
|
||||
{
|
||||
cutExt(item->label, ProjectExt);
|
||||
item->project = true;
|
||||
}
|
||||
|
||||
|
||||
replace(item->label, "&", "&");
|
||||
replace(item->label, "'", "'");
|
||||
|
@ -509,7 +534,10 @@ static void loadCover(Surf* surf)
|
|||
|
||||
if(cart)
|
||||
{
|
||||
tic->api.load(cart, data, size, true);
|
||||
if(hasExt(item->name, PROJECT_EXT))
|
||||
surf->console->loadProject(surf->console, data, size, cart);
|
||||
else
|
||||
tic->api.load(cart, data, size, true);
|
||||
|
||||
if(cart->cover.size)
|
||||
updateMenuItemCover(surf, cart->cover.data, cart->cover.size);
|
||||
|
@ -617,7 +645,26 @@ static void onPlayCart(Surf* surf)
|
|||
{
|
||||
MenuItem* item = &surf->menu.items[surf->menu.pos];
|
||||
|
||||
surf->console->load(surf->console, item->name);
|
||||
if(item->project)
|
||||
{
|
||||
tic_cartridge* cart = SDL_malloc(sizeof(tic_cartridge));
|
||||
|
||||
if(cart)
|
||||
{
|
||||
s32 size = 0;
|
||||
void* data = fsLoadFile(surf->fs, item->name, &size);
|
||||
|
||||
surf->console->loadProject(surf->console, data, size, cart);
|
||||
|
||||
SDL_memcpy(&surf->tic->cart, cart, sizeof(tic_cartridge));
|
||||
|
||||
studioRomLoaded();
|
||||
|
||||
SDL_free(cart);
|
||||
}
|
||||
}
|
||||
else
|
||||
surf->console->load(surf->console, item->name);
|
||||
|
||||
runGameFromSurf();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue