#include "godot_scene.h" #include #include #include #include namespace com::fourisland::lingo2_archipelago { namespace { struct Heading { std::string type; std::string id; std::string path; std::string resource_type; std::string name; std::string parent; GodotInstanceType instance_type; }; Heading ParseTscnHeading(std::string_view line) { std::string original_line(line); Heading heading; if (line[0] != '[') { std::ostringstream errormsg; errormsg << "Heading must start with [." << std::endl << "Bad heading: " << original_line; throw std::invalid_argument(errormsg.str()); } line.remove_prefix(1); int divider = line.find_first_of(" ]"); if (divider == std::string_view::npos) { std::ostringstream errormsg; errormsg << "Malformatted heading: " << line << std::endl << "Original line: " << original_line; throw std::invalid_argument(errormsg.str()); } heading.type = std::string(line.substr(0, divider)); line.remove_prefix(divider + 1); while (!line.empty()) { divider = line.find_first_of("="); if (divider == std::string_view::npos) { std::ostringstream errormsg; errormsg << "Malformatted heading: " << line << std::endl << "Original line: " << original_line; throw std::invalid_argument(errormsg.str()); } std::string key(line.substr(0, divider)); line.remove_prefix(divider + 1); if (line[0] == '"') { line.remove_prefix(1); divider = line.find_first_of("\""); if (divider == std::string_view::npos) { std::ostringstream errormsg; errormsg << "Malformatted heading: " << line << std::endl << "Original line: " << original_line; throw std::invalid_argument(errormsg.str()); } std::string strval(line.substr(0, divider)); line.remove_prefix(divider + 2); if (key == "name") { heading.name = strval; } else if (key == "parent") { heading.parent = strval; } else if (key == "path") { heading.path = strval; } else if (key == "type") { heading.resource_type = strval; } else if (key == "id") { heading.id = strval; } } else if (line[0] == 'S' || line[0] == 'E') { GodotInstanceType rrval; char internal = line[0]; line.remove_prefix(13); // SubResource(" divider = line.find_first_of("\""); if (divider == std::string_view::npos) { std::ostringstream errormsg; errormsg << "Malformatted heading: " << line << std::endl << "Original line: " << original_line; throw std::invalid_argument(errormsg.str()); } std::string refid = std::string(line.substr(0, divider)); line.remove_prefix(divider + 3); GodotInstanceType instance_type; if (internal == 'E') { instance_type = GodotExtResourceRef{.id = refid}; } else { // SubResource is not supported right now. } if (key == "instance") { heading.instance_type = instance_type; } else { // Other keys aren't supported right now. } } else { divider = line.find_first_of(" ]"); if (divider == std::string_view::npos) { std::ostringstream errormsg; errormsg << "Malformatted heading: " << line << std::endl << "Original line: " << original_line; throw std::invalid_argument(errormsg.str()); } int numval = std::atoi(line.substr(0, divider).data()); line.remove_prefix(divider + 1); // keyvals_[key] = numval; } } return heading; } } // namespace std::string GodotNode::GetPath() const { if (parent.empty() || parent == ".") { return name; } else { return parent + "/" + name; } } GodotScene ReadGodotSceneFromFile(const std::string& path) { std::map ext_resources; std::vector nodes; std::ifstream input(path); std::string line; bool section_started = false; Heading cur_heading; std::ostringstream cur_value; bool value_started = false; auto handle_end_of_section = [&]() { section_started = false; value_started = false; if (cur_heading.type == "sub_resource") { // sub_resources_[std::get(cur_heading.GetKeyval("id"))] = // {cur_heading, cur_value.str(), ""}; } else { // other_.emplace_back(cur_heading, cur_value.str()); } cur_value = {}; }; while (std::getline(input, line)) { if (section_started && (line.empty() || line[0] == '[')) { handle_end_of_section(); } if (!line.empty() && line[0] == '[') { Heading heading = ParseTscnHeading(line); if (heading.type == "gd_scene") { // file_descriptor_ = heading; } else if (heading.type == "ext_resource") { GodotExtResource ext_resource; ext_resource.path = heading.path; ext_resource.type = heading.resource_type; ext_resources[heading.id] = ext_resource; } else if (heading.type == "node") { if (heading.parent != "") { nodes.push_back(GodotNode{.name = heading.name, .parent = heading.parent, .instance_type = heading.instance_type}); } } else { cur_heading = heading; section_started = true; } } else if (!line.empty()) { if (value_started) { cur_value << std::endl; } else { value_started = true; } cur_value << line; } } if (section_started) { handle_end_of_section(); } return GodotScene(std::move(ext_resources), std::move(nodes)); } } // namespace com::fourisland::lingo2_archipelago '#n83'>83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
#ifndef TOOLS_VALIDATOR_STRUCTS_H_
#define TOOLS_VALIDATOR_STRUCTS_H_

#include <map>
#include <string>
#include <vector>

#include "proto/human.pb.h"
#include "util/identifiers.h"

namespace com::fourisland::lingo2_archipelago {

struct MalformedIdentifiers {
  std::vector<PaintingIdentifier> paintings;
  std::vector<PanelIdentifier> panels;
  std::vector<KeyholderIdentifier> keyholders;

  bool HasAny() const {
    return !paintings.empty() || !panels.empty() || !keyholders.empty();
  }
};

struct GameNodeInfo {
  bool defined = false;
  int uses = 0;
};

struct MapInfo {
  std::map<std::string, GameNodeInfo> game_nodes;

  std::optional<PortIdentifier> malformed_worldport_entrance;
};

struct RoomInfo {
  std::vector<HumanRoom> definitions;

  std::vector<DoorIdentifier> doors_referenced_by;
  std::vector<PanelIdentifier> panels_referenced_by;
  std::vector<HumanConnection> connections_referenced_by;
};

struct DoorInfo {
  std::vector<HumanDoor> definitions;
  bool has_id = false;

  std::vector<HumanConnection> connections_referenced_by;
  std::vector<DoorIdentifier> doors_referenced_by;
  std::vector<PanelIdentifier> panels_referenced_by;
  std::vector<PaintingIdentifier> paintings_referenced_by;
  std::vector<PortIdentifier> ports_referenced_by;
  std::vector<std::string> progressives_referenced_by;
  std::vector<std::string> door_groups_referenced_by;

  MalformedIdentifiers malformed_identifiers;
};

struct PortInfo {
  std::vector<HumanPort> definitions;

  std::vector<HumanConnection> connections_referenced_by;
  std::vector<HumanConnection> target_connections_referenced_by;
  std::vector<std::string> map_worldport_entrances;
};

struct PaintingInfo {
  std::vector<HumanPainting> definitions;

  std::vector<HumanConnection> connections_referenced_by;
  std::vector<HumanConnection> target_connections_referenced_by;
  std::vector<DoorIdentifier> doors_referenced_by;
};

struct ProxyInfo {
  std::vector<Proxy> definitions;

  std::vector<HumanConnection> connections_referenced_by;
  std::vector<DoorIdentifier> doors_referenced_by;
};

struct PanelInfo {
  std::vector<HumanPanel> definitions;
  bool has_id = false;

  std::string map_area_name;

  std::vector<HumanConnection> connections_referenced_by;
  std::vector<HumanConnection> target_connections_referenced_by;
  std::vector<DoorIdentifier> doors_referenced_by;

  std::map<std::string, ProxyInfo> proxies;
};

struct KeyholderInfo {
  std::vector<HumanKeyholder> definitions;
  bool has_id = false;

  std::vector<DoorIdentifier> doors_referenced_by;
};

using LetterIdentifier = std::tuple<char, bool>;

struct LetterInfo {
  std::vector<RoomIdentifier> defined_in;
  bool has_id = false;
};

struct EndingInfo {
  std::vector<RoomIdentifier> defined_in;
  bool has_id = false;
};

struct PanelNameInfo {
  std::vector<PanelIdentifier> panels_used_by;
};

struct ProgressiveInfo {
  std::vector<HumanProgressive> definitions;
  bool has_id = false;

  std::vector<DoorIdentifier> malformed_doors;
};

struct DoorGroupInfo {
  std::vector<HumanDoorGroup> definitions;
  bool has_id = false;

  std::vector<DoorIdentifier> malformed_doors;
};

struct CollectedInfo {
  std::map<std::string, MapInfo> maps;
  std::map<RoomIdentifier, RoomInfo, RoomIdentifierLess> rooms;
  std::map<DoorIdentifier, DoorInfo, DoorIdentifierLess> doors;
  std::map<PortIdentifier, PortInfo, PortIdentifierLess> ports;
  std::map<PaintingIdentifier, PaintingInfo, PaintingIdentifierLess> paintings;
  std::map<PanelIdentifier, PanelInfo, PanelIdentifierLess> panels;
  std::map<KeyholderIdentifier, KeyholderInfo, KeyholderIdentifierLess>
      keyholders;
  std::map<LetterIdentifier, LetterInfo> letters;
  std::map<std::string, EndingInfo> endings;
  std::map<std::string, PanelNameInfo> panel_names;
  std::map<std::string, ProgressiveInfo> progressives;
  std::map<std::string, DoorGroupInfo> door_groups;
};

}  // namespace com::fourisland::lingo2_archipelago

#endif /* TOOLS_VALIDATOR_STRUCTS_H_ */