diff --git a/Gemfile b/Gemfile index 198b7d8..3bdd24e 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem "importmap-rails" gem "turbo-rails" gem "stimulus-rails" gem "jbuilder" -gem "toml-rb" +gem "tomlrb" gem "nanoid" gem "spicy-proton" diff --git a/Gemfile.lock b/Gemfile.lock index 5db998e..1b3aad3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,7 +94,6 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - citrus (3.0.2) concurrent-ruby (1.3.5) connection_pool (2.5.0) crass (1.0.6) @@ -299,9 +298,7 @@ GEM thruster (0.1.12-x86_64-darwin) thruster (0.1.12-x86_64-linux) timeout (0.4.3) - toml-rb (3.0.1) - citrus (~> 3.0, > 3.0) - racc (~> 1.7) + tomlrb (2.0.3) turbo-rails (2.0.13) actionpack (>= 7.1.0) railties (>= 7.1.0) @@ -358,7 +355,7 @@ DEPENDENCIES spicy-proton stimulus-rails thruster - toml-rb + tomlrb turbo-rails tzinfo-data web-console diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 92566ae..c2f4c80 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -29,6 +29,11 @@ header .muted { font-weight: normal; } +main { + display: grid; + grid-template-columns: 5fr 1fr; +} + .new-buttons { display: flex; gap: 5px; @@ -169,3 +174,26 @@ span#password { .copyable:hover { cursor: pointer; } + +.sidebar { + display: flex; + flex-direction: column; + align-items: center; + margin: 10px 0; +} + +.weather-list { + display: flex; + align-items: center; + gap: 3px; +} + +.weather { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + font-size: 12px; + color: #555; +} + diff --git a/app/javascript/application.js b/app/javascript/application.js index de6bf57..165bdb5 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1,8 +1,2 @@ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import "htmx.org" -import htmx from "htmx.org" -htmx.logger = function(elt, event, data) { - if(console) { - console.log(event, elt, data); - } -} diff --git a/app/views/instance/_list.html.erb b/app/views/instance/_list.html.erb index 6c30549..c506db9 100644 --- a/app/views/instance/_list.html.erb +++ b/app/views/instance/_list.html.erb @@ -1,4 +1,4 @@ -
+
<% APP_DATA[instance.zone.to_sym][:nms].each do |nm| %> <% is_popped = instance.pops.filter { |pop| (Time.current - 120.minutes) <= pop.created_at }.any? { |pop| pop.name == nm[:name].parameterize } %>
@@ -10,7 +10,7 @@ LV<%= nm[:level].to_s.rjust(2, "0") %> <%= nm[:name] %> <% if nm[:weather] %> - + <% end %>
@@ -20,7 +20,7 @@ ๐ŸŒ™ <% end %> <% if nm[:spawned_by][:weather] %> - + <% end %> LV<%= nm[:spawned_by][:level].to_s.rjust(2, "0") %>
@@ -52,4 +52,4 @@
<% end %> -
+ diff --git a/app/views/instance/show.html.erb b/app/views/instance/show.html.erb index 9673813..acdc8d7 100644 --- a/app/views/instance/show.html.erb +++ b/app/views/instance/show.html.erb @@ -22,7 +22,26 @@ - <%= render partial: "list", locals: { instance: @instance } %> +
+ <%= render partial: "list", locals: { instance: @instance } %> + + +
<%= javascript_include_tag "list" %> diff --git a/config/initializers/data.rb b/config/initializers/data.rb index e534c94..fedf8a3 100644 --- a/config/initializers/data.rb +++ b/config/initializers/data.rb @@ -1,5 +1,11 @@ -anemos_data = TomlRB.load_file("./data/anemos.toml", symbolize_keys: true) +anemos_data = Tomlrb.load_file("./data/anemos.toml", symbolize_keys: true) +pagos_data = Tomlrb.load_file("./data/pagos.toml", symbolize_keys: true) +pyros_data = Tomlrb.load_file("./data/pyros.toml", symbolize_keys: true) +hydatos_data = Tomlrb.load_file("./data/hydatos.toml", symbolize_keys: true) APP_DATA = { - anemos: anemos_data + anemos: anemos_data, + pagos: pagos_data, + pyros: pyros_data, + hydatos: hydatos_data } diff --git a/data/anemos.toml b/data/anemos.toml index 19dfaa8..dad6b0a 100644 --- a/data/anemos.toml +++ b/data/anemos.toml @@ -1,3 +1,10 @@ +weather = [ + ["fair", 30], + ["gales", 30], + ["showers", 30], + ["snow", 10] +] + [[nms]] name = "Sabotender Corrido" level = 1 diff --git a/data/hydatos.toml b/data/hydatos.toml new file mode 100644 index 0000000..bc61492 --- /dev/null +++ b/data/hydatos.toml @@ -0,0 +1,7 @@ +weather = [ + ["fair", 12], + ["showers", 22], + ["gloom", 22], + ["thunder", 22], + ["snow", 22] +] diff --git a/data/pagos.toml b/data/pagos.toml new file mode 100644 index 0000000..fff082c --- /dev/null +++ b/data/pagos.toml @@ -0,0 +1,8 @@ +weather = [ + ["fair", 10], + ["fog", 18], + ["heat", 18], + ["snow", 18], + ["thunder", 18], + ["blizzards", 18] +] diff --git a/data/pyros.toml b/data/pyros.toml new file mode 100644 index 0000000..930ec6d --- /dev/null +++ b/data/pyros.toml @@ -0,0 +1,8 @@ +weather = [ + ["fair", 10], + ["heat", 18], + ["thunder", 18], + ["blizzards", 18], + ["umbral_wind", 18], + ["snow", 18] +] diff --git a/lib/clock.rb b/lib/clock.rb new file mode 100644 index 0000000..b4c548c --- /dev/null +++ b/lib/clock.rb @@ -0,0 +1,24 @@ +class Clock + EARTH_TO_EORZEA = 3600.0 / 175.0 + EORZEA_TO_EARTH = 1.0 / EARTH_TO_EORZEA + + def self.get_current_eorzea_time + to_eorzea_time(Time.now.utc) + end + + def self.to_eorzea_time(earth_time) + et_ts = earth_time.to_i + new_ts = et_ts.abs * EARTH_TO_EORZEA + Time.at(new_ts) + end + + def self.to_earth_time(ez_time) + ez_ts = ez_time.to_i + new_ts = (ez_ts * EORZEA_TO_EARTH).ceil + Time.at(new_ts) + end + + def self.display_ez_time(ez_time) + ez_time.strftime("%H:%M") + end +end diff --git a/lib/weather.rb b/lib/weather.rb new file mode 100644 index 0000000..c09fe84 --- /dev/null +++ b/lib/weather.rb @@ -0,0 +1,64 @@ +class Weather + def self.get_weather(zone, hash = hash(get_seed)) + total = 0 + APP_DATA[zone][:weather].each do |arr| + name, rate = arr + if (total += rate) > hash + return name + end + end + end + + def self.forecast(zone, seed = get_seed, count = 10) + res = [] + prev_hash = hash(seed - 1) + prev_weather = get_weather(zone, prev_hash) + count.times do |_| + curr_hash = hash(seed) + curr_weather = get_weather(zone, curr_hash) + res.push({ zone: zone, prev_weather: prev_weather, curr_weather: curr_weather, weather_name: get_weather_name(curr_weather), seed: seed, time: Time.at(seed * 1400000.0 / 1000) }) + prev_hash = curr_hash + prev_weather = curr_weather + seed += 1 + end + res + end + + def self.round_to_last_weather_time(time) + last_hour = time.hour / 8 * 8 + time.change(hour: last_hour) + end + + def self.get_weather_name(name) + case name + when "fair" then "Fair Skies" + when "showers" then "Showers" + when "gales" then "Gales" + when "blizzards" then "Blizzards" + when "heat" then "Heat" + when "thunder" then "Thunderstorms" + when "gloom" then "Gloom" + when "snow" then "Snow" + when "fog" then "Fog" + when "umbral_wind" then "Umbral Wind" + else "Unknown Weather" + end + end + + + def self.get_seed + (Time.now.utc.to_i * 1000 / 1400000.0).floor + end + + def self.hash(seed = get_seed) + base = (seed / 3).floor * 100 + ((seed + 1) % 3) * 8 + # Ruby has no other convenient way to convert a signed integer into an unsigned one + step1 = [ ((base << 11) ^ base) ].pack("L").unpack("L").first + step2 = [ (([ (step1 >> 8) ].pack("L").unpack("L").first.to_i ^ step1)) ].pack("L").unpack("L").first.to_i + step2 % 100 + end + + def self.unsigned_right(input, by) + input << by & 0xFF00 | input >> by & 0xFF + end +end diff --git a/public/weather/fair.png b/public/weather/fair.png new file mode 100644 index 0000000..cf66767 Binary files /dev/null and b/public/weather/fair.png differ diff --git a/public/weather/fog.png b/public/weather/fog.png new file mode 100644 index 0000000..870ff88 Binary files /dev/null and b/public/weather/fog.png differ diff --git a/public/gales.png b/public/weather/gales.png similarity index 100% rename from public/gales.png rename to public/weather/gales.png diff --git a/public/weather/showers.png b/public/weather/showers.png new file mode 100644 index 0000000..d145962 Binary files /dev/null and b/public/weather/showers.png differ diff --git a/public/weather/snow.png b/public/weather/snow.png new file mode 100644 index 0000000..18f6f32 Binary files /dev/null and b/public/weather/snow.png differ diff --git a/public/weather/thunder.png b/public/weather/thunder.png new file mode 100644 index 0000000..fae1932 Binary files /dev/null and b/public/weather/thunder.png differ diff --git a/public/weather/umbral_wind.png b/public/weather/umbral_wind.png new file mode 100644 index 0000000..83d3ee6 Binary files /dev/null and b/public/weather/umbral_wind.png differ