Finally upgraded the strings to const& since I'm about to pull guecs out and distribute it. Oh well, the joke's finally over.
This commit is contained in:
parent
82ce3cb6be
commit
438bd8ab8a
8 changed files with 53 additions and 74 deletions
34
guecs.cpp
34
guecs.cpp
|
@ -22,12 +22,12 @@ namespace guecs {
|
|||
text->setCharacterSize(size);
|
||||
}
|
||||
|
||||
void Textual::update(std::wstring& new_content) {
|
||||
void Textual::update(const wstring& new_content) {
|
||||
content = new_content;
|
||||
text->setString(content);
|
||||
}
|
||||
|
||||
void Sprite::update(const std::string& new_name) {
|
||||
void Sprite::update(const string& new_name) {
|
||||
if(new_name != name) {
|
||||
name = new_name;
|
||||
auto sprite_texture = textures::get(name);
|
||||
|
@ -142,7 +142,7 @@ namespace guecs {
|
|||
return {float($parser.grid_w), float($parser.grid_h)};
|
||||
}
|
||||
|
||||
void UI::layout(std::string grid) {
|
||||
void UI::layout(const string& grid) {
|
||||
$grid = grid;
|
||||
bool good = $parser.parse($grid);
|
||||
dbc::check(good, "LEL parsing failed.");
|
||||
|
@ -153,7 +153,7 @@ namespace guecs {
|
|||
}
|
||||
}
|
||||
|
||||
DinkyECS::Entity UI::init_entity(std::string name) {
|
||||
DinkyECS::Entity UI::init_entity(const string& name) {
|
||||
auto entity = $world.entity();
|
||||
// this lets you look up an entity by name
|
||||
$name_ents.insert_or_assign(name, entity);
|
||||
|
@ -162,13 +162,13 @@ namespace guecs {
|
|||
return entity;
|
||||
}
|
||||
|
||||
DinkyECS::Entity UI::entity(std::string name) {
|
||||
DinkyECS::Entity UI::entity(const string& name) {
|
||||
dbc::check($name_ents.contains(name),
|
||||
fmt::format("GUECS entity {} does not exist. Mispelled cell name?", name));
|
||||
return $name_ents.at(name);
|
||||
}
|
||||
|
||||
DinkyECS::Entity UI::entity(std::string name, int id) {
|
||||
DinkyECS::Entity UI::entity(const string& name, int id) {
|
||||
return entity(fmt::format("{}{}", name, id));
|
||||
}
|
||||
|
||||
|
@ -293,27 +293,31 @@ namespace guecs {
|
|||
return action_count > 0;
|
||||
}
|
||||
|
||||
void UI::show_sprite(string region, string sprite_name) {
|
||||
void UI::show_sprite(const string& region, const string& sprite_name) {
|
||||
auto ent = entity(region);
|
||||
// BUG: this should have two branches that just update the sprite
|
||||
set_init<Sprite>(ent, {sprite_name});
|
||||
|
||||
if(auto sprite = get_if<Sprite>(ent)) {
|
||||
sprite->update(sprite_name);
|
||||
} else {
|
||||
set_init<Sprite>(ent, {sprite_name});
|
||||
}
|
||||
}
|
||||
|
||||
void UI::show_text(string region, wstring content) {
|
||||
void UI::show_text(const string& region, const wstring& content) {
|
||||
auto ent = entity(region);
|
||||
|
||||
if(auto text = get_if<Textual>(ent)) {
|
||||
text->text->setString(content);
|
||||
if(has<Textual>(ent)) {
|
||||
auto& text = get<Textual>(ent);
|
||||
text.text->setString(content);
|
||||
} else {
|
||||
auto &cell = cell_for(ent);
|
||||
Textual to_set{content, 20};
|
||||
to_set.init(cell, $font);
|
||||
to_set.text->setFillColor(ColorValue::LIGHT_MID);
|
||||
set<Textual>(ent, to_set);
|
||||
}
|
||||
}
|
||||
|
||||
void UI::click_on(const std::string& name, bool required) {
|
||||
void UI::click_on(const string& name, bool required) {
|
||||
auto ent = entity(name);
|
||||
|
||||
if(required) {
|
||||
|
@ -334,7 +338,7 @@ namespace guecs {
|
|||
}
|
||||
}
|
||||
|
||||
void UI::show_label(string region, wstring content) {
|
||||
void UI::show_label(const string& region, const wstring& content) {
|
||||
auto ent = entity(region);
|
||||
|
||||
if(auto text = get_if<Label>(ent)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue