mirror of
https://github.com/Relintai/mourne_rcpp_fw.git
synced 2025-01-13 07:41:12 +01:00
Reworked the village related classes to the new style.
This commit is contained in:
parent
f34a592c2c
commit
517402e87e
@ -23,9 +23,10 @@
|
|||||||
|
|
||||||
#include "assignments/assignment_initializer.h"
|
#include "assignments/assignment_initializer.h"
|
||||||
#include "buildings/building_initializer.h"
|
#include "buildings/building_initializer.h"
|
||||||
#include "village/village_initializer.h"
|
|
||||||
#include "weather/weather_initializer.h"
|
#include "weather/weather_initializer.h"
|
||||||
|
|
||||||
|
#include "village/village_node.h"
|
||||||
|
|
||||||
void MourneRoot::handle_request_main(Request *request) {
|
void MourneRoot::handle_request_main(Request *request) {
|
||||||
if (process_middlewares(request)) {
|
if (process_middlewares(request)) {
|
||||||
return;
|
return;
|
||||||
@ -256,13 +257,11 @@ void MourneRoot::setup_middleware() {
|
|||||||
void MourneRoot::create_table() {
|
void MourneRoot::create_table() {
|
||||||
// TODO move these to the node system and remove from here
|
// TODO move these to the node system and remove from here
|
||||||
BuildingController::get_singleton()->create_table();
|
BuildingController::get_singleton()->create_table();
|
||||||
VillageController::get_singleton()->create_table();
|
|
||||||
AssignmentController::get_singleton()->create_table();
|
AssignmentController::get_singleton()->create_table();
|
||||||
WeatherController::get_singleton()->create_table();
|
WeatherController::get_singleton()->create_table();
|
||||||
}
|
}
|
||||||
void MourneRoot::drop_table() {
|
void MourneRoot::drop_table() {
|
||||||
BuildingController::get_singleton()->drop_table();
|
BuildingController::get_singleton()->drop_table();
|
||||||
VillageController::get_singleton()->drop_table();
|
|
||||||
AssignmentController::get_singleton()->drop_table();
|
AssignmentController::get_singleton()->drop_table();
|
||||||
WeatherController::get_singleton()->drop_table();
|
WeatherController::get_singleton()->drop_table();
|
||||||
}
|
}
|
||||||
@ -275,7 +274,6 @@ void MourneRoot::udpate_table() {
|
|||||||
void MourneRoot::create_default_entries() {
|
void MourneRoot::create_default_entries() {
|
||||||
// TODO move these to the node system and remove from here
|
// TODO move these to the node system and remove from here
|
||||||
BuildingController::get_singleton()->create_default_entries();
|
BuildingController::get_singleton()->create_default_entries();
|
||||||
VillageController::get_singleton()->create_default_entries();
|
|
||||||
AssignmentController::get_singleton()->create_default_entries();
|
AssignmentController::get_singleton()->create_default_entries();
|
||||||
WeatherController::get_singleton()->create_default_entries();
|
WeatherController::get_singleton()->create_default_entries();
|
||||||
}
|
}
|
||||||
@ -314,10 +312,13 @@ MourneRoot::MourneRoot() :
|
|||||||
WebRoot() {
|
WebRoot() {
|
||||||
|
|
||||||
BuildingInitializer::allocate_all();
|
BuildingInitializer::allocate_all();
|
||||||
VillageInitializer::allocate_all();
|
|
||||||
AssignmentInitializer::allocate_all();
|
AssignmentInitializer::allocate_all();
|
||||||
WeatherInitializer::allocate_all();
|
WeatherInitializer::allocate_all();
|
||||||
|
|
||||||
|
_village = new VillageNode();
|
||||||
|
_village->set_uri_segment("village");
|
||||||
|
add_child(_village);
|
||||||
|
|
||||||
_admin_panel = new AdminPanel();
|
_admin_panel = new AdminPanel();
|
||||||
_admin_panel->set_uri_segment("admin");
|
_admin_panel->set_uri_segment("admin");
|
||||||
_admin_panel->register_admin_controller("buildings", BuildingController::get_singleton());
|
_admin_panel->register_admin_controller("buildings", BuildingController::get_singleton());
|
||||||
@ -348,7 +349,6 @@ MourneRoot::MourneRoot() :
|
|||||||
}
|
}
|
||||||
|
|
||||||
MourneRoot::~MourneRoot() {
|
MourneRoot::~MourneRoot() {
|
||||||
VillageInitializer::free_all();
|
|
||||||
BuildingInitializer::free_all();
|
BuildingInitializer::free_all();
|
||||||
AssignmentInitializer::free_all();
|
AssignmentInitializer::free_all();
|
||||||
WeatherInitializer::free_all();
|
WeatherInitializer::free_all();
|
||||||
|
@ -12,6 +12,7 @@ class RBACModel;
|
|||||||
class UserController;
|
class UserController;
|
||||||
class MenuNode;
|
class MenuNode;
|
||||||
class MourneUserController;
|
class MourneUserController;
|
||||||
|
class VillageNode;
|
||||||
|
|
||||||
#define ENSURE_LOGIN(request) \
|
#define ENSURE_LOGIN(request) \
|
||||||
if (!is_logged_in(request)) { \
|
if (!is_logged_in(request)) { \
|
||||||
@ -64,6 +65,8 @@ public:
|
|||||||
MourneUserController *_user_controller;
|
MourneUserController *_user_controller;
|
||||||
MenuNode *_menu;
|
MenuNode *_menu;
|
||||||
|
|
||||||
|
VillageNode *_village;
|
||||||
|
|
||||||
static String menu_head;
|
static String menu_head;
|
||||||
static String admin_headers;
|
static String admin_headers;
|
||||||
static String footer;
|
static String footer;
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
#include "village_controller.h"
|
|
||||||
|
|
||||||
#include "web/html/form_validator.h"
|
|
||||||
#include "web/html/html_builder.h"
|
|
||||||
#include "web/http/cookie.h"
|
|
||||||
#include "web/http/http_session.h"
|
|
||||||
#include "web/http/request.h"
|
|
||||||
#include "web/http/session_manager.h"
|
|
||||||
|
|
||||||
#include "village_model.h"
|
|
||||||
|
|
||||||
void VillageController::handle_request_default(Request *request) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void VillageController::create_table() {
|
|
||||||
VillageModel::get_singleton()->create_table();
|
|
||||||
}
|
|
||||||
void VillageController::drop_table() {
|
|
||||||
VillageModel::get_singleton()->drop_table();
|
|
||||||
}
|
|
||||||
void VillageController::create_default_entries() {
|
|
||||||
VillageModel::get_singleton()->create_default_entries();
|
|
||||||
}
|
|
||||||
|
|
||||||
VillageController *VillageController::get_singleton() {
|
|
||||||
return _self;
|
|
||||||
}
|
|
||||||
|
|
||||||
VillageController::VillageController() :
|
|
||||||
Object() {
|
|
||||||
|
|
||||||
if (_self) {
|
|
||||||
printf("VillageController::VillageController(): Error! self is not null!/n");
|
|
||||||
}
|
|
||||||
|
|
||||||
_self = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
VillageController::~VillageController() {
|
|
||||||
if (_self == this) {
|
|
||||||
_self = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VillageController *VillageController::_self = nullptr;
|
|
@ -1,33 +0,0 @@
|
|||||||
#ifndef VILLAGE_CONTROLLER_H
|
|
||||||
#define VILLAGE_CONTROLLER_H
|
|
||||||
|
|
||||||
#include "core/string.h"
|
|
||||||
#include "core/containers/vector.h"
|
|
||||||
|
|
||||||
#include "core/object.h"
|
|
||||||
|
|
||||||
#include "village.h"
|
|
||||||
|
|
||||||
class Request;
|
|
||||||
class FormValidator;
|
|
||||||
|
|
||||||
class VillageController : public Object {
|
|
||||||
RCPP_OBJECT(VillageController, Object);
|
|
||||||
|
|
||||||
public:
|
|
||||||
void create_table();
|
|
||||||
void drop_table();
|
|
||||||
void create_default_entries();
|
|
||||||
|
|
||||||
virtual void handle_request_default(Request *request);
|
|
||||||
|
|
||||||
static VillageController *get_singleton();
|
|
||||||
|
|
||||||
VillageController();
|
|
||||||
~VillageController();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static VillageController *_self;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,37 +0,0 @@
|
|||||||
#include "village_initializer.h"
|
|
||||||
|
|
||||||
void VillageInitializer::allocate_controller() {
|
|
||||||
ERR_FAIL_COND(_controller);
|
|
||||||
|
|
||||||
_controller = new VillageController();
|
|
||||||
}
|
|
||||||
void VillageInitializer::free_controller() {
|
|
||||||
if (_controller) {
|
|
||||||
delete _controller;
|
|
||||||
_controller = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VillageInitializer::allocate_model() {
|
|
||||||
ERR_FAIL_COND(_model);
|
|
||||||
|
|
||||||
_model = new VillageModel();
|
|
||||||
}
|
|
||||||
void VillageInitializer::free_model() {
|
|
||||||
if (_model) {
|
|
||||||
delete _model;
|
|
||||||
_model = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VillageInitializer::allocate_all() {
|
|
||||||
allocate_model();
|
|
||||||
allocate_controller();
|
|
||||||
}
|
|
||||||
void VillageInitializer::free_all() {
|
|
||||||
free_controller();
|
|
||||||
free_model();
|
|
||||||
}
|
|
||||||
|
|
||||||
VillageController *VillageInitializer::_controller = nullptr;
|
|
||||||
VillageModel *VillageInitializer::_model = nullptr;
|
|
@ -1,23 +0,0 @@
|
|||||||
#ifndef VILLAGE_INITIALIZER_H
|
|
||||||
#define VILLAGE_INITIALIZER_H
|
|
||||||
|
|
||||||
#include "village_model.h"
|
|
||||||
#include "village_controller.h"
|
|
||||||
|
|
||||||
class VillageInitializer {
|
|
||||||
public:
|
|
||||||
static void allocate_controller();
|
|
||||||
static void free_controller();
|
|
||||||
|
|
||||||
static void allocate_model();
|
|
||||||
static void free_model();
|
|
||||||
|
|
||||||
static void allocate_all();
|
|
||||||
static void free_all();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static VillageController *_controller;
|
|
||||||
static VillageModel *_model;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,26 +0,0 @@
|
|||||||
#ifndef VILLAGE_MODEL_H
|
|
||||||
#define VILLAGE_MODEL_H
|
|
||||||
|
|
||||||
#include "core/string.h"
|
|
||||||
#include "core/containers/vector.h"
|
|
||||||
|
|
||||||
#include "core/object.h"
|
|
||||||
|
|
||||||
class VillageModel : public Object {
|
|
||||||
RCPP_OBJECT(VillageModel, Object);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual void create_table();
|
|
||||||
virtual void drop_table();
|
|
||||||
virtual void create_default_entries();
|
|
||||||
|
|
||||||
static VillageModel *get_singleton();
|
|
||||||
|
|
||||||
VillageModel();
|
|
||||||
~VillageModel();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static VillageModel *_self;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,4 +1,11 @@
|
|||||||
#include "village_model.h"
|
#include "village_node.h"
|
||||||
|
|
||||||
|
#include "web/html/form_validator.h"
|
||||||
|
#include "web/html/html_builder.h"
|
||||||
|
#include "web/http/cookie.h"
|
||||||
|
#include "web/http/http_session.h"
|
||||||
|
#include "web/http/request.h"
|
||||||
|
#include "web/http/session_manager.h"
|
||||||
|
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
#include "database/database_manager.h"
|
#include "database/database_manager.h"
|
||||||
@ -17,9 +24,11 @@
|
|||||||
#define VILLAGE_BUILDING_SPELLS_TABLE_NAME "village_building_spells"
|
#define VILLAGE_BUILDING_SPELLS_TABLE_NAME "village_building_spells"
|
||||||
#define VILLAGE_BUILDING_SPELL_COOLDOWNS_TABLE_NAME "village_building_spell_cooldowns"
|
#define VILLAGE_BUILDING_SPELL_COOLDOWNS_TABLE_NAME "village_building_spell_cooldowns"
|
||||||
|
|
||||||
|
void VillageNode::handle_request_default(Request *request) {
|
||||||
|
}
|
||||||
|
|
||||||
void VillageModel::create_table() {
|
void VillageNode::create_table() {
|
||||||
Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder();
|
Ref<TableBuilder> tb = get_table_builder();
|
||||||
|
|
||||||
tb->create_table(VILLAGE_TABLE_NAME);
|
tb->create_table(VILLAGE_TABLE_NAME);
|
||||||
tb->integer("id", 11)->auto_increment()->next_row();
|
tb->integer("id", 11)->auto_increment()->next_row();
|
||||||
@ -194,8 +203,8 @@ void VillageModel::create_table() {
|
|||||||
#define VILLAGE_BUILDING_SPELLS_TABLE_NAME "village_building_spells"
|
#define VILLAGE_BUILDING_SPELLS_TABLE_NAME "village_building_spells"
|
||||||
#define VILLAGE_BUILDING_SPELL_COOLDOWNS_TABLE_NAME "village_building_spell_cooldowns"
|
#define VILLAGE_BUILDING_SPELL_COOLDOWNS_TABLE_NAME "village_building_spell_cooldowns"
|
||||||
|
|
||||||
void VillageModel::drop_table() {
|
void VillageNode::drop_table() {
|
||||||
Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder();
|
Ref<TableBuilder> tb = get_table_builder();
|
||||||
|
|
||||||
tb->drop_table_if_exists(VILLAGE_BUILDING_ASSIGNMENTS_TABLE_NAME)->cdrop_table();
|
tb->drop_table_if_exists(VILLAGE_BUILDING_ASSIGNMENTS_TABLE_NAME)->cdrop_table();
|
||||||
tb->drop_table_if_exists(VILLAGE_BUILDING_SPELLS_TABLE_NAME)->cdrop_table();
|
tb->drop_table_if_exists(VILLAGE_BUILDING_SPELLS_TABLE_NAME)->cdrop_table();
|
||||||
@ -209,28 +218,29 @@ void VillageModel::drop_table() {
|
|||||||
tb->run_query();
|
tb->run_query();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VillageModel::create_default_entries() {
|
void VillageNode::create_default_entries() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VillageModel *VillageModel::get_singleton() {
|
|
||||||
|
VillageNode *VillageNode::get_singleton() {
|
||||||
return _self;
|
return _self;
|
||||||
}
|
}
|
||||||
|
|
||||||
VillageModel::VillageModel() :
|
VillageNode::VillageNode() :
|
||||||
Object() {
|
WebNode() {
|
||||||
|
|
||||||
if (_self) {
|
if (_self) {
|
||||||
printf("VillageModel::VillageModel(): Error! self is not null!/n");
|
printf("VillageNode::VillageNode(): Error! self is not null!/n");
|
||||||
}
|
}
|
||||||
|
|
||||||
_self = this;
|
_self = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
VillageModel::~VillageModel() {
|
VillageNode::~VillageNode() {
|
||||||
if (_self == this) {
|
if (_self == this) {
|
||||||
_self = nullptr;
|
_self = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VillageModel *VillageModel::_self = nullptr;
|
VillageNode *VillageNode::_self = nullptr;
|
33
app/village/village_node.h
Normal file
33
app/village/village_node.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef VILLAGE_NODE_H
|
||||||
|
#define VILLAGE_NODE_H
|
||||||
|
|
||||||
|
#include "core/containers/vector.h"
|
||||||
|
#include "core/string.h"
|
||||||
|
|
||||||
|
#include "web/http/web_node.h"
|
||||||
|
|
||||||
|
#include "village.h"
|
||||||
|
|
||||||
|
class Request;
|
||||||
|
class FormValidator;
|
||||||
|
|
||||||
|
class VillageNode : public WebNode {
|
||||||
|
RCPP_OBJECT(VillageNode, WebNode);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void handle_request_default(Request *request);
|
||||||
|
|
||||||
|
void create_table();
|
||||||
|
void drop_table();
|
||||||
|
void create_default_entries();
|
||||||
|
|
||||||
|
static VillageNode *get_singleton();
|
||||||
|
|
||||||
|
VillageNode();
|
||||||
|
~VillageNode();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static VillageNode *_self;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user