- [NEW] Mogut tot el codi de lloc

This commit is contained in:
2025-07-02 13:36:48 +02:00
parent 4670b52378
commit 81c5011bc7
34 changed files with 52 additions and 52 deletions

56
source/aux/font.cpp Normal file
View File

@@ -0,0 +1,56 @@
#include "font.h"
#include "../japi/game.h"
namespace font
{
static draw::surface *font1 = nullptr;
static draw::surface *font2 = nullptr;
static int mode = font::type::normal;
void init()
{
font::font1 = draw::loadSurface("fuente1.gif");
font::font2 = draw::loadSurface("fuente2.gif");
}
void selectFont(const int which)
{
font::mode = which;
}
void setColor(const int color)
{
switch (color) {
case font::color::white: draw::setPaletteEntry(63, 255, 255, 255); break;
case font::color::red: draw::setPaletteEntry(63, 255, 0, 0); break;
case font::color::green: draw::setPaletteEntry(63, 0, 255, 0); break;
case font::color::blue: draw::setPaletteEntry(63, 0, 0, 255); break;
}
}
void print(const int x, const int y, const std::string text)
{
draw::setSource(font::mode == font::type::colored ? font::font2 : font::font1);
if (font::mode == font::type::fade) for (int i=64;i<=67;++i) draw::swapcol(i, i+4);
const int len = text.length();
for (int i=0;i<len;++i)
{
char chr = text[i];
if (font::mode == font::type::colored)
draw::draw(x+i*7, y, 6, 6, (int(chr)-32)*7, 0);
else
draw::draw(x+i*7, y, 5, 5, (int(chr)-32)*7, 0);
}
for (int i=64;i<=67;++i) draw::restorecol(i);
}
void print(const int x, const int y, const int num)
{
const char txt[3] = { char(num/10 + 48), char(num%10 + 48), 0 };
print(x, y, txt);
}
}

28
source/aux/font.h Normal file
View File

@@ -0,0 +1,28 @@
#pragma once
#include <string>
namespace font
{
namespace type
{
const int normal = 0;
const int colored = 1;
const int fade = 2;
}
namespace color
{
const int white = 0;
const int red = 1;
const int green = 2;
const int blue = 3;
}
void init();
void selectFont(const int which);
void setColor(const int color);
void print(const int x, const int y, const std::string text);
void print(const int x, const int y, const int num);
}

68
source/aux/textfile.cpp Normal file
View File

@@ -0,0 +1,68 @@
#include "textfile.h"
#include "../japi/game.h"
#include <stdlib.h>
namespace textfile
{
char *buffer = nullptr;
int fsize = 0;
int p = 0;
const int toInt(std::string token)
{
int value = 0;
for (std::size_t i=0; i<token.length(); ++i)
{
if (token[i]<48 || token[i]>57) return 0;
value = (value*10) + (token[i]-48);
}
return value;
}
const bool open(std::string filename)
{
buffer = file::getFileBuffer(filename.c_str(), fsize);
p = 0;
return true;
}
void close()
{
free(buffer);
}
std::string getNextToken()
{
char token[255];
int tpos = 0;
// Ignore whitespace
while (p<fsize && buffer[p]<=32 ) p++;
// Grab token
while (p<fsize && buffer[p]>32 ) token[tpos++]=buffer[p++];
token[tpos]=0;
return std::string(token);
}
const bool searchToken(std::string token)
{
while (p<fsize && getNextToken() != token) p++;
return p<fsize;
}
std::string getStringValue(std::string token)
{
textfile::searchToken(token);
textfile::searchToken("=");
return textfile::getNextToken();
}
const int getIntValue(std::string token)
{
return toInt(getStringValue(token));
}
}

20
source/aux/textfile.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include <string>
namespace textfile
{
const int toInt(std::string token);
const bool open(std::string filename);
void close();
std::string getNextToken();
const bool searchToken(std::string token);
std::string getStringValue(std::string token);
const int getIntValue(std::string token);
}