#include #include #include #include #include #include #include #include #include #include #include #include "container.h" #include "proto/data.pb.h" #include "proto/human.pb.h" namespace com::fourisland::lingo2_archipelago { namespace { template 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 DataPacker { public: DataPacker(const std::string& mapdir, const std::string& outputpath) : mapdir_(mapdir), outputpath_(outputpath) {} void Run() { std::filesystem::path datadir_path = mapdir_; ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); ProcessMaps(datadir_path); ProcessIdsFile(datadir_path / "ids.txtpb"); { std::ofstream outputfile(outputpath_); container_.all_objects().SerializeToOstream(&outputfile); } std::string output; google::protobuf::TextFormat::PrintToString(container_.all_objects(), &output); std::cout << output << std::endl; } private: 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(); ProcessConnectionsFile(path / "connections.txtpb", map_name); ProcessDoorsFile(path / "doors.txtpb", map_name); ProcessRooms(path / "rooms", map_name); } 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(dir_entry.path().string()); ProcessRoom(room, current_map_name); } } void ProcessRoom(const HumanRoom& h_room, const std::string& current_map_name) { uint64_t room_id = container_.FindOrAddRoom(current_map_name, h_room.name(), std::nullopt); Room& room = *container_.all_objects().mutable_rooms(room_id); room.set_display_name(h_room.display_name()); for (const HumanPanel& h_panel : h_room.panels()) { room.add_panels(ProcessPanel(h_panel, current_map_name, room.name())); } for (const HumanPainting& h_painting : h_room.paintings()) { room.add_paintings( ProcessPainting(h_painting, current_map_name, room.name())); } for (const HumanPort& h_port : h_room.ports()) { room.add_ports(ProcessPort(h_port, current_map_name, room.name())); } std::copy( h_room.letters().begin(), h_room.letters().end(), google::protobuf::RepeatedFieldBackInserter(room.mutable_letters())); } uint64_t ProcessPanel(const HumanPanel& h_panel, const std::string& current_map_name, const std::string& current_room_name) { uint64_t panel_id = container_.FindOrAddPanel(current_map_name, current_room_name, h_panel.name(), std::nullopt, std::nullopt); Panel& panel = *container_.all_objects().mutable_panels(panel_id); panel.set_path(h_panel.path()); panel.set_clue(h_panel.clue()); panel.set_answer(h_panel.answer()); std::copy( h_panel.symbols().begin(), h_panel.symbols().end(), google::protobuf::RepeatedFieldBackInserter(panel.mutable_symbols())); std::copy( h_panel.proxies().begin(), h_panel.proxies().end(), google::protobuf::RepeatedFieldBackInserter(panel.mutable_proxies())); if (h_panel.has_required_door()) { std::optional map_name = h_panel.required_door().has_map() ? std::optional(h_panel.required_door().map()) : std::nullopt; panel.set_required_door(container_.FindOrAddDoor( map_name, h_panel.required_door().name(), current_map_name)); } return panel_id; } uint64_t ProcessPainting(const HumanPainting& h_painting, const std::string& current_map_name, const std::string& current_room_name) { uint64_t painting_id = container_.FindOrAddPainting( current_map_name, current_room_name, h_painting.name(), std::nullopt, std::nullopt); Painting& painting = *container_.all_objects().mutable_paintings(painting_id); painting.set_path(h_painting.path()); painting.set_display_name(h_painting.display_name()); painting.set_orientation(h_painting.orientation()); if (h_painting.has_flipped()) { painting.set_flipped(h_painting.flipped()); } if (h_painting.has_move()) { painting.set_move(h_painting.move()); } if (h_painting.has_enter_only()) { painting.set_enter_only(h_painting.enter_only()); } if (h_painting.has_required_door()) { std::optional map_name = h_painting.required_door().has_map() ? std::optional(h_painting.required_door().map()) : std::nullopt; painting.set_required_door(container_.FindOrAddDoor( map_name, h_painting.required_door().name(), current_map_name)); } return painting_id; } uint64_t ProcessPort(const HumanPort& h_port, const std::string& current_map_name, const std::string& current_room_name) { uint64_t port_id = container_.FindOrAddPort(current_map_name, current_room_name, h_port.name(), std::nullopt, std::nullopt); Port& port = *container_.all_objects().mutable_ports(port_id); port.set_path(h_port.path()); port.set_orientation(h_port.orientation()); if (h_port.has_required_door()) { std::optional map_name = h_port.required_door().has_map() ? std::optional(h_port.required_door().map()) : std::nullopt; port.set_required_door(container_.FindOrAddDoor( map_name, h_port.required_door().name(), current_map_name)); } return port_id; } void ProcessDoorsFile(std::filesystem::path path, const std::string& current_map_name) { if (!std::filesystem::exists(path)) { return; } auto doors = ReadMessageFromFile(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) { uint64_t door_id = container_.FindOrAddDoor(current_map_name, h_door.name(), std::nullopt); Door& door = *container_.all_objects().mutable_doors(door_id); if (h_door.has_location_room()) { door.set_room_id(container_.FindOrAddRoom( current_map_name, h_door.location_room(), std::nullopt)); Room& room = *container_.all_objects().mutable_rooms(door.room_id()); room.add_doors(door_id); } std::copy( h_door.receivers().begin(), h_door.receivers().end(), google::protobuf::RepeatedFieldBackInserter(door.mutable_receivers())); std::copy( h_door.switches().begin(), h_door.switches().end(), google::protobuf::RepeatedFieldBackInserter(door.mutable_switches())); for (const PaintingIdentifier& pi : h_door.move_paintings()) { std::optional map_name = pi.has_map() ? std::optional(pi.map()) : std::nullopt; door.add_move_paintings(container_.FindOrAddPainting( map_name, pi.room(), pi.name(), current_map_name, std::nullopt)); } for (const PanelIdentifier& pi : h_door.panels()) { ProxyIdentifier* proxy = door.add_panels(); std::optional map_name = pi.has_map() ? std::optional(pi.map()) : std::nullopt; proxy->set_panel(container_.FindOrAddPanel( map_name, pi.room(), pi.name(), current_map_name, std::nullopt)); if (pi.has_answer()) { proxy->set_answer(pi.answer()); } } if (h_door.has_control_center_color()) { door.set_control_center_color(h_door.control_center_color()); } door.set_type(h_door.type()); } void ProcessConnectionsFile(std::filesystem::path path, std::optional current_map_name) { if (!std::filesystem::exists(path)) { return; } auto connections = ReadMessageFromFile(path.string()); for (const HumanConnection& connection : connections.connections()) { ProcessConnection(connection, current_map_name); } } void ProcessConnection(const HumanConnection& human_connection, const std::optional& current_map_name) { Connection f_connection; if (human_connection.has_from_room()) { f_connection.set_from_room(container_.FindOrAddRoom( std::nullopt, human_connection.from_room(), current_map_name)); } else if (human_connection.has_from()) { ProcessSingleConnection(human_connection.from(), current_map_name, f_connection); } Connection r_connection; r_connection.set_to_room(f_connection.from_room()); if (human_connection.has_to_room()) { r_connection.set_from_room(container_.FindOrAddRoom( std::nullopt, human_connection.to_room(), current_map_name)); } else if (human_connection.has_to()) { ProcessSingleConnection(human_connection.to(), current_map_name, r_connection); } f_connection.set_to_room(r_connection.from_room()); if (human_connection.has_door()) { std::optional map_name = human_connection.door().has_map() ? std::optional(human_connection.door().map()) : std::nullopt; uint64_t door_id = container_.FindOrAddDoor( map_name, human_connection.door().name(), current_map_name); f_connection.set_required_door(door_id); r_connection.set_required_door(door_id); } container_.AddConnection(f_connection); if (!human_connection.oneway()) { container_.AddConnection(r_connection); } } void ProcessSingleConnection( const HumanConnection::Endpoint& endpoint, const std::optional& current_map_name, Connection& connection) { if (endpoint.has_room()) { std::optional map_name = endpoint.room().has_map() ? std::optional(endpoint.room().map()) : std::nullopt; connection.set_from_room(container_.FindOrAddRoom( map_name, endpoint.room().name(), current_map_name)); } else if (endpoint.has_painting()) { std::optional map_name = endpoint.painting().has_map() ? std::optional(endpoint.painting().map()) : std::nullopt; std::string room_name; if (!endpoint.painting().has_room()) { std::cout << "Missing room name for painting " << endpoint.painting().name() << std::endl; room_name = "default"; } else { room_name = endpoint.painting().room(); } connection.set_from_room( container_.FindOrAddRoom(map_name, room_name, current_map_name)); connection.set_painting(container_.FindOrAddPainting( map_name, room_name, endpoint.painting().name(), current_map_name, std::nullopt)); } else if (endpoint.has_port()) { std::optional map_name = endpoint.port().has_map() ? std::optional(endpoint.port().map()) : std::nullopt; std::string room_name; if (!endpoint.port().has_room()) { std::cout << "Missing room name for port " << endpoint.port().name() << std::endl; room_name = "default"; } else { room_name = endpoint.port().room(); } connection.set_from_room( container_.FindOrAddRoom(map_name, room_name, current_map_name)); connection.set_port( container_.FindOrAddPort(map_name, room_name, endpoint.port().name(), current_map_name, std::nullopt)); } else if (endpoint.has_panel()) { std::optional map_name = endpoint.panel().has_map() ? std::optional(endpoint.panel().map()) : std::nullopt; std::string room_name; if (!endpoint.panel().has_room()) { std::cout << "Missing room name for panel " << endpoint.panel().name() << std::endl; room_name = "default"; } else { room_name = endpoint.panel().room(); } connection.set_from_room( container_.FindOrAddRoom(map_name, room_name, current_map_name)); connection.mutable_panel()->set_panel(container_.FindOrAddPanel( map_name, room_name, endpoint.panel().name(), current_map_name, std::nullopt)); if (endpoint.panel().has_answer()) { connection.mutable_panel()->set_answer(endpoint.panel().answer()); } } } void ProcessIdsFile(std::filesystem::path path) { auto ids = ReadMessageFromFile(path.string()); for (const auto& [map_name, map] : ids.maps()) { for (const auto& [door_name, ap_id] : map.doors()) { uint64_t door_id = container_.FindOrAddDoor(map_name, door_name, std::nullopt); container_.all_objects().mutable_doors(door_id)->set_ap_id(ap_id); } for (const auto& [room_name, room] : map.rooms()) { for (const auto& [panel_name, ap_id] : room.panels()) { uint64_t panel_id = container_.FindOrAddPanel( map_name, room_name, panel_name, std::nullopt, std::nullopt); container_.all_objects().mutable_panels(panel_id)->set_ap_id(ap_id); } } } auto& specials = *container_.all_objects().mutable_special_ids(); for (const auto& [tag, id] : ids.special()) { specials[tag] = id; } } std::string mapdir_; std::string outputpath_; Container container_; }; } // namespace } // namespace com::fourisland::lingo2_archipelago int main(int argc, char** argv) { if (argc != 3) { std::cout << "Incorrect argument count." << std::endl; std::cout << "Usage: datapacker [path to map directory] [output file]" << std::endl; return 1; } std::string mapdir = argv[1]; std::string outputpath = argv[2]; com::fourisland::lingo2_archipelago::DataPacker data_packer(mapdir, outputpath); data_packer.Run(); return 0; } 70' href='#n370'>370 371 372 373 374 375 376 377 378 379 380
GIT
  remote: https://github.com/hatkirby/lingo.git
  revision: d60d1ca4c2c602b674ab9559a4a29907220d9c45
  branch: main
  glob: rails/*.gemspec
  specs:
    lingo (0.1.0)
      haml-rails (~> 2.0)
      rails (>= 7.0.3)
      sassc-rails

GIT
  remote: https://github.com/hatkirby/pokeviewer.git
  revision: e28f6b73ab7f2e59605ebd800e921a6146fc49ae
  specs:
    pokeviewer (0.1.0)
      activerecord-diff
      coffee-rails (~> 4.2)
      enumerize
      haml
      jquery-rails
      normalize-rails
      rails (~> 7.0.3)
      sassc-rails
      sequenced
      victor

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (7.0.4)
      actionpack (= 7.0.4)
      activesupport (= 7.0.4)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailbox (7.0.4)
      actionpack (= 7.0.4)
      activejob (= 7.0.4)
      activerecord (= 7.0.4)
      activestorage (= 7.0.4)
      activesupport (= 7.0.4)
      mail (>= 2.7.1)
      net-imap
      net-pop
      net-smtp
    actionmailer (7.0.4)
      actionpack (= 7.0.4)
      actionview (= 7.0.4)
      activejob (= 7.0.4)
      activesupport (= 7.0.4)
      mail (~> 2.5, >= 2.5.4)
      net-imap
      net-pop
      net-smtp
      rails-dom-testing (~> 2.0)
    actionpack (7.0.4)
      actionview (= 7.0.4)
      activesupport (= 7.0.4)
      rack (~> 2.0, >= 2.2.0)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.2.0)
    actiontext (7.0.4)
      actionpack (= 7.0.4)
      activerecord (= 7.0.4)
      activestorage (= 7.0.4)
      activesupport (= 7.0.4)
      globalid (>= 0.6.0)
      nokogiri (>= 1.8.5)
    actionview (7.0.4)
      activesupport (= 7.0.4)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.1, >= 1.2.0)
    activejob (7.0.4)
      activesupport (= 7.0.4)
      globalid (>= 0.3.6)
    activemodel (7.0.4)
      activesupport (= 7.0.4)
    activerecord (7.0.4)
      activemodel (= 7.0.4)
      activesupport (= 7.0.4)
    activerecord-diff (2.0.0)
    activestorage (7.0.4)
      actionpack (= 7.0.4)
      activejob (= 7.0.4)
      activerecord (= 7.0.4)
      activesupport (= 7.0.4)
      marcel (~> 1.0)
      mini_mime (>= 1.1.0)
    activesupport (7.0.4)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 1.6, < 2)
      minitest (>= 5.1)
      tzinfo (~> 2.0)
    acts-as-taggable-on (9.0.1)
      activerecord (>= 6.0, < 7.1)
    addressable (2.8.1)
      public_suffix (>= 2.0.2, < 6.0)
    airbrussh (1.4.1)
      sshkit (>= 1.6.1, != 1.7.0)
    audited (5.0.2)
      activerecord (>= 5.0, < 7.1)
    bcrypt (3.1.18)
    bindex (0.8.1)
    builder (3.2.4)
    byebug (11.1.3)
    capistrano (3.17.1)
      airbrussh (>= 1.0.0)
      i18n
      rake (>= 10.0.0)
      sshkit (>= 1.9.0)
    capistrano-bundler (2.1.0)
      capistrano (~> 3.1)
    capistrano-passenger (0.2.1)
      capistrano (~> 3.0)
    capistrano-rails (1.6.2)
      capistrano (~> 3.1)
      capistrano-bundler (>= 1.1, < 3)
    capistrano-rvm (0.1.2)
      capistrano (~> 3.0)
      sshkit (~> 1.2)
    capybara (2.18.0)
      addressable
      mini_mime (>= 0.1.3)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (>= 2.0, < 4.0)
    ckeditor (4.2.4)
      cocaine
      orm_adapter (~> 0.5.0)
    climate_control (0.2.0)
    cocaine (0.6.0)
      terrapin (= 0.6.0)
    coffee-rails (4.2.2)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.12.2)
    concurrent-ruby (1.1.10)
    crass (1.0.6)
    date (3.3.1)
    devise (4.8.1)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 4.1.0)
      responders
      warden (~> 1.2.3)
    enumerize (2.5.0)
      activesupport (>= 3.2)
    erubi (1.11.0)
    execjs (2.8.1)
    ffi (1.15.5)
    globalid (1.0.0)
      activesupport (>= 5.0)
    haml (6.1.1)
      temple (>= 0.8.2)
      thor
      tilt
    haml-rails (2.1.0)
      actionpack (>= 5.1)
      activesupport (>= 5.1)
      haml (>= 4.0.6)
      railties (>= 5.1)
    highline (2.0.3)
    i18n (1.12.0)
      concurrent-ruby (~> 1.0)
    jbuilder (2.11.5)
      actionview (>= 5.0.0)
      activesupport (>= 5.0.0)
    jquery-rails (4.5.1)
      rails-dom-testing (>= 1, < 3)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    jquery-ui-rails (6.0.1)
      railties (>= 3.2.16)
    js-routes (2.2.4)
      railties (>= 4)
    libv8 (3.16.14.19)
    listen (3.0.8)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
    loofah (2.19.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.8.0)
      mini_mime (>= 0.1.1)
      net-imap
      net-pop
      net-smtp
    marcel (1.0.2)
    method_source (1.0.0)
    mime-types (3.4.1)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2022.0105)
    mimemagic (0.3.10)
      nokogiri (~> 1)
      rake
    mini_mime (1.1.2)
    mini_portile2 (2.8.0)
    minitest (5.16.3)
    mysql2 (0.5.4)
    net-imap (0.3.2)
      date
      net-protocol
    net-pop (0.1.2)
      net-protocol
    net-protocol (0.2.1)
      timeout
    net-scp (4.0.0)
      net-ssh (>= 2.6.5, < 8.0.0)
    net-smtp (0.3.3)
      net-protocol
    net-ssh (7.0.1)
    nio4r (2.5.8)
    nokogiri (1.13.10)
      mini_portile2 (~> 2.8.0)
      racc (~> 1.4)
    normalize-rails (8.0.1)
    orm_adapter (0.5.0)
    paperclip (6.1.0)
      activemodel (>= 4.2.0)
      activesupport (>= 4.2.0)
      mime-types
      mimemagic (~> 0.3.0)
      terrapin (~> 0.6.0)
    public_suffix (5.0.1)
    racc (1.6.1)
    rack (2.2.4)
    rack-test (2.0.2)
      rack (>= 1.3)
    rails (7.0.4)
      actioncable (= 7.0.4)
      actionmailbox (= 7.0.4)
      actionmailer (= 7.0.4)
      actionpack (= 7.0.4)
      actiontext (= 7.0.4)
      actionview (= 7.0.4)
      activejob (= 7.0.4)
      activemodel (= 7.0.4)
      activerecord (= 7.0.4)
      activestorage (= 7.0.4)
      activesupport (= 7.0.4)
      bundler (>= 1.15.0)
      railties (= 7.0.4)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.4.3)
      loofah (~> 2.3)
    railties (7.0.4)
      actionpack (= 7.0.4)
      activesupport (= 7.0.4)
      method_source
      rake (>= 12.2)
      thor (~> 1.0)
      zeitwerk (~> 2.5)
    rake (13.0.6)
    rb-fsevent (0.11.2)
    rb-inotify (0.10.1)
      ffi (~> 1.0)
    ref (2.0.0)
    responders (3.0.1)
      actionpack (>= 5.0)
      railties (>= 5.0)
    rexml (3.2.5)
    rubyzip (2.3.2)
    sassc (2.4.0)
      ffi (~> 1.9)
    sassc-rails (2.1.2)
      railties (>= 4.0.0)
      sassc (>= 2.0)
      sprockets (> 3.0)
      sprockets-rails
      tilt
    selenium-webdriver (4.7.1)
      rexml (~> 3.2, >= 3.2.5)
      rubyzip (>= 1.2.2, < 3.0)
      websocket (~> 1.0)
    sequenced (4.0.0)
      activerecord (>= 3.0)
      activesupport (>= 3.0)
    spring (2.1.1)
    spring-watcher-listen (2.0.1)
      listen (>= 2.7, < 4.0)
      spring (>= 1.2, < 3.0)
    sprockets (3.7.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.4.2)
      actionpack (>= 5.2)
      activesupport (>= 5.2)
      sprockets (>= 3.0.0)
    sqlite3 (1.5.4)
      mini_portile2 (~> 2.8.0)
    sshkit (1.21.3)
      net-scp (>= 1.1.2)
      net-ssh (>= 2.8.0)
    temple (0.9.1)
    terrapin (0.6.0)
      climate_control (>= 0.0.3, < 1.0)
    therubyracer (0.12.3)
      libv8 (~> 3.16.14.15)
      ref
    thor (1.2.1)
    tilt (2.0.11)
    timeout (0.3.1)
    turbolinks (5.2.1)
      turbolinks-source (~> 5.2)
    turbolinks-source (5.2.0)
    tzinfo (2.0.5)
      concurrent-ruby (~> 1.0)
    uglifier (4.2.0)
      execjs (>= 0.3.0, < 3)
    victor (0.3.4)
    warden (1.2.9)
      rack (>= 2.0.9)
    web-console (4.2.0)
      actionview (>= 6.0.0)
      activemodel (>= 6.0.0)
      bindex (>= 0.4.0)
      railties (>= 6.0.0)
    webrick (1.7.0)
    websocket (1.2.9)
    websocket-driver (0.7.5)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    xpath (3.2.0)
      nokogiri (~> 1.8)
    zeitwerk (2.6.6)

PLATFORMS
  ruby

DEPENDENCIES
  acts-as-taggable-on
  audited (~> 5.0)
  byebug
  capistrano (~> 3.0)
  capistrano-bundler
  capistrano-passenger
  capistrano-rails
  capistrano-rvm
  capybara (~> 2.13)
  ckeditor (~> 4.2.4)
  coffee-rails (~> 4.2)
  devise
  enumerize
  haml
  highline
  jbuilder (~> 2.5)
  jquery-rails
  jquery-ui-rails
  js-routes
  lingo!
  listen (>= 3.0.5, < 3.2)
  mysql2
  normalize-rails
  paperclip
  pokeviewer!
  rails (~> 7.0.3)
  sassc-rails
  selenium-webdriver
  spring
  spring-watcher-listen (~> 2.0.0)
  sprockets (= 3.7.2)
  sqlite3
  therubyracer
  turbolinks (~> 5)
  tzinfo-data
  uglifier (>= 1.3.0)
  web-console (>= 3.3.0)
  webrick (~> 1.7)

BUNDLED WITH
   2.2.3