- Ara gamestate_sequence llig les sequències en format text.

- Llevades totes les sequències en format binari.
This commit is contained in:
2023-10-13 12:15:13 +02:00
parent c905e5be1f
commit f9103548cf
9 changed files with 55 additions and 94 deletions

View File

@@ -19,30 +19,9 @@ namespace gamestate
{
namespace sequence
{
int num_diapositives = 0;
char *sequence_file = nullptr;
char *sfpointer = nullptr;
FILE *sequence_file = nullptr;
uint32_t wait_until = 0;
uint8_t getByte()
{
return *(sequence_file++);
}
uint16_t getWord()
{
return getByte() + (getByte() << 8);
}
std::string getString()
{
uint8_t tamanyCadena = getByte();
char filename[256];
for (int i=0; i<tamanyCadena; i++) filename[i] = getByte();
filename[tamanyCadena] = '\0';
return std::string(filename);
}
void drawPic(std::string filename)
{
draw::surface *pic = draw::loadSurface(filename, true);
@@ -82,13 +61,15 @@ namespace gamestate
{
if (!draw::isfading() && (input::anyKeyPressed() || input::mouseBtn(1))) {
wait_until=0;
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) num_diapositives=0;
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) fseek(sequence_file, 0, SEEK_END);
} else {
draw::render();
return true;
}
}
if (num_diapositives==0) {
if (feof(sequence_file))
{
fclose(sequence_file);
const int fase = game::getConfig("fase");
if ( fase == -1 || fase == 30) {
gamestate::menu::init();
@@ -96,70 +77,52 @@ namespace gamestate
gamestate::prefase::init();
}
free(sfpointer);
return true;
}
const char tipo_diapositiva = *(sequence_file++);
switch ( tipo_diapositiva )
{
case DIAPO_ESPERAR:
} else {
char text[100];
int x, y, val;
int res = fscanf(sequence_file, "%s", text);
if (res==1)
{
const uint16_t time = getWord();
wait_until = SDL_GetTicks() + time;
printf("- Esperar(%i)\n", time);
break;
std::string command(text);
if (command=="ESPERAR") {
int res = fscanf(sequence_file, "%i", &val);
wait_until = SDL_GetTicks() + val;
} else if (command=="FADEIN") {
int res = fscanf(sequence_file, " '%[^']'", text);
drawPic(text);
draw::fadein();
draw::render();
wait_until = SDL_GetTicks() + 500;
} else if (command=="SHOW") {
int res = fscanf(sequence_file, " '%[^']'", text);
drawPic(text);
draw::render();
} else if (command=="PRINT") {
int res = fscanf(sequence_file, " %i %i %i '%[^']'", &x, &y, &val, text);
drawText(x, y, val, text);
} else if (command=="PLAYMUSIC") {
int res = fscanf(sequence_file, " '%[^']'", text);
audio::playMusic(audio::loadMusic(text));
} else if (command=="FADEOUT") {
draw::fadeout();
wait_until = SDL_GetTicks() + 500;
} else if (command=="FADEOUTMUSIC") {
draw::fadeout();
audio::fadeoutMusic();
wait_until = SDL_GetTicks() + 500;
}
}
case DIAPO_FADEIN:
{
std::string filename = getString();
drawPic(filename);
draw::fadein();
draw::render();
wait_until = SDL_GetTicks() + 500;
printf("- FadeIn('%s')\n", filename.c_str());
break;
}
case DIAPO_SHOW:
{
std::string filename = getString();
drawPic(filename);
draw::render();
printf("- Show('%s')\n", filename.c_str());
break;
}
case DIAPO_PRINT:
{
const uint16_t x = getWord();
const uint16_t y = getWord();
const uint8_t col = getByte();
std::string text = getString();
drawText(x, y, col, text);
printf("- Print(%i, %i, %i, '%s')\n", x, y, col, text.c_str());
break;
}
case DIAPO_MUSICA:
{
std::string filename = getString();
audio::playMusic(audio::loadMusic(filename));
printf("- PlayMusic('%s')\n", filename.c_str());
break;
}
case DIAPO_FADEOUT:
{
draw::fadeout();
wait_until = SDL_GetTicks() + 500;
printf("- FadeOut()\n");
break;
}
case DIAPO_FADEMUSIC:
draw::fadeout();
audio::fadeoutMusic();
wait_until = SDL_GetTicks() + 500;
printf("- FadeOutMusic()\n");
break;
}
num_diapositives--;
return true;
}
@@ -171,20 +134,18 @@ namespace gamestate
switch (fase)
{
case -1: filename = "seqIN.seq"; break;
case 0: filename = "seq00.seq"; break;
case 5: filename = "seq05.seq"; break;
case 10: filename = "seq10.seq"; break;
case 15: filename = "seq15.seq"; break;
case 20: filename = "seq20.seq"; break;
case 25: filename = "seq25.seq"; break;
case 30: filename = "seq30.seq"; break;
case -1: filename = "seqIN.txt"; break;
case 0: filename = "seq00.txt"; break;
case 5: filename = "seq05.txt"; break;
case 10: filename = "seq10.txt"; break;
case 15: filename = "seq15.txt"; break;
case 20: filename = "seq20.txt"; break;
case 25: filename = "seq25.txt"; break;
case 30: filename = "seq30.txt"; break;
}
int filesize;
sequence_file = file::getFileBuffer(filename, filesize);
sfpointer = sequence_file;
num_diapositives = *(sequence_file++);
sequence_file = file::getFilePointer(filename, filesize);
game::setState(&gamestate::sequence::loop);
}