DungeonCrawl
|
Implements functionality to work with the gamestate and database. More...
#include "gamestate_database.h"
#include "../../logging/logger.h"
#include "../database.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
Go to the source code of this file.
Macros | |
#define | TIMESTAMP_FORMAT "%Y-%m-%d %H:%M:%S" |
#define | SQL_INSERT_GAME_STATE "INSERT INTO game_state (GS_SAVEDTIME, GS_NAME) VALUES (?, ?)" |
#define | SQL_INSERT_MAP_STATE "INSERT INTO map_state (MS_MAP, MS_REVEALED, MS_HEIGHT,MS_WIDTH, MS_GS_ID) VALUES (?, ?, ?, ?, ?)" |
#define | SQL_INSERT_PLAYER_STATE "INSERT INTO player_state (PS_X, PS_Y, PS_GS_ID) VALUES (?, ?, ?)" |
#define | SQL_SELECT_LAST_GAME_STATE "SELECT GS_ID FROM game_state ORDER BY GS_SAVEDTIME DESC LIMIT 1" |
#define | SQL_SELECT_MAP_STATE "SELECT MS_HEIGHT, MS_WIDTH FROM map_state WHERE MS_GS_ID = ?" |
#define | SQL_SELECT_MAP "SELECT value FROM map_state, json_each(map_state.MS_MAP) WHERE MS_GS_ID = ?" |
#define | SQL_SELECT_REVEALED_MAP "SELECT value FROM map_state, json_each(map_state.MS_REVEALED) WHERE MS_GS_ID = ?" |
#define | SQL_SELECT_PLAYER_STATE "SELECT PS_X, PS_Y FROM player_state WHERE PS_GS_ID = ?" |
#define | SQL_SELECT_ALL_GAME_STATES "SELECT GS_ID, GS_SAVEDTIME, GS_NAME FROM game_state ORDER BY GS_SAVEDTIME DESC" |
Functions | |
char * | get_iso8601_time () |
Get the current time in ISO 8601 format. | |
sqlite_int64 | save_game_state (const db_connection_t *db_connection, const int *map, const int *revealed_map, const int width, const int height, const vector2d_t player, const char *save_name) |
Save the game state. | |
char * | arr2D_to_flat_json (const int *arr, const int width, const int height) |
Convert a 2D array to a Json-Array. | |
int | get_game_state (const db_connection_t *db_connection, int *map, int *revealed_map, const int width, const int height, const player_pos_setter_t setter) |
Load the game state from the database. | |
int | get_game_state_by_id (const db_connection_t *db_connection, const int game_state_id, int *map, int *revealed_map, const int width, const int height, const player_pos_setter_t setter) |
Load the game state for a specific id from the database. | |
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. | |
void | create_tables_game_state (const db_connection_t *db_connection) |
Create the tables for the game state. | |
int | get_latest_save_id (const db_connection_t *db_connection) |
Implements functionality to work with the gamestate and database.
Definition in file gamestate_database.c.
#define SQL_INSERT_GAME_STATE "INSERT INTO game_state (GS_SAVEDTIME, GS_NAME) VALUES (?, ?)" |
Definition at line 18 of file gamestate_database.c.
#define SQL_INSERT_MAP_STATE "INSERT INTO map_state (MS_MAP, MS_REVEALED, MS_HEIGHT,MS_WIDTH, MS_GS_ID) VALUES (?, ?, ?, ?, ?)" |
Definition at line 19 of file gamestate_database.c.
#define SQL_INSERT_PLAYER_STATE "INSERT INTO player_state (PS_X, PS_Y, PS_GS_ID) VALUES (?, ?, ?)" |
Definition at line 20 of file gamestate_database.c.
#define SQL_SELECT_ALL_GAME_STATES "SELECT GS_ID, GS_SAVEDTIME, GS_NAME FROM game_state ORDER BY GS_SAVEDTIME DESC" |
Definition at line 26 of file gamestate_database.c.
#define SQL_SELECT_LAST_GAME_STATE "SELECT GS_ID FROM game_state ORDER BY GS_SAVEDTIME DESC LIMIT 1" |
Definition at line 21 of file gamestate_database.c.
#define SQL_SELECT_MAP "SELECT value FROM map_state, json_each(map_state.MS_MAP) WHERE MS_GS_ID = ?" |
Definition at line 23 of file gamestate_database.c.
#define SQL_SELECT_MAP_STATE "SELECT MS_HEIGHT, MS_WIDTH FROM map_state WHERE MS_GS_ID = ?" |
Definition at line 22 of file gamestate_database.c.
#define SQL_SELECT_PLAYER_STATE "SELECT PS_X, PS_Y FROM player_state WHERE PS_GS_ID = ?" |
Definition at line 25 of file gamestate_database.c.
#define SQL_SELECT_REVEALED_MAP "SELECT value FROM map_state, json_each(map_state.MS_REVEALED) WHERE MS_GS_ID = ?" |
Definition at line 24 of file gamestate_database.c.
#define TIMESTAMP_FORMAT "%Y-%m-%d %H:%M:%S" |
Definition at line 16 of file gamestate_database.c.
char * arr2D_to_flat_json | ( | const int * | arr, |
int | width, | ||
int | height ) |
Convert a 2D array to a Json-Array.
arr | The given array to convert to a Json-Array |
width | The width of the array |
height | The height of the array |
Definition at line 203 of file gamestate_database.c.
void create_tables_game_state | ( | const db_connection_t * | db_connection | ) |
Create the tables for the game state.
db_connection | The database connection |
Definition at line 430 of file gamestate_database.c.
void free_save_infos | ( | save_info_container_t * | save_infos | ) |
Free the resources associated with a save_info_container.
save_infos | Save info to free. |
Definition at line 421 of file gamestate_database.c.
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.
db_connection | A database connection. |
map | Pointer to the map to load into. |
revealed_map | Pointer to the revealed map to load into. |
width | Width of the map. |
height | Hieght of the map. |
setter | A setter for the player position. |
Definition at line 231 of file gamestate_database.c.
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.
db_connection | A database connection. |
game_state_id | The id of the game state to be loaded. |
map | Pointer to the map to load into. |
revealed_map | Pointer to the revealed map to load into. |
width | Width of the map. |
height | Hieght of the map. |
setter | A setter for the player position. |
Definition at line 235 of file gamestate_database.c.
char * get_iso8601_time | ( | ) |
Get the current time in ISO 8601 format.
Definition at line 194 of file gamestate_database.c.
int get_latest_save_id | ( | const db_connection_t * | db_connection | ) |
db_connection | Connection to the database |
Definition at line 474 of file gamestate_database.c.
save_info_container_t * get_save_infos | ( | const db_connection_t * | db_connection | ) |
Get the info of the saves.
db_connection | A database connedtion. |
Definition at line 365 of file gamestate_database.c.
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.
db_connection | A database connection. |
map | The current map where nothing is hidden. |
revealed_map | The current state of the revealed map. |
width | The width of the map. |
height | The hight of the map. |
player | The player position. |
save_name | A name for the save file. |
Definition at line 31 of file gamestate_database.c.