DungeonCrawl
Loading...
Searching...
No Matches
gamestate_database.h
Go to the documentation of this file.
1
5#ifndef GAMESTATE_DATABASE_H
6#define GAMESTATE_DATABASE_H
7
8#include "../../common.h"
9#include "../database.h"
10
11#define MAX_NUMBER_SAVES 20
12#define TIMESTAMP_LENGTH 20
13
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," \
18 "\"GS_NAME\" TEXT," \
19 "PRIMARY KEY(\"GS_ID\" AUTOINCREMENT)" \
20 ");"
21#define SQL_CREATE_TABLES_GAMESTATE_MS \
22 "CREATE TABLE IF NOT EXISTS \"map_state\" (" \
23 "\"MS_ID\" INTEGER NOT NULL UNIQUE," \
24 "\"MS_MAP\" TEXT," \
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\")" \
31 ");"
32#define SQL_CREATE_TABLES_GAMESTATE_PS \
33 "CREATE TABLE IF NOT EXISTS \"player_state\" (" \
34 "\"PS_ID\" INTEGER NOT NULL UNIQUE," \
35 "\"PS_X\" INTEGER," \
36 "\"PS_Y\" INTEGER," \
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\")" \
40 ");"
41
42typedef void (*player_pos_setter_t)(int player_x, int player_y);
43
44typedef struct {
45 int id;
46 char timestamp[TIMESTAMP_LENGTH];
47 char name[MAX_STRING_LENGTH];
49
50typedef struct {
51 int count;
52 save_info_t* infos;
54
60void create_tables_game_state(const db_connection_t* db_connection);
73sqlite_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);
85int get_game_state(const db_connection_t* db_connection, int* map, int* revealed_map, int width, int height, player_pos_setter_t setter);
98int 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);
111void free_save_infos(save_info_container_t* save_infos);
112
113
122char* arr2D_to_flat_json(const int* arr, int width, int height);
123
129int get_latest_save_id(const db_connection_t* db_connection);
130#endif//GAMESTATE_DATABASE_H
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.
Definition database.h:22
2-dimensional vector struct
Definition common.h:164