Character bounds are stored in the server database
This allows for customization of bounding boxes, as well as highlighting aspects needed when adding new fields to the characters.
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "sqlite3.h"
|
||||
|
||||
#include "character_defines.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -30,10 +32,45 @@
|
||||
//Define the queries
|
||||
//-------------------------
|
||||
|
||||
static const char* CREATE_CHARACTER = "INSERT INTO Characters (owner, handle, avatar) VALUES (?, ?, ?);";
|
||||
static const char* LOAD_CHARACTER = "SELECT * FROM Characters WHERE handle = ?;";
|
||||
static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET roomIndex = ?2, originX = ?3, originY = ?4 WHERE uid = ?1;";
|
||||
//NOTE: Programmer set variables are NOT zero-indexed
|
||||
//NOTE: SQLite3 returned variables (i.e. loading) ARE zero-indexed
|
||||
|
||||
static const char* CREATE_CHARACTER = "INSERT INTO Characters ("
|
||||
"owner, "
|
||||
"handle, "
|
||||
"avatar, "
|
||||
"boundsX, "
|
||||
"boundsY, "
|
||||
"boundsW, "
|
||||
"boundsH"
|
||||
") VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7);";
|
||||
|
||||
static const char* LOAD_CHARACTER = "SELECT "
|
||||
"uid, "
|
||||
"owner, "
|
||||
"handle, "
|
||||
"avatar, "
|
||||
"roomIndex, "
|
||||
"originX, "
|
||||
"originY, "
|
||||
"boundsX, "
|
||||
"boundsY, "
|
||||
"boundsW, "
|
||||
"boundsH "
|
||||
"FROM Characters WHERE handle = ?;";
|
||||
|
||||
static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET "
|
||||
"roomIndex = ?2, "
|
||||
"originX = ?3, "
|
||||
"originY = ?4, "
|
||||
"boundsX = ?5, "
|
||||
"boundsY = ?6, "
|
||||
"boundsW = ?7, "
|
||||
"boundsH = ?8 "
|
||||
"WHERE uid = ?1;";
|
||||
|
||||
static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;";
|
||||
|
||||
static const char* COUNT_CHARACTER_RECORDS = "SELECT COUNT(*) FROM Characters;";
|
||||
|
||||
//-------------------------
|
||||
@@ -55,6 +92,10 @@ int CharacterManager::Create(int owner, std::string handle, std::string avatar)
|
||||
ret |= sqlite3_bind_int(statement, 1, owner);
|
||||
ret |= sqlite3_bind_text(statement, 2, handle.c_str(), handle.size() + 1, SQLITE_STATIC);
|
||||
ret |= sqlite3_bind_text(statement, 3, avatar.c_str(), avatar.size() + 1, SQLITE_STATIC);
|
||||
ret |= sqlite3_bind_int(statement, 4, CHARACTER_BOUNDS_X);
|
||||
ret |= sqlite3_bind_int(statement, 5, CHARACTER_BOUNDS_Y);
|
||||
ret |= sqlite3_bind_int(statement, 6, CHARACTER_BOUNDS_WIDTH);
|
||||
ret |= sqlite3_bind_int(statement, 7, CHARACTER_BOUNDS_HEIGHT);
|
||||
|
||||
//check for binding errors
|
||||
if (ret) {
|
||||
@@ -121,9 +162,14 @@ int CharacterManager::Load(int owner, std::string handle, std::string avatar) {
|
||||
//Don't cache the birth
|
||||
|
||||
//world origin
|
||||
newChar.roomIndex = sqlite3_column_int(statement, 5);
|
||||
newChar.origin.x = (double)sqlite3_column_int(statement, 6);
|
||||
newChar.origin.y = (double)sqlite3_column_int(statement, 7);
|
||||
newChar.roomIndex = sqlite3_column_int(statement, 4);
|
||||
newChar.origin.x = (double)sqlite3_column_int(statement, 5);
|
||||
newChar.origin.y = (double)sqlite3_column_int(statement, 6);
|
||||
//bounds
|
||||
newChar.bounds.x = (int)sqlite3_column_int(statement, 7);
|
||||
newChar.bounds.y = (int)sqlite3_column_int(statement, 8);
|
||||
newChar.bounds.w = (int)sqlite3_column_int(statement, 9);
|
||||
newChar.bounds.h = (int)sqlite3_column_int(statement, 10);
|
||||
|
||||
//gameplay components: equipment, items, buffs, debuffs...
|
||||
|
||||
@@ -165,6 +211,10 @@ int CharacterManager::Save(int uid) {
|
||||
ret |= sqlite3_bind_int(statement, 2, character.roomIndex) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 3, (int)character.origin.x) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 4, (int)character.origin.y) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 5, character.bounds.x) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 6, character.bounds.y) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 7, character.bounds.w) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 8, character.bounds.h) != SQLITE_OK;
|
||||
|
||||
//gameplay components: equipment, items, buffs, debuffs...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user