Skip to content

Commit

Permalink
console: Fix comment formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Dec 13, 2023
1 parent effd189 commit 95d547c
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 173 deletions.
214 changes: 108 additions & 106 deletions libopenage/console/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,79 +44,83 @@ Console::Console(/* presenter::LegacyDisplay *display */) :

Console::~Console() {}

// void Console::load_colors(std::vector<gamedata::palette_color> &colortable) {
// for (auto &c : colortable) {
// this->termcolors.emplace_back(c);
// }
/*
void Console::load_colors(std::vector<gamedata::palette_color> &colortable) {
for (auto &c : colortable) {
this->termcolors.emplace_back(c);
}
// if (termcolors.size() != 256) {
// throw Error(MSG(err) << "Exactly 256 terminal colors are required.");
// }
// }
if (termcolors.size() != 256) {
throw Error(MSG(err) << "Exactly 256 terminal colors are required.");
}
}
*/

void Console::register_to_engine() {
// TODO: Use new renderer
/*
this->display->register_input_action(this);
this->display->register_tick_action(this);
this->display->register_drawhud_action(this);
this->display->register_resize_action(this);
Bind the console toggle key globally
auto &action = this->display->get_action_manager();
auto &global = this->display->get_input_manager().get_global_context();
global.bind(action.get("TOGGLE_CONSOLE"), [this](const input::legacy::action_arg_t &) {
this->set_visible(!this->visible);
});
// this->display->register_input_action(this);
// this->display->register_tick_action(this);
// this->display->register_drawhud_action(this);
// this->display->register_resize_action(this);

// Bind the console toggle key globally
// auto &action = this->display->get_action_manager();
// auto &global = this->display->get_input_manager().get_global_context();

// global.bind(action.get("TOGGLE_CONSOLE"), [this](const input::legacy::action_arg_t &) {
// this->set_visible(!this->visible);
// });


// TODO: bind any needed input to InputContext

// toggle console will take highest priority
// this->input_context.bind(action.get("TOGGLE_CONSOLE"), [this](const input::legacy::action_arg_t &) {
// this->set_visible(false);
// });
// this->input_context.bind(input::legacy::event_class::UTF8, [this](const input::legacy::action_arg_t &arg) {
// // a single char typed into the console
// std::string utf8 = arg.e.as_utf8();
// this->buf.write(utf8.c_str());
// command += utf8;
// return true;
// });
// this->input_context.bind(input::legacy::event_class::NONPRINT, [this](const input::legacy::action_arg_t &arg) {
// switch (arg.e.as_char()) {
// case 8: // remove a single UTF-8 character
// if (this->command.size() > 0) {
// util::utf8_pop_back(this->command);
// this->buf.pop_last_char();
// }
// return true;

// case 13: // interpret command
// this->buf.write('\n');
// this->interpret(this->command);
// this->command = "";
// return true;

// default:
// return false;
// }
// });
// this->input_context.utf8_mode = true;
TODO: bind any needed input to InputContext
toggle console will take highest priority
this->input_context.bind(action.get("TOGGLE_CONSOLE"), [this](const input::legacy::action_arg_t &) {
this->set_visible(false);
});
this->input_context.bind(input::legacy::event_class::UTF8, [this](const input::legacy::action_arg_t &arg) {
// a single char typed into the console
std::string utf8 = arg.e.as_utf8();
this->buf.write(utf8.c_str());
command += utf8;
return true;
});
this->input_context.bind(input::legacy::event_class::NONPRINT, [this](const input::legacy::action_arg_t &arg) {
switch (arg.e.as_char()) {
case 8: // remove a single UTF-8 character
if (this->command.size() > 0) {
util::utf8_pop_back(this->command);
this->buf.pop_last_char();
}
return true;
case 13: // interpret command
this->buf.write('\n');
this->interpret(this->command);
this->command = "";
return true;
default:
return false;
}
});
this->input_context.utf8_mode = true;
*/
}

void Console::set_visible(bool /* make_visible */) {
// TODO: Use new renderer

// if (make_visible) {
// this->display->get_input_manager().push_context(&this->input_context);
// this->visible = true;
// }
// else {
// this->display->get_input_manager().remove_context(&this->input_context);
// this->visible = false;
// }
/*
if (make_visible) {
this->display->get_input_manager().push_context(&this->input_context);
this->visible = true;
}
else {
this->display->get_input_manager().remove_context(&this->input_context);
this->visible = false;
}
*/
}

void Console::write(const char *text) {
Expand All @@ -143,8 +147,7 @@ void Console::interpret(const std::string &command) {
std::string value = command.substr(second_space + 1, std::string::npos);
// TODO: Use new engine class
// this->engine->get_cvar_manager().set(name, value);
log::log(MSG(dbg) << "Tried setting cvar " << name << " with " << value
<< " but engine is not implemented yet.");
log::log(MSG(dbg) << "Tried setting cvar " << name << " with " << value << " but engine is not implemented yet.");
}
}
else if (command.substr(0, 3) == "get") {
Expand All @@ -154,60 +157,59 @@ void Console::interpret(const std::string &command) {
// TODO: Use new engine class
// std::string value = this->engine->get_cvar_manager().get(name);
// this->write(value.c_str());
log::log(MSG(dbg) << "Tried getting cvar " << name
<< " but engine is not implemented yet.");
log::log(MSG(dbg) << "Tried getting cvar " << name << " but engine is not implemented yet.");
}
}
}
/*
bool Console::on_tick() {
if (!this->visible) {
return true;
}
// bool Console::on_tick() {
// if (!this->visible) {
// return true;
// }

// // TODO: handle stuff such as cursor blinking,
// // repeating held-down keys
// return true;
// }

// bool Console::on_drawhud() {
// if (!this->visible) {
// return true;
// }
// TODO: handle stuff such as cursor blinking,
// repeating held-down keys
return true;
}
// // TODO: Use new renderer
bool Console::on_drawhud() {
if (!this->visible) {
return true;
}
// // draw::to_opengl(this->display, this);
// TODO: Use new renderer
// return true;
// }
// draw::to_opengl(this->display, this);
// bool Console::on_input(SDL_Event *e) {
// // only handle inputs if the console is visible
// if (!this->visible) {
// return true;
// }
return true;
}
// switch (e->type) {
// case SDL_KEYDOWN:
// //TODO handle key inputs
bool Console::on_input(SDL_Event *e) {
// only handle inputs if the console is visible
if (!this->visible) {
return true;
}
// //do not allow anyone else to handle this input
// return false;
// }
switch (e->type) {
case SDL_KEYDOWN:
//TODO handle key inputs
// return true;
// }
//do not allow anyone else to handle this input
return false;
}
// bool Console::on_resize(coord::viewport_delta new_size) {
// coord::pixel_t w = this->buf.get_dims().x * this->charsize.x;
// coord::pixel_t h = this->buf.get_dims().y * this->charsize.y;
return true;
}
// this->bottomleft = {(new_size.x - w) / 2, (new_size.y - h) / 2};
// this->topright = {this->bottomleft.x + w, this->bottomleft.y - h};
bool Console::on_resize(coord::viewport_delta new_size) {
coord::pixel_t w = this->buf.get_dims().x * this->charsize.x;
coord::pixel_t h = this->buf.get_dims().y * this->charsize.y;
// return true;
// }
this->bottomleft = {(new_size.x - w) / 2, (new_size.y - h) / 2};
this->topright = {this->bottomleft.x + w, this->bottomleft.y - h};
return true;
}
*/
} // namespace console
} // namespace openage
Loading

0 comments on commit 95d547c

Please sign in to comment.