about summary refs log tree commit diff stats
path: root/tools/util/godot_scene.h
blob: 17f3f508edc1189b279fe228d6bbe575e1dba7fe (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
#ifndef TOOLS_UTIL_TSCN_H_
#define TOOLS_UTIL_TSCN_H_

#include <map>
#include <memory>
#include <string>
#include <utility>
#include <variant>
#include <vector>

namespace com::fourisland::lingo2_archipelago {

struct GodotExtResource {
  std::string type;
  std::string path;
};

struct GodotExtResourceRef {
  std::string id;
};

using GodotInstanceType = std::variant<std::monostate, GodotExtResourceRef>;

struct GodotNode {
  std::string name;
  std::string parent;
  GodotInstanceType instance_type;

  std::string GetPath() const;
};

class GodotScene {
 public:
  GodotScene(std::map<std::string, GodotExtResource> ext_resources,
             std::vector<GodotNode> nodes)
      : ext_resources_(std::move(ext_resources)), nodes_(std::move(nodes)) {}

  const GodotExtResource* GetExtResource(const std::string& id) const {
    auto it = ext_resources_.find(id);
    if (it != ext_resources_.end()) {
      return &it->second;
    } else {
      return nullptr;
    }
  }
  const std::vector<GodotNode>& GetNodes() const { return nodes_; }

 private:
  std::map<std::string, GodotExtResource> ext_resources_;
  std::vector<GodotNode> nodes_;
};

GodotScene ReadGodotSceneFromFile(const std::string& path);

}  // namespace com::fourisland::lingo2_archipelago

#endif /* TOOLS_UTIL_TSCN_H_ */
_to_one :game many_to_many :profiles, join_table: :dids end class Image < Sequel::Model many_to_one :game end class Did < Sequel::Model many_to_one :profile many_to_one :achievement end def scrape_profile(profile, full) if full url = "https://steamcommunity.com/#{profile.profile_path}/games/?tab=all" else url = "https://steamcommunity.com/#{profile.profile_path}/games/" end page = Nokogiri::HTML(open(url)) script = page.css(".responsive_page_template_content script").text[18..-1] data = JSON.parse(script[0..script.index(";\r\n\t\t")-1]) ids = data.map { |d| d["appid"] } index = 0 ids.each do |id| index += 1 puts "#{profile.profile_path} - #{index}/#{ids.count}" achsp = Nokogiri::HTML( open("https://steamcommunity.com/#{profile.profile_path}/stats/#{id}/")) achsp.css(".achieveTxt").each do |node| unless node.css(".achieveUnlockTime").empty? if Game.where(steam_appid: id).count > 0 game = Game.where(steam_appid: id).first else moon_index = Random.rand(MOON_COLORS.size) game = Game.new(steam_appid: id, color: MOON_COLORS[moon_index]) game.save # The cookie is required for games that have an age restriction storepage = Nokogiri::HTML( open( "http://store.steampowered.com/app/#{id}", "Cookie" => 'birthtime=126248401')) img_id = 0 storepage.css(".highlight_screenshot_link").each do |node| begin imagepage = open(node["href"]).read img_id += 1 img_filename = "#{id}-#{img_id}.jpg" img_filepath = File.join(@config["images"], img_filename) img_file = File.open(img_filepath, "w") img_file.write(imagepage) img_file.close image = Image.new(game: game, filename: img_filename) image.save rescue OpenURI::HTTPError puts "Error downloading an image" end sleep 2 end end title = node.at_css("h3").text if game.achievements_dataset.where(title: title).count > 0 achievement = game.achievements_dataset.where(title: title).first else achievement = Achievement.new(game: game, title: title) achievement.save end unless Did.where(profile: profile, achievement: achievement).count > 0 begin unlock = DateTime.strptime( node.css(".achieveUnlockTime").text.lstrip[9..-1], "%b %d, %Y @ %l:%M%P") rescue ArgumentError unlock = DateTime.strptime( node.css(".achieveUnlockTime").text.lstrip[9..-1], "%b %d @ %l:%M%P") end join = Did.new( profile: profile, achievement: achievement, achieved_at: unlock) join.save end end end end end if ARGV[1] == "add" userpath = ARGV[2] if Profile.where(profile_path: userpath).count > 0 raise "Profile " + userpath + " already exists" end profile = Profile.new(profile_path: userpath) profile.save scrape_profile profile, true elsif ARGV[1] == "update" if ARGV.size == 3 scrape_profile Profile.where(profile_path: ARGV[2]).first, false else Profile.all.each do |profile| scrape_profile profile, false end end elsif ARGV[1] == "full" if ARGV.size == 3 scrape_profile Profile.where(profile_path: ARGV[2]).first, true else Profile.all.each do |profile| scrape_profile profile, true end end elsif ARGV[1] == "recolor" Game.all.each do |game| moon_index = Random.rand(MOON_COLORS.size) game.color = MOON_COLORS[moon_index] game.save end end