feat: add sprite spawns

This commit is contained in:
insects 2025-03-13 14:36:23 +01:00
parent 0581c53454
commit ca352fc531
13 changed files with 379 additions and 13 deletions

View file

@ -0,0 +1,63 @@
<h3>Challenge log</h3>
<div class="sprite-list">
<% Bestiary.get_sprites_for_zone(instance.zone).each do |sprite| %>
<% is_spawning = forecast[0][:curr_weather].in?(sprite[:weather]) %>
<div class="sprite">
<div class="sprite-name">
<img src="/<%= sprite[:element] %>.png" width="15" style="margin-top: -3px;" />
<%= sprite[:name] %>
</div>
<% if is_spawning %>
<div class="spawning">is spawning!</div>
<% else %>
<% next_pattern = forecast.find { |f| f[:curr_weather].in?(sprite[:weather]) } %>
<div class="not-spawning">spawns in
<% if next_pattern.nil? %>
>300m
<% else %>
<%= ((next_pattern[:time] - Time.now.utc) / 1.minutes).ceil %>m
<% end %>
</div>
<% end %>
</div>
<% if is_spawning %>
<div class="sprite-levels">
<% sprite[:sprite_levels].each do |lvl| %>
<div>
<div style="display: flex; gap: 3px;">
<div>lv<%= lvl[:lv] %></div>
<div>
<% if lvl[:mutates] %>
<img src="/mutation.png" width="13" />
<% elsif lvl[:adapts] %>
<img src="/adaptation.png" width="13" />
<% end %>
</div>
</div>
~<%= lvl[:mx] %>/<%= lvl[:my] %>
</div>
<% end %>
</div>
<details class="sprite-map">
<summary>
show map
</summary>
<div style="position: relative;">
<img src="/maps/<%= sprite[:zone] %>_fw.jpg" style="width: 100%; position: relative;" />
<% sprite[:sprite_levels].each do |lvl| %>
<div
title="LV<%= lvl[:lv] %>"
style="line-height: 10px; position: absolute; left: <%= (lvl[:mx] / 42) * 100.0 - 2.0 %>%; top: <%= (lvl[:my] / 42) * 100.0 - 2.5 %>%"
>
&bullet;
<br/>
<small>LV<%= lvl[:lv] %></small>
</div>
<% end %>
</div>
</details>
<% end %>
<% end %>
</div>

View file

@ -34,7 +34,7 @@
<% pop = instance.pops.find { |pop| pop.name == nm[:name].parameterize } %>
<% mins = ActiveSupport::Duration.build(Time.current - pop.created_at) %>
<div class="timer">
<div>» <%= (120.minutes - mins).in_minutes.floor %>m</div>
<div>» <%= (120.minutes - mins).in_minutes.ceil %>m</div>
<div class="progress-container">
<span class="progress-bar" style="width: <%= (mins.in_minutes / 120) * 100 %>%"></span>
</div>
@ -55,14 +55,14 @@
<% end %>
<% if nm[:weather] && forecast[0][:curr_weather] != nm[:weather] %>
<% next_pattern = forecast.find { |f| f[:curr_weather] == nm[:weather] } %>
<%= Weather.get_weather_name(nm[:weather]) %> in <%= ((next_pattern[:time] - Time.now.utc) / 1.minutes).floor %>m
<%= Weather.get_weather_name(nm[:weather]) %> in <%= ((next_pattern[:time] - Time.now.utc) / 1.minutes).ceil %>m
<% end %>
<% if nm[:spawned_by][:weather] && forecast[0][:curr_weather] != nm[:spawned_by][:weather] %>
<% next_pattern = forecast.find { |f| f[:curr_weather] == nm[:spawned_by][:weather] } %>
<%= Weather.get_weather_name(nm[:spawned_by][:weather]) %> in <%= ((next_pattern[:time] - Time.now.utc) / 1.minutes).floor %>m
<%= Weather.get_weather_name(nm[:spawned_by][:weather]) %> in <%= ((next_pattern[:time] - Time.now.utc) / 1.minutes).ceil %>m
<% end %>
<% if (nm[:night_only] || nm[:spawned_by][:night_only]) && is_day? %>
<div>Night in <%= ((Clock.to_earth_time(Clock.get_current_eorzea_time.change(hour: 18)) - Time.now.utc) / 1.minutes).floor %>m</div>
Night in <%= ((Clock.to_earth_time(Clock.get_current_eorzea_time.change(hour: 18)) - Time.now.utc) / 1.minutes).ceil %>m
<% end %>
</div>
</div>
@ -87,4 +87,12 @@
</div>
</section>
<% end %>
<a href="/maps/<%= @instance.zone %>_full.jpg" target="_blank">
<button>full map (new tab)</button>
</a>
<%= form_with url: clone_instance_path(instance: @instance.public_id), html: { style: "display: inline-block;" } do |f| %>
<%= f.submit "clone instance" %>
<% end %>
</div>

View file

@ -1,5 +1,5 @@
<div id="public_id" data-content="<%= @instance.public_id %>"></div>
<div hx-get="" hx-trigger="every 5m" hx-swap="outerHTML" hx-select="#container" hx-target="#container">
<div hx-get="" hx-trigger="<%= Rails.env == "development" ? "every 5m" : "every 5s" %>" hx-swap="outerHTML" hx-select="#container" hx-target="#container">
<header>
<div class="title">
<%= link_to root_path do %><img src="/icon.png" width="50" alt="eureka.coffee logo" /><% end %>
@ -36,13 +36,14 @@
»
<div class="weather">
<img src="/weather/<%= @forecast[i + 1][:curr_weather] %>.png" width="25" title="<%= @forecast[i + 1][:weather_name] %>" />
<div><%= ((@forecast[i + 1][:time] - Time.now.utc) / 1.minutes).floor %>m</div>
<div><%= ((@forecast[i + 1][:time] - Time.now.utc) / 1.minutes).ceil %>m</div>
</div>
<% end %>
</div>
<div>
<%= render partial: "fairies", locals: { instance: @instance } %>
<%= render partial: "chlog", locals: { instance: @instance, forecast: @forecast } %>
</div>
</div>
</main>
@ -50,9 +51,3 @@
<%= javascript_include_tag "list" %>
</div>
<a href="/maps/<%= @instance.zone %>_full.jpg" target="_blank">
<button>full map (new tab)</button>
</a>
<%= form_with url: clone_instance_path(instance: @instance.public_id), html: { style: "display: inline-block;" } do |f| %>
<%= f.submit "clone instance" %>
<% end %>