summaryrefslogtreecommitdiff
path: root/app/views/characters/hearth/index.html.erb
blob: 1ad2726c15b2a361cce070aad7299acc7dbdc60a (plain)
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
<% foundation = @all_amenities.find_by_gid("foundation") %>
<h1 class="text-3xl mb-2">Hearth</h1>

<% if current_char.hearth.has_amenity?(foundation) %>
  <p class="mb-2">Here is your hearth, your safe haven and stronghold against all that ravages and thrashes
    in these realms. Amidst this great dream of planar chaos and destruction, you have built something.
  </p>

  <div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
    <% @all_amenities.each do |ha| %>
      <div class="border-2 border-gray-600 rounded p-4">
        <h2 class="text-lg font-bold"><%= ha.name %></h2>
        <% built_amenity = current_char.hearth.built_hearth_amenities.find_by(hearth_amenity: ha) %>
        <% if built_amenity %>
          <p class="mb-2">Level <%= built_amenity.level %></p>
          <p class="mb-2"><%= ha.description %></p>
          <% if @amenity_activities[ha.gid.to_sym] %>
            <div data-controller="activity-select">
              <%= form_with url: start_activity_path, method: :post do |f| %>
                <%= f.select :id, @amenity_activities[ha.gid.to_sym].sort_by { |a| a.name }.map { |a| [a.name, a.id] },
                             {}, { data: { activity_select_target: "select", action: "activity-select#load" } } %>
                <%= f.number_field :actions, value: 1, size: 5, min: 1, max: 2_000_000_000 %>
                <%= f.submit "Go" %>
              <% end %>
              <div data-activity-select-target="output" class="my-1"></div>
            </div>
          <% end %>
          <% if built_amenity.usable? %>
            <% if built_amenity.on_cooldown? %>
              <div class="text-sm">Will be filled again in
                <%= distance_of_time_in_words_to_now(built_amenity.cooled_down_at) %>.
              </div>
            <% else %>
              <%= button_to "Use", hearth_amenity_use_path(built_amenity.hearth_amenity) %>
            <% end %>
          <% end %>
          <% if built_amenity.hearth_amenity.gid == "loamspire" %>
            <%= link_to "Manage crops", character_hearth_loamspire_path, class: "btn btn-primary" %>
          <% end %>
        <% end %>
        <% next_level = built_amenity ? built_amenity.level + 1 : 1 %>
        <% construct_activity = ha.construct_activity(next_level) %>
        <% if construct_activity %>
          <div class="my-3">
            <%= form_with url: start_activity_path do |f| %>
              <%= f.hidden_field :id, value: construct_activity.id %>
              <%= f.hidden_field :actions, value: 1 %>
              <%= f.submit construct_activity.name %>
            <% end %>
            <div class="text-sm">(costs <%= construct_activity.costs.join(", ")%>)</div>
          </div>
        <% end %>
      </div>
    <% end %>
  </div>
<% else %>
  <p>You haven't built your hearth yet. First, you'll need to start with a foundation.</p>
  <% construct_activity = foundation.construct_activity(1) %>
  <%= form_with url: start_activity_path do |f| %>
    <%= f.hidden_field :id, value: construct_activity.id %>
    <%= f.hidden_field :actions, value: 1 %>
    <%= f.submit construct_activity.name %>
  <% end %>
  (costs <%= construct_activity.costs.join(", ")%>)
<% end %>