5#ifndef GAMESTATE_DATABASE_H
6#define GAMESTATE_DATABASE_H
11#define MAX_NUMBER_SAVES 20
12#define TIMESTAMP_LENGTH 20
14#define SQL_CREATE_TABLES_GAMESTATE_GS \
15 "CREATE TABLE IF NOT EXISTS \"game_state\" (" \
16 "\"GS_ID\" INTEGER NOT NULL UNIQUE," \
17 "\"GS_SAVEDTIME\" TEXT," \
19 "PRIMARY KEY(\"GS_ID\" AUTOINCREMENT)" \
21#define SQL_CREATE_TABLES_GAMESTATE_MS \
22 "CREATE TABLE IF NOT EXISTS \"map_state\" (" \
23 "\"MS_ID\" INTEGER NOT NULL UNIQUE," \
25 "\"MS_REVEALED\" TEXT," \
26 "\"MS_HEIGHT\" INTEGER," \
27 "\"MS_WIDTH\" INTEGER," \
28 "\"MS_GS_ID\" INTEGER NOT NULL UNIQUE," \
29 "PRIMARY KEY(\"MS_ID\" AUTOINCREMENT)," \
30 "FOREIGN KEY(\"MS_GS_ID\") REFERENCES \"game_state\"(\"GS_ID\")" \
32#define SQL_CREATE_TABLES_GAMESTATE_PS \
33 "CREATE TABLE IF NOT EXISTS \"player_state\" (" \
34 "\"PS_ID\" INTEGER NOT NULL UNIQUE," \
37 "\"PS_GS_ID\" INTEGER NOT NULL UNIQUE," \
38 "PRIMARY KEY(\"PS_ID\" AUTOINCREMENT)," \
39 "FOREIGN KEY(\"PS_GS_ID\") REFERENCES \"game_state\"(\"GS_ID\")" \
42typedef void (*player_pos_setter_t)(
int player_x,
int player_y);
46 char timestamp[TIMESTAMP_LENGTH];
47 char name[MAX_STRING_LENGTH];
Defines common macros, types, and global variables for color schemes and utilities.
Exposes functions for working with the database.
void create_tables_game_state(const db_connection_t *db_connection)
Create the tables for the game state.
int get_game_state(const db_connection_t *db_connection, int *map, int *revealed_map, int width, int height, player_pos_setter_t setter)
Load the game state from the database.
char * arr2D_to_flat_json(const int *arr, int width, int height)
Convert a 2D array to a Json-Array.
int get_game_state_by_id(const db_connection_t *db_connection, int game_state_id, int *map, int *revealed_map, int width, int height, player_pos_setter_t setter)
Load the game state for a specific id from the database.
int get_latest_save_id(const db_connection_t *db_connection)
sqlite_int64 save_game_state(const db_connection_t *db_connection, const int *map, const int *revealed_map, int width, int height, vector2d_t player, const char *save_name)
Save the game state.
save_info_container_t * get_save_infos(const db_connection_t *db_connection)
Get the info of the saves.
void free_save_infos(save_info_container_t *save_infos)
Free the resources associated with a save_info_container.
This struct is used for the database connection in SQLite.
2-dimensional vector struct