about summary refs log tree commit diff stats
path: root/game_data.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game_data.cpp')
-rw-r--r--game_data.cpp73
1 files changed, 37 insertions, 36 deletions
diff --git a/game_data.cpp b/game_data.cpp index db574d3..0ae5468 100644 --- a/game_data.cpp +++ b/game_data.cpp
@@ -1,9 +1,10 @@
1#include "game_data.h" 1#include "game_data.h"
2 2
3#include <hkutil/string.h> 3#include <hkutil/string.h>
4#include <iostream>
5#include <yaml-cpp/yaml.h> 4#include <yaml-cpp/yaml.h>
6 5
6#include <iostream>
7
7LingoColor GetColorForString(const std::string &str) { 8LingoColor GetColorForString(const std::string &str) {
8 if (str == "black") { 9 if (str == "black") {
9 return LingoColor::kBlack; 10 return LingoColor::kBlack;
@@ -33,7 +34,7 @@ GameData::GameData() {
33 YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml"); 34 YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml");
34 YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml"); 35 YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml");
35 36
36 rooms_.reserve(lingo_config.size() + 1); // The +1 is for Menu 37 rooms_.reserve(lingo_config.size() + 1); // The +1 is for Menu
37 38
38 for (const auto &room_it : lingo_config) { 39 for (const auto &room_it : lingo_config) {
39 int room_id = AddOrGetRoom(room_it.first.as<std::string>()); 40 int room_id = AddOrGetRoom(room_it.first.as<std::string>());
@@ -44,49 +45,49 @@ GameData::GameData() {
44 Room &from_room_obj = rooms_[from_room_id]; 45 Room &from_room_obj = rooms_[from_room_id];
45 46
46 switch (entrance_it.second.Type()) { 47 switch (entrance_it.second.Type()) {
47 case YAML::NodeType::Scalar: { 48 case YAML::NodeType::Scalar: {
48 // This is just "true". 49 // This is just "true".
49 from_room_obj.exits.push_back({.destination_room = room_id}); 50 from_room_obj.exits.push_back({.destination_room = room_id});
50 break; 51 break;
51 }
52 case YAML::NodeType::Map: {
53 Exit exit_obj;
54 exit_obj.destination_room = room_id;
55
56 if (entrance_it.second["door"]) {
57 std::string door_room = room_obj.name;
58 if (entrance_it.second["room"]) {
59 door_room = entrance_it.second["room"].as<std::string>();
60 }
61 exit_obj.door = AddOrGetDoor(
62 door_room, entrance_it.second["door"].as<std::string>());
63 } 52 }
64 53 case YAML::NodeType::Map: {
65 from_room_obj.exits.push_back(exit_obj);
66 break;
67 }
68 case YAML::NodeType::Sequence: {
69 for (const auto &option : entrance_it.second) {
70 Exit exit_obj; 54 Exit exit_obj;
71 exit_obj.destination_room = room_id; 55 exit_obj.destination_room = room_id;
72 56
73 std::string door_room = room_obj.name; 57 if (entrance_it.second["door"]) {
74 if (option["room"]) { 58 std::string door_room = room_obj.name;
75 door_room = option["room"].as<std::string>(); 59 if (entrance_it.second["room"]) {
60 door_room = entrance_it.second["room"].as<std::string>();
61 }
62 exit_obj.door = AddOrGetDoor(
63 door_room, entrance_it.second["door"].as<std::string>());
76 } 64 }
77 exit_obj.door =
78 AddOrGetDoor(door_room, option["door"].as<std::string>());
79 65
80 from_room_obj.exits.push_back(exit_obj); 66 from_room_obj.exits.push_back(exit_obj);
67 break;
81 } 68 }
69 case YAML::NodeType::Sequence: {
70 for (const auto &option : entrance_it.second) {
71 Exit exit_obj;
72 exit_obj.destination_room = room_id;
73
74 std::string door_room = room_obj.name;
75 if (option["room"]) {
76 door_room = option["room"].as<std::string>();
77 }
78 exit_obj.door =
79 AddOrGetDoor(door_room, option["door"].as<std::string>());
82 80
83 break; 81 from_room_obj.exits.push_back(exit_obj);
84 } 82 }
85 default: { 83
86 // This shouldn't happen. 84 break;
87 std::cout << "Error reading game data: " << entrance_it << std::endl; 85 }
88 break; 86 default: {
89 } 87 // This shouldn't happen.
88 std::cout << "Error reading game data: " << entrance_it << std::endl;
89 break;
90 }
90 } 91 }
91 } 92 }
92 93