about summary refs log tree commit diff stats
path: root/src
Commit message (Expand)AuthorAgeFilesLines
* Added connection historyStar Rauchenberger2024-03-075-20/+100
* Bump version v0.6.5Star Rauchenberger2024-02-181-1/+1
* Make win condition checkableStar Rauchenberger2024-02-186-8/+62
* Bump version v0.6.4Star Rauchenberger2024-01-271-1/+1
* Fix area popups not shrinkingStar Rauchenberger2024-01-271-0/+1
* Bump version v0.6.3Star Rauchenberger2024-01-191-1/+1
* Area popups are now paintedStar Rauchenberger2024-01-195-129/+91
* Open window at a bigger sizeStar Rauchenberger2024-01-191-2/+1
* Fix some bad memory access stuffStar Rauchenberger2024-01-191-82/+99
* Bump version v0.6.2Star Rauchenberger2024-01-121-1/+1
* Bump version v0.6.1Star Rauchenberger2023-11-281-1/+1
* Stop relying on correctly set working directoryStar Rauchenberger2023-11-268-14/+65
* Handle LEVEL 2 panel hunt being enabled globally nowStar Rauchenberger2023-11-251-1/+2
* Bump version v0.6.0Star Rauchenberger2023-11-171-1/+1
* Fixed hunt-only areas not showing up for huntsStar Rauchenberger2023-11-173-1/+4
* Show hunt panels optionStar Rauchenberger2023-11-1711-6/+54
* Added hybrid areas and settings dialogStar Rauchenberger2023-11-177-19/+118
* Bump version v0.5.7Star Rauchenberger2023-11-101-1/+1
* Bump version v0.5.6Star Rauchenberger2023-11-101-1/+1
* Bump version v0.5.5Star Rauchenberger2023-11-091-1/+1
* Bump version v0.5.4Star Rauchenberger2023-10-191-1/+1
* Check for updates on Four Island nowStar Rauchenberger2023-10-191-25/+15
* Bump versionStar Rauchenberger2023-09-281-1/+1
* Added early color hallways support v0.5.3Star Rauchenberger2023-09-283-0/+13
* Bump version v0.5.2Star Rauchenberger2023-09-171-1/+1
* Fixed race condition in reachabilityStar Rauchenberger2023-09-171-3/+11
* Use hardcoded AP ids nowStar Rauchenberger2023-09-178-106/+143
* Bump version v0.5.1Star Rauchenberger2023-09-071-1/+1
* Bump version v0.5.0Star Rauchenberger2023-08-251-1/+1
* Panelsanity supportStar Rauchenberger2023-08-257-76/+131
* Rewrote how panel solvability is determinedStar Rauchenberger2023-08-253-64/+102
* Keep flood boundary even when on doors modeStar Rauchenberger2023-08-231-1/+3
* Version bump v0.4.5Star Rauchenberger2023-08-031-1/+1
* LEVEL 2 and required_panel supportStar Rauchenberger2023-08-035-0/+75
* Bump version v0.4.4Star Rauchenberger2023-07-241-1/+1
* New data storage key formatStar Rauchenberger2023-07-241-3/+11
* Bump version v0.4.3Star Rauchenberger2023-07-031-1/+1
* Doors show up in popups in definition orderStar Rauchenberger2023-07-031-1/+6
* Bump version v0.4.2Star Rauchenberger2023-06-181-1/+1
* Bump versionStar Rauchenberger2023-06-181-1/+1
* Bump version v0.4.1 v0.4.0Star Rauchenberger2023-05-271-1/+1
* Show list of achievements on the sideStar Rauchenberger2023-05-218-4/+122
* Bump version v0.3.0Star Rauchenberger2023-05-181-1/+1
* Added some loggingStar Rauchenberger2023-05-183-5/+62
* Bump version v0.2.0Star Rauchenberger2023-05-091-1/+1
* Support reduce_checksStar Rauchenberger2023-05-097-3/+55
* Detect fake pilgrimageStar Rauchenberger2023-05-061-0/+24
* Automatically check for updatesStar Rauchenberger2023-05-065-3/+148
* Refactored away singletonsStar Rauchenberger2023-05-057-593/+622
* Use local cert store if availableStar Rauchenberger2023-05-051-1/+8
n class="cp">#include <hkutil/string.h> #include <yaml-cpp/yaml.h> #include <iostream> namespace { LingoColor GetColorForString(const std::string &str) { if (str == "black") { return LingoColor::kBlack; } else if (str == "red") { return LingoColor::kRed; } else if (str == "blue") { return LingoColor::kBlue; } else if (str == "yellow") { return LingoColor::kYellow; } else if (str == "orange") { return LingoColor::kOrange; } else if (str == "green") { return LingoColor::kGreen; } else if (str == "gray") { return LingoColor::kGray; } else if (str == "brown") { return LingoColor::kBrown; } else if (str == "purple") { return LingoColor::kPurple; } else { std::cout << "Invalid color: " << str << std::endl; return LingoColor::kNone; } } struct GameData { std::vector<Room> rooms_; std::vector<Door> doors_; std::vector<Panel> panels_; std::vector<MapArea> map_areas_; std::map<std::string, int> room_by_id_; std::map<std::string, int> door_by_id_; std::map<std::string, int> panel_by_id_; std::map<std::string, int> area_by_id_; std::map<std::string, int> room_by_painting_; std::vector<int> achievement_panels_; GameData() { YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml"); YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml"); rooms_.reserve(lingo_config.size() * 2); for (const auto &room_it : lingo_config) { int room_id = AddOrGetRoom(room_it.first.as<std::string>()); Room &room_obj = rooms_[room_id]; for (const auto &entrance_it : room_it.second["entrances"]) { int from_room_id = AddOrGetRoom(entrance_it.first.as<std::string>()); Room &from_room_obj = rooms_[from_room_id]; switch (entrance_it.second.Type()) { case YAML::NodeType::Scalar: { // This is just "true". from_room_obj.exits.push_back({.destination_room = room_id}); break; } case YAML::NodeType::Map: { Exit exit_obj; exit_obj.destination_room = room_id; if (entrance_it.second["door"]) { std::string door_room = room_obj.name; if (entrance_it.second["room"]) { door_room = entrance_it.second["room"].as<std::string>(); } exit_obj.door = AddOrGetDoor( door_room, entrance_it.second["door"].as<std::string>()); } if (entrance_it.second["painting"]) { exit_obj.painting = entrance_it.second["painting"].as<bool>(); } from_room_obj.exits.push_back(exit_obj); break; } case YAML::NodeType::Sequence: { for (const auto &option : entrance_it.second) { Exit exit_obj; exit_obj.destination_room = room_id; std::string door_room = room_obj.name; if (option["room"]) { door_room = option["room"].as<std::string>(); } exit_obj.door = AddOrGetDoor(door_room, option["door"].as<std::string>()); if (option["painting"]) { exit_obj.painting = option["painting"].as<bool>(); } from_room_obj.exits.push_back(exit_obj); } break; } default: { // This shouldn't happen. std::cout << "Error reading game data: " << entrance_it << std::endl; break; } } } if (room_it.second["panels"]) { for (const auto &panel_it : room_it.second["panels"]) { int panel_id = AddOrGetPanel(room_obj.name, panel_it.first.as<std::string>()); Panel &panel_obj = panels_[panel_id]; if (panel_it.second["colors"]) { if (panel_it.second["colors"].IsScalar()) { panel_obj.colors.push_back(GetColorForString( panel_it.second["colors"].as<std::string>())); } else { for (const auto &color_node : panel_it.second["colors"]) { panel_obj.colors.push_back( GetColorForString(color_node.as<std::string>())); } } } if (panel_it.second["required_room"]) { if (panel_it.second["required_room"].IsScalar()) { panel_obj.required_rooms.push_back(AddOrGetRoom( panel_it.second["required_room"].as<std::string>())); } else { for (const auto &rr_node : panel_it.second["required_room"]) { panel_obj.required_rooms.push_back( AddOrGetRoom(rr_node.as<std::string>())); } } } if (panel_it.second["required_door"]) { if (panel_it.second["required_door"].IsMap()) { std::string rd_room = room_obj.name; if (panel_it.second["required_door"]["room"]) { rd_room = panel_it.second["required_door"]["room"].as<std::string>(); } panel_obj.required_doors.push_back(AddOrGetDoor( rd_room, panel_it.second["required_door"]["door"].as<std::string>())); } else { for (const auto &rr_node : panel_it.second["required_door"]) { std::string rd_room = room_obj.name; if (rr_node["room"]) { rd_room = rr_node["room"].as<std::string>(); } panel_obj.required_doors.push_back( AddOrGetDoor(rd_room, rr_node["door"].as<std::string>())); } } } if (panel_it.second["check"]) { panel_obj.check = panel_it.second["check"].as<bool>(); } if (panel_it.second["achievement"]) { panel_obj.achievement = panel_it.second["achievement"].as<bool>(); if (panel_obj.achievement) { achievement_panels_.push_back(panel_id); } } if (panel_it.second["exclude_reduce"]) { panel_obj.exclude_reduce = panel_it.second["exclude_reduce"].as<bool>(); } } } if (room_it.second["doors"]) { for (const auto &door_it : room_it.second["doors"]) { int door_id = AddOrGetDoor(room_obj.name, door_it.first.as<std::string>()); Door &door_obj = doors_[door_id]; bool has_external_panels = false; std::vector<std::string> panel_names; for (const auto &panel_node : door_it.second["panels"]) { if (panel_node.IsScalar()) { panel_names.push_back(panel_node.as<std::string>()); door_obj.panels.push_back( AddOrGetPanel(room_obj.name, panel_node.as<std::string>())); } else { has_external_panels = true; panel_names.push_back(panel_node["panel"].as<std::string>()); door_obj.panels.push_back( AddOrGetPanel(panel_node["room"].as<std::string>(), panel_node["panel"].as<std::string>())); } } if (door_it.second["skip_location"]) { door_obj.skip_location = door_it.second["skip_location"].as<bool>(); } if (door_it.second["skip_item"]) { door_obj.skip_item = door_it.second["skip_item"].as<bool>(); } if (door_it.second["event"]) { door_obj.skip_location = door_it.second["event"].as<bool>(); door_obj.skip_item = door_it.second["event"].as<bool>(); } if (door_it.second["item_name"]) { door_obj.item_name = door_it.second["item_name"].as<std::string>(); } else if (!door_it.second["skip_item"] && !door_it.second["event"]) { door_obj.item_name = room_obj.name + " - " + door_obj.name; } if (door_it.second["group"]) { door_obj.group_name = door_it.second["group"].as<std::string>(); } if (door_it.second["location_name"]) { door_obj.location_name = door_it.second["location_name"].as<std::string>(); } else if (!door_it.second["skip_location"] && !door_it.second["event"]) { if (has_external_panels) { std::cout << room_obj.name << " - " << door_obj.name << " has panels from other rooms but does not have an " "explicit " "location name and is not marked skip_location or event" << std::endl; } door_obj.location_name = room_obj.name + " - " + hatkirby::implode(panel_names, ", "); } if (door_it.second["include_reduce"]) { door_obj.exclude_reduce = !door_it.second["include_reduce"].as<bool>(); } } } if (room_it.second["paintings"]) { for (const auto &painting : room_it.second["paintings"]) { std::string painting_id = painting["id"].as<std::string>(); room_by_painting_[painting_id] = room_id; if (!painting["exit_only"] || !painting["exit_only"].as<bool>()) { PaintingExit painting_exit; painting_exit.id = painting_id; if (painting["required_door"]) { std::string rd_room = room_obj.name; if (painting["required_door"]["room"]) { rd_room = painting["required_door"]["room"].as<std::string>(); } painting_exit.door = AddOrGetDoor( rd_room, painting["required_door"]["door"].as<std::string>()); } room_obj.paintings.push_back(painting_exit); } } } if (room_it.second["progression"]) { for (const auto &progression_it : room_it.second["progression"]) { std::string progressive_item_name = progression_it.first.as<std::string>(); int index = 1; for (const auto &stage : progression_it.second) { int door_id = -1; if (stage.IsScalar()) { door_id = AddOrGetDoor(room_obj.name, stage.as<std::string>()); } else { door_id = AddOrGetDoor(stage["room"].as<std::string>(), stage["door"].as<std::string>()); } doors_[door_id].progressives.push_back( {.item_name = progressive_item_name, .quantity = index}); index++; } } } } map_areas_.reserve(areas_config.size()); std::map<std::string, int> fold_areas; for (const auto &area_it : areas_config) { if (area_it.second["map"]) { int area_id = AddOrGetArea(area_it.first.as<std::string>()); MapArea &area_obj = map_areas_[area_id]; area_obj.map_x = area_it.second["map"][0].as<int>(); area_obj.map_y = area_it.second["map"][1].as<int>(); } else if (area_it.second["fold_into"]) { fold_areas[area_it.first.as<std::string>()] = AddOrGetArea(area_it.second["fold_into"].as<std::string>()); } } for (const Panel &panel : panels_) { if (panel.check) { int room_id = panel.room; std::string room_name = rooms_[room_id].name; std::string area_name = room_name; if (fold_areas.count(room_name)) { int fold_area_id = fold_areas[room_name]; area_name = map_areas_[fold_area_id].name; } int area_id = AddOrGetArea(area_name); MapArea &map_area = map_areas_[area_id]; // room field should be the original room ID map_area.locations.push_back( {.name = panel.name, .ap_location_name = room_name + " - " + panel.name, .room = panel.room, .panels = {panel.id}}); } } for (const Door &door : doors_) { if (!door.skip_location) { int room_id = door.room; std::string area_name = rooms_[room_id].name; std::string section_name; size_t divider_pos = door.location_name.find(" - "); if (divider_pos == std::string::npos) { section_name = door.location_name; } else { area_name = door.location_name.substr(0, divider_pos); section_name = door.location_name.substr(divider_pos + 3); } if (fold_areas.count(area_name)) { int fold_area_id = fold_areas[area_name]; area_name = map_areas_[fold_area_id].name; } int area_id = AddOrGetArea(area_name); MapArea &map_area = map_areas_[area_id]; // room field should be the original room ID map_area.locations.push_back({.name = section_name, .ap_location_name = door.location_name, .room = door.room, .panels = door.panels}); } } } int AddOrGetRoom(std::string room) { if (!room_by_id_.count(room)) { room_by_id_[room] = rooms_.size(); rooms_.push_back({.name = room}); } return room_by_id_[room]; } int AddOrGetDoor(std::string room, std::string door) { std::string full_name = room + " - " + door; if (!door_by_id_.count(full_name)) { door_by_id_[full_name] = doors_.size(); doors_.push_back({.room = AddOrGetRoom(room), .name = door}); } return door_by_id_[full_name]; } int AddOrGetPanel(std::string room, std::string panel) { std::string full_name = room + " - " + panel; if (!panel_by_id_.count(full_name)) { int panel_id = panels_.size(); panel_by_id_[full_name] = panel_id; panels_.push_back( {.id = panel_id, .room = AddOrGetRoom(room), .name = panel}); } return panel_by_id_[full_name]; } int AddOrGetArea(std::string area) { if (!area_by_id_.count(area)) { int area_id = map_areas_.size(); area_by_id_[area] = area_id; map_areas_.push_back({.id = area_id, .name = area}); } return area_by_id_[area]; } }; GameData &GetState() { static GameData *instance = new GameData(); return *instance; } } // namespace const std::vector<MapArea> &GD_GetMapAreas() { return GetState().map_areas_; } const MapArea &GD_GetMapArea(int id) { return GetState().map_areas_.at(id); } int GD_GetRoomByName(const std::string &name) { return GetState().room_by_id_.at(name); } const Room &GD_GetRoom(int room_id) { return GetState().rooms_.at(room_id); } const std::vector<Door> &GD_GetDoors() { return GetState().doors_; } const Door &GD_GetDoor(int door_id) { return GetState().doors_.at(door_id); } const Panel &GD_GetPanel(int panel_id) { return GetState().panels_.at(panel_id); } int GD_GetRoomForPainting(const std::string &painting_id) { return GetState().room_by_painting_.at(painting_id); } const std::vector<int> &GD_GetAchievementPanels() { return GetState().achievement_panels_; }