mirror of
https://github.com/Relintai/mourne_rcpp_fw.git
synced 2024-12-23 21:16:50 +01:00
Reworked building controller and building model to the new style.
This commit is contained in:
parent
517402e87e
commit
ced07f3bb7
@ -1,307 +0,0 @@
|
|||||||
#include "building_controller.h"
|
|
||||||
|
|
||||||
#include "web/html/form_validator.h"
|
|
||||||
#include "web/html/html_builder.h"
|
|
||||||
#include "web/http/cookie.h"
|
|
||||||
#include "web/http/http_enums.h"
|
|
||||||
#include "web/http/http_session.h"
|
|
||||||
#include "web/http/request.h"
|
|
||||||
#include "web/http/session_manager.h"
|
|
||||||
|
|
||||||
#include "building_model.h"
|
|
||||||
|
|
||||||
#include "../html_macros.h"
|
|
||||||
|
|
||||||
void BuildingController::handle_request_default(Request *request) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingController::admin_handle_request_main(Request *request) {
|
|
||||||
String seg = request->get_current_path_segment();
|
|
||||||
|
|
||||||
if (seg == "") {
|
|
||||||
admin_render_building_list(request);
|
|
||||||
return;
|
|
||||||
} else if (seg == "new") {
|
|
||||||
request->push_path();
|
|
||||||
Ref<Building> b;
|
|
||||||
b.instance();
|
|
||||||
|
|
||||||
admin_render_building(request, b);
|
|
||||||
return;
|
|
||||||
} else if (seg == "edit") {
|
|
||||||
request->push_path();
|
|
||||||
|
|
||||||
String seg_building_id = request->get_current_path_segment();
|
|
||||||
|
|
||||||
if (!seg_building_id.is_int()) {
|
|
||||||
request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bid = seg_building_id.to_int();
|
|
||||||
|
|
||||||
Ref<Building> b = BuildingModel::get_singleton()->get_building(bid);
|
|
||||||
|
|
||||||
if (!b.is_valid()) {
|
|
||||||
request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
admin_render_building(request, b);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
request->send_error(404);
|
|
||||||
}
|
|
||||||
String BuildingController::admin_get_section_name() {
|
|
||||||
return "Buildings";
|
|
||||||
}
|
|
||||||
void BuildingController::admin_add_section_links(Vector<AdminSectionLinkInfo> *links) {
|
|
||||||
links->push_back(AdminSectionLinkInfo("- Building Editor", ""));
|
|
||||||
}
|
|
||||||
bool BuildingController::admin_full_render() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingController::admin_render_building_list(Request *request) {
|
|
||||||
Vector<Ref<Building> > buildings = BuildingModel::get_singleton()->get_all();
|
|
||||||
|
|
||||||
HTMLBuilder b;
|
|
||||||
|
|
||||||
b.div("back")->fa(request->get_url_root_parent(), "<--- Back")->cdiv();
|
|
||||||
b.br();
|
|
||||||
b.fdiv("Building Editor", "top_menu");
|
|
||||||
b.br();
|
|
||||||
b.div("top_menu")->fa(request->get_url_root("new"), "Create New")->cdiv();
|
|
||||||
b.br();
|
|
||||||
|
|
||||||
b.div("list_container");
|
|
||||||
|
|
||||||
for (int i = 0; i < buildings.size(); ++i) {
|
|
||||||
Ref<Building> building = buildings[i];
|
|
||||||
|
|
||||||
if (!building.is_valid()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i % 2 == 0) {
|
|
||||||
b.div("row");
|
|
||||||
} else {
|
|
||||||
b.div("row second");
|
|
||||||
}
|
|
||||||
{
|
|
||||||
b.fdiv(String::num(building->id), "attr_box");
|
|
||||||
b.fdiv(String::num(building->rank), "attr_box");
|
|
||||||
b.fdiv(String::num(building->next_rank), "attr_box");
|
|
||||||
b.fdiv(building->name, "name");
|
|
||||||
|
|
||||||
b.div("actionbox")->fa(request->get_url_root("edit/" + String::num(building->id)), "Edit")->cdiv();
|
|
||||||
}
|
|
||||||
b.cdiv();
|
|
||||||
}
|
|
||||||
|
|
||||||
b.cdiv();
|
|
||||||
|
|
||||||
request->body += b.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingController::admin_render_building(Request *request, Ref<Building> building) {
|
|
||||||
if (!building.is_valid()) {
|
|
||||||
RLOG_ERR("admin_render_building: !building.is_valid()\n");
|
|
||||||
request->send_error(HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector<Ref<Building> > buildings = BuildingModel::get_singleton()->get_all();
|
|
||||||
|
|
||||||
HTMLBuilder b;
|
|
||||||
|
|
||||||
b.div("back")->fa(request->get_url_root_parent(), "<--- Back")->cdiv();
|
|
||||||
b.br();
|
|
||||||
b.fdiv("Building Editor", "top_menu");
|
|
||||||
b.br();
|
|
||||||
|
|
||||||
b.form_post(request->get_url_root());
|
|
||||||
|
|
||||||
bool show_post = false; //request->get_method() == HTTP_METHOD_POST && validation errors;
|
|
||||||
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Name:", "name", show_post, building->name, request->get_parameter("name"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXTAREA("Description:", "description", show_post, building->description, request->get_parameter("description"));
|
|
||||||
|
|
||||||
b.div("row_edit");
|
|
||||||
b.fdiv("Icon:", "edit_name");
|
|
||||||
//todo I'm not sure yet how this worked originally
|
|
||||||
//b.div("edit_input")->f()->input_image("icon", building->icon)->f()->cdiv();
|
|
||||||
b.div("edit_input")->w("TODO")->cdiv();
|
|
||||||
b.cdiv();
|
|
||||||
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Rank:", "rank", show_post, String::num(building->rank), request->get_parameter("rank"));
|
|
||||||
|
|
||||||
Vector<Ref<Building> > nrbs = BuildingModel::get_singleton()->get_all();
|
|
||||||
b.div("row_edit");
|
|
||||||
b.fdiv("Next Rank:", "edit_name");
|
|
||||||
b.div("edit_input");
|
|
||||||
{
|
|
||||||
b.select("next_rank", "drop");
|
|
||||||
{
|
|
||||||
int current_id = building->id;
|
|
||||||
int current_nr = building->next_rank;
|
|
||||||
|
|
||||||
b.foption(String::num(0), "- None -", current_nr == 0);
|
|
||||||
|
|
||||||
for (int i = 0; i < nrbs.size(); ++i) {
|
|
||||||
Ref<Building> build = nrbs[i];
|
|
||||||
|
|
||||||
int id = build->id;
|
|
||||||
|
|
||||||
if (id == current_id) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
b.foption(String::num(id), build->name + " R" + String::num(build->rank), current_nr == id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b.cselect();
|
|
||||||
}
|
|
||||||
b.cdiv();
|
|
||||||
b.cdiv();
|
|
||||||
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Time to Build:", "time_to_build", show_post, String::num(building->time_to_build), request->get_parameter("time_to_build"));
|
|
||||||
|
|
||||||
ADMIN_EDIT_LINE_SPACER();
|
|
||||||
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Score:", "score", show_post, String::num(building->score), request->get_parameter("score"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Defense:", "defense", show_post, String::num(building->defense), request->get_parameter("defense"));
|
|
||||||
|
|
||||||
//TODO
|
|
||||||
/*
|
|
||||||
int ability;
|
|
||||||
|
|
||||||
<div class="row_edit">
|
|
||||||
<div class="edit_name">
|
|
||||||
Ability:
|
|
||||||
</div>
|
|
||||||
<div class="edit_input">
|
|
||||||
<?=form_dropdown('ability', $opt_ability, $sability, $attr_drop); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
*/
|
|
||||||
|
|
||||||
b.div("row_edit");
|
|
||||||
b.fdiv("Ability:", "edit_name");
|
|
||||||
b.div("edit_input")->w("TODO")->cdiv();
|
|
||||||
b.cdiv();
|
|
||||||
|
|
||||||
ADMIN_EDIT_LINE_SPACER();
|
|
||||||
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Cost Food:", "cost_food", show_post, String::num(building->cost_food), request->get_parameter("cost_food"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Cost Wood:", "cost_wood", show_post, String::num(building->cost_wood), request->get_parameter("cost_wood"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Cost Stone:", "cost_stone", show_post, String::num(building->cost_stone), request->get_parameter("cost_stone"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Cost Iron:", "cost_iron", show_post, String::num(building->cost_iron), request->get_parameter("cost_iron"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Cost Mana:", "cost_mana", show_post, String::num(building->cost_food), request->get_parameter("cost_mana"));
|
|
||||||
|
|
||||||
ADMIN_EDIT_LINE_SPACER();
|
|
||||||
|
|
||||||
/*
|
|
||||||
int creates;
|
|
||||||
int num_creates;
|
|
||||||
|
|
||||||
<div class="row_edit">
|
|
||||||
<div class="edit_name">
|
|
||||||
Creates:
|
|
||||||
</div>
|
|
||||||
<div class="edit_input">
|
|
||||||
<?=form_dropdown($name_creates, $optcre, $screate, $attr_creates); ?>
|
|
||||||
X (max) <?=form_input($attr_num_creates); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
*/
|
|
||||||
|
|
||||||
b.div("row_edit");
|
|
||||||
b.fdiv("Creates:", "edit_name");
|
|
||||||
b.div("edit_input")->w("TODO")->cdiv();
|
|
||||||
b.cdiv();
|
|
||||||
|
|
||||||
ADMIN_EDIT_LINE_SPACER();
|
|
||||||
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Max Food:", "mod_max_food", show_post, String::num(building->mod_max_food), request->get_parameter("mod_max_food"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Max Wood:", "mod_max_wood", show_post, String::num(building->mod_max_wood), request->get_parameter("mod_max_wood"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Max Stone:", "mod_max_stone", show_post, String::num(building->mod_max_stone), request->get_parameter("mod_max_stone"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Max Iron:", "mod_max_iron", show_post, String::num(building->mod_max_iron), request->get_parameter("mod_max_iron"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Max Mana:", "mod_max_mana", show_post, String::num(building->mod_max_mana), request->get_parameter("mod_max_mana"));
|
|
||||||
|
|
||||||
ADMIN_EDIT_LINE_SPACER();
|
|
||||||
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Rate Food:", "mod_rate_food", show_post, String::num(building->mod_rate_food), request->get_parameter("mod_rate_food"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Rate Wood:", "mod_rate_wood", show_post, String::num(building->mod_rate_wood), request->get_parameter("mod_rate_wood"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Rate Stone:", "mod_rate_stone", show_post, String::num(building->mod_rate_stone), request->get_parameter("mod_rate_stone"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Rate Iron:", "mod_rate_iron", show_post, String::num(building->mod_rate_iron), request->get_parameter("mod_rate_iron"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Rate Mana:", "mod_rate_mana", show_post, String::num(building->mod_rate_mana), request->get_parameter("mod_rate_mana"));
|
|
||||||
|
|
||||||
ADMIN_EDIT_LINE_SPACER();
|
|
||||||
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Percent Food:", "mod_percent_food", show_post, String::num(building->mod_percent_food), request->get_parameter("mod_percent_food"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Percent Wood:", "mod_percent_wood", show_post, String::num(building->mod_percent_wood), request->get_parameter("mod_percent_wood"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Percent Stone:", "mod_percent_stone", show_post, String::num(building->mod_percent_stone), request->get_parameter("mod_percent_stone"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Percent Iron:", "mod_percent_iron", show_post, String::num(building->mod_percent_iron), request->get_parameter("mod_percent_iron"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Mod Percent Mana:", "mod_percent_mana", show_post, String::num(building->mod_percent_mana), request->get_parameter("mod_percent_mana"));
|
|
||||||
|
|
||||||
ADMIN_EDIT_LINE_SPACER();
|
|
||||||
|
|
||||||
//TODO <?=form_dropdown($name_assign1, $optass, $assign1, $attr_assign); ?>
|
|
||||||
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Assignment 1:", "assignment1", show_post, String::num(building->assignment1), request->get_parameter("assignment1"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Assignment 2:", "assignment2", show_post, String::num(building->assignment2), request->get_parameter("assignment2"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Assignment 3:", "assignment3", show_post, String::num(building->assignment3), request->get_parameter("assignment3"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Assignment 4:", "assignment4", show_post, String::num(building->assignment4), request->get_parameter("assignment4"));
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Assignment 5:", "assignment5", show_post, String::num(building->assignment5), request->get_parameter("assignment5"));
|
|
||||||
|
|
||||||
ADMIN_EDIT_LINE_SPACER();
|
|
||||||
|
|
||||||
//TODO <?=form_dropdown($name_req_tech, $optreqtech, $selreqtech, $attr_req_tech); ?>
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Required Technology:", "req_tech", show_post, String::num(building->req_tech), request->get_parameter("req_tech"));
|
|
||||||
ADMIN_EDIT_LINE_SPACER();
|
|
||||||
//TODO <?=form_dropdown($name_tech_group, $opttechgroup, $seltechgroup, $attr_assign);?>
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Technology Group:", "tech_group", show_post, String::num(building->tech_group), request->get_parameter("tech_group"));
|
|
||||||
ADMIN_EDIT_LINE_SPACER();
|
|
||||||
//TODO <?=form_dropdown($name_tech_secondary_group, $opttechgroup, $seltechsecgroup, $attr_tech_secondary_group); ?>
|
|
||||||
ADMIN_EDIT_INPUT_TEXT("Secondary Technology Group:", "tech_secondary_group", show_post, String::num(building->tech_secondary_group), request->get_parameter("tech_secondary_group"));
|
|
||||||
|
|
||||||
b.div("edit_submit")->input_submit("Save", "submit")->cdiv();
|
|
||||||
|
|
||||||
b.cform();
|
|
||||||
|
|
||||||
request->body += b.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingController::create_table() {
|
|
||||||
BuildingModel::get_singleton()->create_table();
|
|
||||||
}
|
|
||||||
void BuildingController::drop_table() {
|
|
||||||
BuildingModel::get_singleton()->drop_table();
|
|
||||||
}
|
|
||||||
void BuildingController::create_default_entries() {
|
|
||||||
BuildingModel::get_singleton()->create_default_entries();
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildingController *BuildingController::get_singleton() {
|
|
||||||
return _self;
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildingController::BuildingController() :
|
|
||||||
AdminNode() {
|
|
||||||
|
|
||||||
if (_self) {
|
|
||||||
printf("BuildingController::BuildingController(): Error! self is not null!/n");
|
|
||||||
}
|
|
||||||
|
|
||||||
_self = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildingController::~BuildingController() {
|
|
||||||
if (_self == this) {
|
|
||||||
_self = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildingController *BuildingController::_self = nullptr;
|
|
@ -1,37 +0,0 @@
|
|||||||
#include "building_initializer.h"
|
|
||||||
|
|
||||||
void BuildingInitializer::allocate_controller() {
|
|
||||||
ERR_FAIL_COND(_controller);
|
|
||||||
|
|
||||||
_controller = new BuildingController();
|
|
||||||
}
|
|
||||||
void BuildingInitializer::free_controller() {
|
|
||||||
if (_controller) {
|
|
||||||
delete _controller;
|
|
||||||
_controller = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingInitializer::allocate_model() {
|
|
||||||
ERR_FAIL_COND(_model);
|
|
||||||
|
|
||||||
_model = new BuildingModel();
|
|
||||||
}
|
|
||||||
void BuildingInitializer::free_model() {
|
|
||||||
if (_model) {
|
|
||||||
delete _model;
|
|
||||||
_model = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingInitializer::allocate_all() {
|
|
||||||
allocate_model();
|
|
||||||
allocate_controller();
|
|
||||||
}
|
|
||||||
void BuildingInitializer::free_all() {
|
|
||||||
free_controller();
|
|
||||||
free_model();
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildingController *BuildingInitializer::_controller = nullptr;
|
|
||||||
BuildingModel *BuildingInitializer::_model = nullptr;
|
|
@ -1,23 +0,0 @@
|
|||||||
#ifndef BUILDING_INITIALIZER_H
|
|
||||||
#define BUILDING_INITIALIZER_H
|
|
||||||
|
|
||||||
#include "building_model.h"
|
|
||||||
#include "building_controller.h"
|
|
||||||
|
|
||||||
class BuildingInitializer {
|
|
||||||
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 BuildingController *_controller;
|
|
||||||
static BuildingModel *_model;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,36 +0,0 @@
|
|||||||
#ifndef BUILDING_MODEL_H
|
|
||||||
#define BUILDING_MODEL_H
|
|
||||||
|
|
||||||
#include "core/string.h"
|
|
||||||
#include "core/containers/vector.h"
|
|
||||||
|
|
||||||
#include "core/object.h"
|
|
||||||
#include "core/reference.h"
|
|
||||||
|
|
||||||
class Building;
|
|
||||||
class QueryResult;
|
|
||||||
|
|
||||||
class BuildingModel : public Object {
|
|
||||||
RCPP_OBJECT(BuildingModel, Object);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual Ref<Building> get_building(const int id);
|
|
||||||
virtual Vector<Ref<Building> > get_all();
|
|
||||||
virtual void save_building(Ref<Building> &building);
|
|
||||||
|
|
||||||
virtual void parse_row(Ref<QueryResult> &result, Ref<Building> &building);
|
|
||||||
|
|
||||||
void create_table();
|
|
||||||
void drop_table();
|
|
||||||
void create_default_entries();
|
|
||||||
|
|
||||||
static BuildingModel *get_singleton();
|
|
||||||
|
|
||||||
BuildingModel();
|
|
||||||
~BuildingModel();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static BuildingModel *_self;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,4 +1,12 @@
|
|||||||
#include "building_model.h"
|
#include "building_node.h"
|
||||||
|
|
||||||
|
#include "web/html/form_validator.h"
|
||||||
|
#include "web/html/html_builder.h"
|
||||||
|
#include "web/http/cookie.h"
|
||||||
|
#include "web/http/http_enums.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"
|
||||||
@ -8,19 +16,283 @@
|
|||||||
|
|
||||||
#include "crypto/hash/sha256.h"
|
#include "crypto/hash/sha256.h"
|
||||||
|
|
||||||
#include "building.h"
|
#include "../html_macros.h"
|
||||||
|
|
||||||
|
|
||||||
#define BUILDING_TABLE_NAME "buildings"
|
#define BUILDING_TABLE_NAME "buildings"
|
||||||
|
|
||||||
#define BUILDING_TABLE_COLUMNS "id, name, description, icon, rank, next_rank, time_to_build, creates, num_creates, score, defense, ability, cost_food, cost_wood, cost_stone, cost_iron, cost_mana, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, assignment1, assignment2, assignment3, assignment4, assignment5, req_tech, tech_group, tech_secondary_group"
|
#define BUILDING_TABLE_COLUMNS "id, name, description, icon, rank, next_rank, time_to_build, creates, num_creates, score, defense, ability, cost_food, cost_wood, cost_stone, cost_iron, cost_mana, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, assignment1, assignment2, assignment3, assignment4, assignment5, req_tech, tech_group, tech_secondary_group"
|
||||||
#define BUILDING_TABLE_COLUMNS_NOID "name, description, icon, rank, next_rank, time_to_build, creates, num_creates, score, defense, ability, cost_food, cost_wood, cost_stone, cost_iron, cost_mana, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, assignment1, assignment2, assignment3, assignment4, assignment5, req_tech, tech_group, tech_secondary_group"
|
#define BUILDING_TABLE_COLUMNS_NOID "name, description, icon, rank, next_rank, time_to_build, creates, num_creates, score, defense, ability, cost_food, cost_wood, cost_stone, cost_iron, cost_mana, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, assignment1, assignment2, assignment3, assignment4, assignment5, req_tech, tech_group, tech_secondary_group"
|
||||||
|
|
||||||
Ref<Building> BuildingModel::get_building(const int id) {
|
|
||||||
|
void BuildingNode::handle_request_default(Request *request) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildingNode::admin_handle_request_main(Request *request) {
|
||||||
|
String seg = request->get_current_path_segment();
|
||||||
|
|
||||||
|
if (seg == "") {
|
||||||
|
admin_render_building_list(request);
|
||||||
|
return;
|
||||||
|
} else if (seg == "new") {
|
||||||
|
request->push_path();
|
||||||
|
Ref<Building> b;
|
||||||
|
b.instance();
|
||||||
|
|
||||||
|
admin_render_building(request, b);
|
||||||
|
return;
|
||||||
|
} else if (seg == "edit") {
|
||||||
|
request->push_path();
|
||||||
|
|
||||||
|
String seg_building_id = request->get_current_path_segment();
|
||||||
|
|
||||||
|
if (!seg_building_id.is_int()) {
|
||||||
|
request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bid = seg_building_id.to_int();
|
||||||
|
|
||||||
|
Ref<Building> b = db_get_building(bid);
|
||||||
|
|
||||||
|
if (!b.is_valid()) {
|
||||||
|
request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
admin_render_building(request, b);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
request->send_error(404);
|
||||||
|
}
|
||||||
|
String BuildingNode::admin_get_section_name() {
|
||||||
|
return "Buildings";
|
||||||
|
}
|
||||||
|
void BuildingNode::admin_add_section_links(Vector<AdminSectionLinkInfo> *links) {
|
||||||
|
links->push_back(AdminSectionLinkInfo("- Building Editor", ""));
|
||||||
|
}
|
||||||
|
bool BuildingNode::admin_full_render() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildingNode::admin_render_building_list(Request *request) {
|
||||||
|
Vector<Ref<Building> > buildings = db_get_all();
|
||||||
|
|
||||||
|
HTMLBuilder b;
|
||||||
|
|
||||||
|
b.div("back")->fa(request->get_url_root_parent(), "<--- Back")->cdiv();
|
||||||
|
b.br();
|
||||||
|
b.fdiv("Building Editor", "top_menu");
|
||||||
|
b.br();
|
||||||
|
b.div("top_menu")->fa(request->get_url_root("new"), "Create New")->cdiv();
|
||||||
|
b.br();
|
||||||
|
|
||||||
|
b.div("list_container");
|
||||||
|
|
||||||
|
for (int i = 0; i < buildings.size(); ++i) {
|
||||||
|
Ref<Building> building = buildings[i];
|
||||||
|
|
||||||
|
if (!building.is_valid()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i % 2 == 0) {
|
||||||
|
b.div("row");
|
||||||
|
} else {
|
||||||
|
b.div("row second");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
b.fdiv(String::num(building->id), "attr_box");
|
||||||
|
b.fdiv(String::num(building->rank), "attr_box");
|
||||||
|
b.fdiv(String::num(building->next_rank), "attr_box");
|
||||||
|
b.fdiv(building->name, "name");
|
||||||
|
|
||||||
|
b.div("actionbox")->fa(request->get_url_root("edit/" + String::num(building->id)), "Edit")->cdiv();
|
||||||
|
}
|
||||||
|
b.cdiv();
|
||||||
|
}
|
||||||
|
|
||||||
|
b.cdiv();
|
||||||
|
|
||||||
|
request->body += b.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildingNode::admin_render_building(Request *request, Ref<Building> building) {
|
||||||
|
if (!building.is_valid()) {
|
||||||
|
RLOG_ERR("admin_render_building: !building.is_valid()\n");
|
||||||
|
request->send_error(HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<Ref<Building> > buildings = db_get_all();
|
||||||
|
|
||||||
|
HTMLBuilder b;
|
||||||
|
|
||||||
|
b.div("back")->fa(request->get_url_root_parent(), "<--- Back")->cdiv();
|
||||||
|
b.br();
|
||||||
|
b.fdiv("Building Editor", "top_menu");
|
||||||
|
b.br();
|
||||||
|
|
||||||
|
b.form_post(request->get_url_root());
|
||||||
|
|
||||||
|
bool show_post = false; //request->get_method() == HTTP_METHOD_POST && validation errors;
|
||||||
|
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Name:", "name", show_post, building->name, request->get_parameter("name"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXTAREA("Description:", "description", show_post, building->description, request->get_parameter("description"));
|
||||||
|
|
||||||
|
b.div("row_edit");
|
||||||
|
b.fdiv("Icon:", "edit_name");
|
||||||
|
//todo I'm not sure yet how this worked originally
|
||||||
|
//b.div("edit_input")->f()->input_image("icon", building->icon)->f()->cdiv();
|
||||||
|
b.div("edit_input")->w("TODO")->cdiv();
|
||||||
|
b.cdiv();
|
||||||
|
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Rank:", "rank", show_post, String::num(building->rank), request->get_parameter("rank"));
|
||||||
|
|
||||||
|
Vector<Ref<Building> > nrbs = db_get_all();
|
||||||
|
b.div("row_edit");
|
||||||
|
b.fdiv("Next Rank:", "edit_name");
|
||||||
|
b.div("edit_input");
|
||||||
|
{
|
||||||
|
b.select("next_rank", "drop");
|
||||||
|
{
|
||||||
|
int current_id = building->id;
|
||||||
|
int current_nr = building->next_rank;
|
||||||
|
|
||||||
|
b.foption(String::num(0), "- None -", current_nr == 0);
|
||||||
|
|
||||||
|
for (int i = 0; i < nrbs.size(); ++i) {
|
||||||
|
Ref<Building> build = nrbs[i];
|
||||||
|
|
||||||
|
int id = build->id;
|
||||||
|
|
||||||
|
if (id == current_id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
b.foption(String::num(id), build->name + " R" + String::num(build->rank), current_nr == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.cselect();
|
||||||
|
}
|
||||||
|
b.cdiv();
|
||||||
|
b.cdiv();
|
||||||
|
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Time to Build:", "time_to_build", show_post, String::num(building->time_to_build), request->get_parameter("time_to_build"));
|
||||||
|
|
||||||
|
ADMIN_EDIT_LINE_SPACER();
|
||||||
|
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Score:", "score", show_post, String::num(building->score), request->get_parameter("score"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Defense:", "defense", show_post, String::num(building->defense), request->get_parameter("defense"));
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
/*
|
||||||
|
int ability;
|
||||||
|
|
||||||
|
<div class="row_edit">
|
||||||
|
<div class="edit_name">
|
||||||
|
Ability:
|
||||||
|
</div>
|
||||||
|
<div class="edit_input">
|
||||||
|
<?=form_dropdown('ability', $opt_ability, $sability, $attr_drop); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
*/
|
||||||
|
|
||||||
|
b.div("row_edit");
|
||||||
|
b.fdiv("Ability:", "edit_name");
|
||||||
|
b.div("edit_input")->w("TODO")->cdiv();
|
||||||
|
b.cdiv();
|
||||||
|
|
||||||
|
ADMIN_EDIT_LINE_SPACER();
|
||||||
|
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Cost Food:", "cost_food", show_post, String::num(building->cost_food), request->get_parameter("cost_food"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Cost Wood:", "cost_wood", show_post, String::num(building->cost_wood), request->get_parameter("cost_wood"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Cost Stone:", "cost_stone", show_post, String::num(building->cost_stone), request->get_parameter("cost_stone"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Cost Iron:", "cost_iron", show_post, String::num(building->cost_iron), request->get_parameter("cost_iron"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Cost Mana:", "cost_mana", show_post, String::num(building->cost_food), request->get_parameter("cost_mana"));
|
||||||
|
|
||||||
|
ADMIN_EDIT_LINE_SPACER();
|
||||||
|
|
||||||
|
/*
|
||||||
|
int creates;
|
||||||
|
int num_creates;
|
||||||
|
|
||||||
|
<div class="row_edit">
|
||||||
|
<div class="edit_name">
|
||||||
|
Creates:
|
||||||
|
</div>
|
||||||
|
<div class="edit_input">
|
||||||
|
<?=form_dropdown($name_creates, $optcre, $screate, $attr_creates); ?>
|
||||||
|
X (max) <?=form_input($attr_num_creates); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
*/
|
||||||
|
|
||||||
|
b.div("row_edit");
|
||||||
|
b.fdiv("Creates:", "edit_name");
|
||||||
|
b.div("edit_input")->w("TODO")->cdiv();
|
||||||
|
b.cdiv();
|
||||||
|
|
||||||
|
ADMIN_EDIT_LINE_SPACER();
|
||||||
|
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Max Food:", "mod_max_food", show_post, String::num(building->mod_max_food), request->get_parameter("mod_max_food"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Max Wood:", "mod_max_wood", show_post, String::num(building->mod_max_wood), request->get_parameter("mod_max_wood"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Max Stone:", "mod_max_stone", show_post, String::num(building->mod_max_stone), request->get_parameter("mod_max_stone"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Max Iron:", "mod_max_iron", show_post, String::num(building->mod_max_iron), request->get_parameter("mod_max_iron"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Max Mana:", "mod_max_mana", show_post, String::num(building->mod_max_mana), request->get_parameter("mod_max_mana"));
|
||||||
|
|
||||||
|
ADMIN_EDIT_LINE_SPACER();
|
||||||
|
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Rate Food:", "mod_rate_food", show_post, String::num(building->mod_rate_food), request->get_parameter("mod_rate_food"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Rate Wood:", "mod_rate_wood", show_post, String::num(building->mod_rate_wood), request->get_parameter("mod_rate_wood"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Rate Stone:", "mod_rate_stone", show_post, String::num(building->mod_rate_stone), request->get_parameter("mod_rate_stone"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Rate Iron:", "mod_rate_iron", show_post, String::num(building->mod_rate_iron), request->get_parameter("mod_rate_iron"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Rate Mana:", "mod_rate_mana", show_post, String::num(building->mod_rate_mana), request->get_parameter("mod_rate_mana"));
|
||||||
|
|
||||||
|
ADMIN_EDIT_LINE_SPACER();
|
||||||
|
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Percent Food:", "mod_percent_food", show_post, String::num(building->mod_percent_food), request->get_parameter("mod_percent_food"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Percent Wood:", "mod_percent_wood", show_post, String::num(building->mod_percent_wood), request->get_parameter("mod_percent_wood"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Percent Stone:", "mod_percent_stone", show_post, String::num(building->mod_percent_stone), request->get_parameter("mod_percent_stone"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Percent Iron:", "mod_percent_iron", show_post, String::num(building->mod_percent_iron), request->get_parameter("mod_percent_iron"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Mod Percent Mana:", "mod_percent_mana", show_post, String::num(building->mod_percent_mana), request->get_parameter("mod_percent_mana"));
|
||||||
|
|
||||||
|
ADMIN_EDIT_LINE_SPACER();
|
||||||
|
|
||||||
|
//TODO <?=form_dropdown($name_assign1, $optass, $assign1, $attr_assign); ?>
|
||||||
|
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Assignment 1:", "assignment1", show_post, String::num(building->assignment1), request->get_parameter("assignment1"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Assignment 2:", "assignment2", show_post, String::num(building->assignment2), request->get_parameter("assignment2"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Assignment 3:", "assignment3", show_post, String::num(building->assignment3), request->get_parameter("assignment3"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Assignment 4:", "assignment4", show_post, String::num(building->assignment4), request->get_parameter("assignment4"));
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Assignment 5:", "assignment5", show_post, String::num(building->assignment5), request->get_parameter("assignment5"));
|
||||||
|
|
||||||
|
ADMIN_EDIT_LINE_SPACER();
|
||||||
|
|
||||||
|
//TODO <?=form_dropdown($name_req_tech, $optreqtech, $selreqtech, $attr_req_tech); ?>
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Required Technology:", "req_tech", show_post, String::num(building->req_tech), request->get_parameter("req_tech"));
|
||||||
|
ADMIN_EDIT_LINE_SPACER();
|
||||||
|
//TODO <?=form_dropdown($name_tech_group, $opttechgroup, $seltechgroup, $attr_assign);?>
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Technology Group:", "tech_group", show_post, String::num(building->tech_group), request->get_parameter("tech_group"));
|
||||||
|
ADMIN_EDIT_LINE_SPACER();
|
||||||
|
//TODO <?=form_dropdown($name_tech_secondary_group, $opttechgroup, $seltechsecgroup, $attr_tech_secondary_group); ?>
|
||||||
|
ADMIN_EDIT_INPUT_TEXT("Secondary Technology Group:", "tech_secondary_group", show_post, String::num(building->tech_secondary_group), request->get_parameter("tech_secondary_group"));
|
||||||
|
|
||||||
|
b.div("edit_submit")->input_submit("Save", "submit")->cdiv();
|
||||||
|
|
||||||
|
b.cform();
|
||||||
|
|
||||||
|
request->body += b.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Building> BuildingNode::db_get_building(const int id) {
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
return Ref<Building>();
|
return Ref<Building>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<QueryBuilder> b = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
Ref<QueryBuilder> b = get_query_builder();
|
||||||
|
|
||||||
b->select(BUILDING_TABLE_COLUMNS);
|
b->select(BUILDING_TABLE_COLUMNS);
|
||||||
b->from(BUILDING_TABLE_NAME);
|
b->from(BUILDING_TABLE_NAME);
|
||||||
@ -38,13 +310,13 @@ Ref<Building> BuildingModel::get_building(const int id) {
|
|||||||
Ref<Building> building;
|
Ref<Building> building;
|
||||||
building.instance();
|
building.instance();
|
||||||
|
|
||||||
parse_row(r, building);
|
db_parse_row(r, building);
|
||||||
|
|
||||||
return building;
|
return building;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Ref<Building> > BuildingModel::get_all() {
|
Vector<Ref<Building> > BuildingNode::db_get_all() {
|
||||||
Ref<QueryBuilder> b = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
Ref<QueryBuilder> b = get_query_builder();
|
||||||
|
|
||||||
b->select(BUILDING_TABLE_COLUMNS);
|
b->select(BUILDING_TABLE_COLUMNS);
|
||||||
b->from(BUILDING_TABLE_NAME);
|
b->from(BUILDING_TABLE_NAME);
|
||||||
@ -59,7 +331,7 @@ Vector<Ref<Building> > BuildingModel::get_all() {
|
|||||||
Ref<Building> building;
|
Ref<Building> building;
|
||||||
building.instance();
|
building.instance();
|
||||||
|
|
||||||
parse_row(r, building);
|
db_parse_row(r, building);
|
||||||
|
|
||||||
buildings.push_back(building);
|
buildings.push_back(building);
|
||||||
}
|
}
|
||||||
@ -67,8 +339,8 @@ Vector<Ref<Building> > BuildingModel::get_all() {
|
|||||||
return buildings;
|
return buildings;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildingModel::save_building(Ref<Building> &building) {
|
void BuildingNode::db_save_building(Ref<Building> &building) {
|
||||||
Ref<QueryBuilder> b = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
Ref<QueryBuilder> b = get_query_builder();
|
||||||
|
|
||||||
if (building->id == 0) {
|
if (building->id == 0) {
|
||||||
b->insert(BUILDING_TABLE_NAME, BUILDING_TABLE_COLUMNS_NOID);
|
b->insert(BUILDING_TABLE_NAME, BUILDING_TABLE_COLUMNS_NOID);
|
||||||
@ -191,7 +463,7 @@ void BuildingModel::save_building(Ref<Building> &building) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildingModel::parse_row(Ref<QueryResult> &result, Ref<Building> &building) {
|
void BuildingNode::db_parse_row(Ref<QueryResult> &result, Ref<Building> &building) {
|
||||||
|
|
||||||
building->id = result->get_cell_int(0);
|
building->id = result->get_cell_int(0);
|
||||||
|
|
||||||
@ -243,8 +515,8 @@ void BuildingModel::parse_row(Ref<QueryResult> &result, Ref<Building> &building)
|
|||||||
building->tech_secondary_group = result->get_cell_int(39);
|
building->tech_secondary_group = result->get_cell_int(39);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildingModel::create_table() {
|
void BuildingNode::create_table() {
|
||||||
Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder();
|
Ref<TableBuilder> tb = get_table_builder();
|
||||||
|
|
||||||
tb->create_table(BUILDING_TABLE_NAME);
|
tb->create_table(BUILDING_TABLE_NAME);
|
||||||
tb->integer("id", 11)->auto_increment()->next_row();
|
tb->integer("id", 11)->auto_increment()->next_row();
|
||||||
@ -300,18 +572,18 @@ void BuildingModel::create_table() {
|
|||||||
tb->run_query();
|
tb->run_query();
|
||||||
//tb->print();
|
//tb->print();
|
||||||
}
|
}
|
||||||
void BuildingModel::drop_table() {
|
void BuildingNode::drop_table() {
|
||||||
Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder();
|
Ref<TableBuilder> tb = get_table_builder();
|
||||||
|
|
||||||
tb->drop_table_if_exists(BUILDING_TABLE_NAME)->cdrop_table();
|
tb->drop_table_if_exists(BUILDING_TABLE_NAME)->cdrop_table();
|
||||||
|
|
||||||
tb->run_query();
|
tb->run_query();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildingModel::create_default_entries() {
|
void BuildingNode::create_default_entries() {
|
||||||
String table_columns = "id, name, description, icon, rank, next_rank, time_to_build, creates, num_creates, score, defense, ability, cost_food, cost_wood, cost_stone, cost_iron, cost_mana, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, assignment1, assignment2, assignment3, assignment4, assignment5, req_tech, tech_group, tech_secondary_group";
|
String table_columns = "id, name, description, icon, rank, next_rank, time_to_build, creates, num_creates, score, defense, ability, cost_food, cost_wood, cost_stone, cost_iron, cost_mana, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, assignment1, assignment2, assignment3, assignment4, assignment5, req_tech, tech_group, tech_secondary_group";
|
||||||
|
|
||||||
Ref<QueryBuilder> qb = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
Ref<QueryBuilder> qb = get_query_builder();
|
||||||
|
|
||||||
qb->begin_transaction()->nl();
|
qb->begin_transaction()->nl();
|
||||||
qb->insert(BUILDING_TABLE_NAME, table_columns)->nl()->w("VALUES(1, 'empty', '', 'empty/empty.png', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)")->end_command()->nl();
|
qb->insert(BUILDING_TABLE_NAME, table_columns)->nl()->w("VALUES(1, 'empty', '', 'empty/empty.png', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)")->end_command()->nl();
|
||||||
@ -330,24 +602,24 @@ void BuildingModel::create_default_entries() {
|
|||||||
//qb->print();
|
//qb->print();
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildingModel *BuildingModel::get_singleton() {
|
BuildingNode *BuildingNode::get_singleton() {
|
||||||
return _self;
|
return _self;
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildingModel::BuildingModel() :
|
BuildingNode::BuildingNode() :
|
||||||
Object() {
|
AdminNode() {
|
||||||
|
|
||||||
if (_self) {
|
if (_self) {
|
||||||
printf("BuildingModel::BuildingModel(): Error! self is not null!/n");
|
printf("BuildingNode::BuildingNode(): Error! self is not null!/n");
|
||||||
}
|
}
|
||||||
|
|
||||||
_self = this;
|
_self = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildingModel::~BuildingModel() {
|
BuildingNode::~BuildingNode() {
|
||||||
if (_self == this) {
|
if (_self == this) {
|
||||||
_self = nullptr;
|
_self = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildingModel *BuildingModel::_self = nullptr;
|
BuildingNode *BuildingNode::_self = nullptr;
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef BUILDING_CONTROLLER_H
|
#ifndef BUILDING_NODE_H
|
||||||
#define BUILDING_CONTROLLER_H
|
#define BUILDING_NODE_H
|
||||||
|
|
||||||
#include "core/string.h"
|
#include "core/string.h"
|
||||||
#include "core/containers/vector.h"
|
#include "core/containers/vector.h"
|
||||||
@ -10,9 +10,10 @@
|
|||||||
|
|
||||||
class Request;
|
class Request;
|
||||||
class FormValidator;
|
class FormValidator;
|
||||||
|
class QueryResult;
|
||||||
|
|
||||||
class BuildingController : public AdminNode {
|
class BuildingNode : public AdminNode {
|
||||||
RCPP_OBJECT(BuildingController, AdminNode);
|
RCPP_OBJECT(BuildingNode, AdminNode);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void handle_request_default(Request *request);
|
void handle_request_default(Request *request);
|
||||||
@ -25,17 +26,23 @@ public:
|
|||||||
void admin_render_building_list(Request *request);
|
void admin_render_building_list(Request *request);
|
||||||
void admin_render_building(Request *request, Ref<Building> building);
|
void admin_render_building(Request *request, Ref<Building> building);
|
||||||
|
|
||||||
|
virtual Ref<Building> db_get_building(const int id);
|
||||||
|
virtual Vector<Ref<Building> > db_get_all();
|
||||||
|
virtual void db_save_building(Ref<Building> &building);
|
||||||
|
|
||||||
|
virtual void db_parse_row(Ref<QueryResult> &result, Ref<Building> &building);
|
||||||
|
|
||||||
void create_table();
|
void create_table();
|
||||||
void drop_table();
|
void drop_table();
|
||||||
void create_default_entries();
|
void create_default_entries();
|
||||||
|
|
||||||
static BuildingController *get_singleton();
|
static BuildingNode *get_singleton();
|
||||||
|
|
||||||
BuildingController();
|
BuildingNode();
|
||||||
~BuildingController();
|
~BuildingNode();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static BuildingController *_self;
|
static BuildingNode *_self;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -22,10 +22,10 @@
|
|||||||
#include "mourne_user_controller.h"
|
#include "mourne_user_controller.h"
|
||||||
|
|
||||||
#include "assignments/assignment_initializer.h"
|
#include "assignments/assignment_initializer.h"
|
||||||
#include "buildings/building_initializer.h"
|
|
||||||
#include "weather/weather_initializer.h"
|
#include "weather/weather_initializer.h"
|
||||||
|
|
||||||
#include "village/village_node.h"
|
#include "village/village_node.h"
|
||||||
|
#include "buildings/building_node.h"
|
||||||
|
|
||||||
void MourneRoot::handle_request_main(Request *request) {
|
void MourneRoot::handle_request_main(Request *request) {
|
||||||
if (process_middlewares(request)) {
|
if (process_middlewares(request)) {
|
||||||
@ -256,24 +256,20 @@ 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();
|
|
||||||
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();
|
|
||||||
AssignmentController::get_singleton()->drop_table();
|
AssignmentController::get_singleton()->drop_table();
|
||||||
WeatherController::get_singleton()->drop_table();
|
WeatherController::get_singleton()->drop_table();
|
||||||
}
|
}
|
||||||
void MourneRoot::udpate_table() {
|
void MourneRoot::udpate_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()->udpate_table();
|
|
||||||
AssignmentController::get_singleton()->udpate_table();
|
AssignmentController::get_singleton()->udpate_table();
|
||||||
WeatherController::get_singleton()->udpate_table();
|
WeatherController::get_singleton()->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();
|
|
||||||
AssignmentController::get_singleton()->create_default_entries();
|
AssignmentController::get_singleton()->create_default_entries();
|
||||||
WeatherController::get_singleton()->create_default_entries();
|
WeatherController::get_singleton()->create_default_entries();
|
||||||
}
|
}
|
||||||
@ -311,7 +307,6 @@ void MourneRoot::compile_menu() {
|
|||||||
MourneRoot::MourneRoot() :
|
MourneRoot::MourneRoot() :
|
||||||
WebRoot() {
|
WebRoot() {
|
||||||
|
|
||||||
BuildingInitializer::allocate_all();
|
|
||||||
AssignmentInitializer::allocate_all();
|
AssignmentInitializer::allocate_all();
|
||||||
WeatherInitializer::allocate_all();
|
WeatherInitializer::allocate_all();
|
||||||
|
|
||||||
@ -319,9 +314,13 @@ MourneRoot::MourneRoot() :
|
|||||||
_village->set_uri_segment("village");
|
_village->set_uri_segment("village");
|
||||||
add_child(_village);
|
add_child(_village);
|
||||||
|
|
||||||
|
_building = new BuildingNode();
|
||||||
|
_building->set_uri_segment("building");
|
||||||
|
add_child(_building);
|
||||||
|
|
||||||
_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", _building);
|
||||||
_admin_panel->register_admin_controller("assignments", AssignmentController::get_singleton());
|
_admin_panel->register_admin_controller("assignments", AssignmentController::get_singleton());
|
||||||
_admin_panel->register_admin_controller("weather", WeatherController::get_singleton());
|
_admin_panel->register_admin_controller("weather", WeatherController::get_singleton());
|
||||||
|
|
||||||
@ -349,7 +348,6 @@ MourneRoot::MourneRoot() :
|
|||||||
}
|
}
|
||||||
|
|
||||||
MourneRoot::~MourneRoot() {
|
MourneRoot::~MourneRoot() {
|
||||||
BuildingInitializer::free_all();
|
|
||||||
AssignmentInitializer::free_all();
|
AssignmentInitializer::free_all();
|
||||||
WeatherInitializer::free_all();
|
WeatherInitializer::free_all();
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ class UserController;
|
|||||||
class MenuNode;
|
class MenuNode;
|
||||||
class MourneUserController;
|
class MourneUserController;
|
||||||
class VillageNode;
|
class VillageNode;
|
||||||
|
class BuildingNode;
|
||||||
|
|
||||||
#define ENSURE_LOGIN(request) \
|
#define ENSURE_LOGIN(request) \
|
||||||
if (!is_logged_in(request)) { \
|
if (!is_logged_in(request)) { \
|
||||||
@ -66,6 +67,7 @@ public:
|
|||||||
MenuNode *_menu;
|
MenuNode *_menu;
|
||||||
|
|
||||||
VillageNode *_village;
|
VillageNode *_village;
|
||||||
|
BuildingNode *_building;
|
||||||
|
|
||||||
static String menu_head;
|
static String menu_head;
|
||||||
static String admin_headers;
|
static String admin_headers;
|
||||||
|
Loading…
Reference in New Issue
Block a user