about summary refs log tree commit diff stats
path: root/data/maps/the_great/rooms/Back Area.txtpb
blob: 33da39477b9f7861714f9ac5833f8eda7e104175 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: "Back Area"
panel_display_name: "Back Area"
panels {
  name: "PLANT"
  path: "Panels/General/entry_14"
  clue: "plant"
  answer: "growth"
  symbols: NULL
}
panels {
  name: "TREE"
  path: "Panels/General/entry_15"
  clue: "tree"
  answer: "growth"
  symbols: NULL
}
panels {
  name: "PAINTING"
  path: "Panels/General/entry_11"
  clue: "painting"
  answer: "art"
  symbols: EXAMPLE
}
panels {
  name: "TOWEL"
  path: "Panels/Towers/tower_2"
  clue: "towel"
  answer: "tower"
  symbols: SPARKLES
}
paintings {
  name: "SPIRAL"
  path: "Components/Paintings/spiral"
  enter_only: true
  orientation: "north"
  required_door { name: "Spiral Painting" }
  # TODO: Hint painting type
}
ports {
  name: "UNKEMPT"
  display_name: "Unkempt Entrance"
  path: "Meshes/Blocks/Warps/worldport5"
  destination { x: 72 y: 0 z: 10.5 }
  rotation: 180
}
ports {
  name: "THREEDOORS"
  display_name: "Three Doors Entrance"
  path: "Meshes/Blocks/Warps/worldport16"
  destination { x: 77 y: 0 z: 33.5 }
  rotation: 0
}
ports {
  name: "TOWER"
  display_name: "Tower Entrance"
  path: "Meshes/Blocks/Warps/worldport10"
  destination { x: 0 y: 0 z: 52 }
  rotation: 0
  required_door { name: "Tower Entrance" }
  # The reverse warp bypasses the door, so there needs to be two oneway connections.
}
ports {
  name: "TREE"
  display_name: "Tree Entrance"
  path: "Meshes/Blocks/Warps/worldport17"
  destination { x: 26 y: 0 z: 58 }
  rotation: 180
}
ght .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>

#include <cstdint>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <string>

#include "proto/human.pb.h"
#include "util/ids_yaml_format.h"
#include "util/naming.h"

namespace com::fourisland::lingo2_archipelago {
namespace {

template <typename T>
T ReadMessageFromFile(const std::string& path) {
  std::cout << "Processing " << path << std::endl;

  std::ifstream file(path);
  std::stringstream buffer;
  buffer << file.rdbuf();

  T message;
  google::protobuf::TextFormat::ParseFromString(buffer.str(), &message);

  return message;
}

class AssignIds {
 public:
  AssignIds(const std::string& mapdir) : mapdir_(mapdir) {}

  void Run() {
    std::filesystem::path datadir_path = mapdir_;
    std::filesystem::path ids_path = datadir_path / "ids.yaml";

    ReadIds(ids_path);

    ProcessMaps(datadir_path);

    WriteIds(ids_path);

    std::cout << "Next ID: " << next_id_ << std::endl;
  }

  void ReadIds(std::filesystem::path path) {
    if (!std::filesystem::exists(path)) {
      return;
    }

    id_mappings_ = ReadIdsFromYaml(path.string());

    for (const auto& [_, map] : id_mappings_.maps()) {
      for (const auto& [_, id] : map.doors()) {
        if (id > next_id_) {
          next_id_ = id;
        }
      }

      for (const auto& [_, room] : map.rooms()) {
        for (const auto& [_, id] : room.panels()) {
          if (id > next_id_) {
            next_id_ = id;
          }
        }

        for (const auto& [_, id] : room.masteries()) {
          if (id > next_id_) {
            next_id_ = id;
          }
        }
      }
    }

    for (const auto& [_, id] : id_mappings_.special()) {
      if (id > next_id_) {
        next_id_ = id;
      }
    }

    for (const auto& [_, id] : id_mappings_.letters()) {
      if (id > next_id_) {
        next_id_ = id;
      }
    }

    for (const auto& [_, id] : id_mappings_.endings()) {
      if (id > next_id_) {
        next_id_ = id;
      }
    }

    next_id_++;
  }

  void WriteIds(std::filesystem::path path) {
    WriteIdsAsYaml(id_mappings_, path.string());
  }

  void ProcessMaps(std::filesystem::path path) {
    std::filesystem::path maps_dir = path / "maps";
    for (auto const& dir_entry :
         std::filesystem::directory_iterator(maps_dir)) {
      ProcessMap(dir_entry.path());
    }
  }

  void ProcessMap(std::filesystem::path path) {
    std::string map_name = path.filename().string();

    ProcessDoorsFile(path / "doors.txtpb", map_name);
    ProcessRooms(path / "rooms", map_name);
  }

  void ProcessDoorsFile(std::filesystem::path path,
                        const std::string& current_map_name) {
    if (!std::filesystem::exists(path)) {
      return;
    }

    auto doors = ReadMessageFromFile<HumanDoors>(path.string());

    for (const HumanDoor& door : doors.doors()) {
      ProcessDoor(door, current_map_name);
    }
  }

  void ProcessDoor(const HumanDoor& h_door,
                   const std::string& current_map_name) {
    if (h_door.type() == DoorType::EVENT) {
      return;
    }

    if (!id_mappings_.maps().contains(current_map_name) ||
        !id_mappings_.maps()
             .at(current_map_name)
             .doors()
             .contains(h_door.name())) {
      auto& maps = *id_mappings_.mutable_maps();
      auto& doors = *maps[current_map_name].mutable_doors();
      doors[h_door.name()] = next_id_++;
    }
  }

  void ProcessRooms(std::filesystem::path path,
                    const std::string& current_map_name) {
    for (auto const& dir_entry : std::filesystem::directory_iterator(path)) {
      auto room = ReadMessageFromFile<HumanRoom>(dir_entry.path().string());
      ProcessRoom(room, current_map_name);
    }
  }

  void ProcessRoom(const HumanRoom& h_room,
                   const std::string& current_map_name) {
    for (const HumanPanel& h_panel : h_room.panels()) {
      if (!id_mappings_.maps().contains(current_map_name) ||
          !id_mappings_.maps()
               .at(current_map_name)
               .rooms()
               .contains(h_room.name()) ||
          !id_mappings_.maps()
               .at(current_map_name)
               .rooms()
               .at(h_room.name())
               .panels()
               .contains(h_panel.name())) {
        auto& maps = *id_mappings_.mutable_maps();
        auto& rooms = *maps[current_map_name].mutable_rooms();
        auto& panels = *rooms[h_room.name()].mutable_panels();
        panels[h_panel.name()] = next_id_++;
      }
    }

    for (const HumanLetter& h_letter : h_room.letters()) {
      std::string lettername = GetLetterName(h_letter.key(), h_letter.level2());

      if (!id_mappings_.letters().contains(lettername)) {
        auto& letters = *id_mappings_.mutable_letters();
        letters[lettername] = next_id_++;
      }
    }

    for (const HumanMastery& h_mastery : h_room.masteries()) {
      if (!id_mappings_.maps().contains(current_map_name) ||
          !id_mappings_.maps()
               .at(current_map_name)
               .rooms()
               .contains(h_room.name()) ||
          !id_mappings_.maps()
               .at(current_map_name)
               .rooms()
               .at(h_room.name())
               .masteries()
               .contains(h_mastery.name())) {
        auto& maps = *id_mappings_.mutable_maps();
        auto& rooms = *maps[current_map_name].mutable_rooms();
        auto& masteries = *rooms[h_room.name()].mutable_masteries();
        masteries[h_mastery.name()] = next_id_++;
      }
    }

    for (const HumanEnding& h_ending : h_room.endings()) {
      if (!id_mappings_.endings().contains(h_ending.name())) {
        auto& endings = *id_mappings_.mutable_endings();
        endings[h_ending.name()] = next_id_++;
      }
    }
  }

 private:
  std::string mapdir_;

  uint64_t next_id_ = 1;

  IdMappings id_mappings_;
};

}  // namespace
}  // namespace com::fourisland::lingo2_archipelago

int main(int argc, char** argv) {
  if (argc != 2) {
    std::cout << "Incorrect argument count." << std::endl;
    std::cout << "Usage: assign_ids [path to map directory]" << std::endl;
    return 1;
  }

  std::string mapdir = argv[1];

  com::fourisland::lingo2_archipelago::AssignIds assign_ids(mapdir);
  assign_ids.Run();

  return 0;
}