diff --git a/app/assets/stylesheets/characters.css b/app/assets/stylesheets/characters.css index 264d70d..a8210ed 100644 --- a/app/assets/stylesheets/characters.css +++ b/app/assets/stylesheets/characters.css @@ -108,3 +108,29 @@ text-decoration: none; } } + +.stat-value { + position: relative; +} + +.stat-min-value:empty, .stat-max-value:empty { + display: none; +} +.stat-min-value, .stat-max-value { + font-size: .3em; + background-color: var(--background-color); + color: var(--header-text-color); + position: absolute; + bottom: 0; + padding: .5em; +} + +.stat-min-value { + left: 0; + border-radius: 0 1em 0 0; +} + +.stat-max-value { + right: 0; + border-radius: 1em 0 0 0; +} diff --git a/app/assets/stylesheets/forms.css b/app/assets/stylesheets/forms.css index 62ae208..16706ca 100644 --- a/app/assets/stylesheets/forms.css +++ b/app/assets/stylesheets/forms.css @@ -54,6 +54,7 @@ form.stat-form { display: block; margin: 1em auto; width: fit-content; + text-align: center; } .feature-box form.text-field-form { @@ -64,3 +65,14 @@ form.stat-form { margin-bottom: 1em; } } + +.inline { + padding: .5em; + input { + padding: .2em; + height: auto; + min-width: 5em; + font-size: 1em; + } +} + diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 3c421b7..8bb6f78 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -23,7 +23,7 @@ class StatsController < ApplicationController def update @editable = ActiveModel::Type::Boolean.new.cast(params[:editable]) - @stat.update(stat_params) + @stat.update!(stat_params) end def destroy @@ -48,6 +48,8 @@ class StatsController < ApplicationController params.require(:stat).permit( :name, :value, + :min_allowed, + :max_allowed, :roll_command, character_sheet_feature_attributes: [ :id, :featurable_id, :featurable_type, :character_sheet_section_id, :_destroy, diff --git a/app/models/stat.rb b/app/models/stat.rb index 90a55e2..139dc9d 100644 --- a/app/models/stat.rb +++ b/app/models/stat.rb @@ -10,10 +10,16 @@ class Stat < ApplicationRecord validates :name, presence: true, length: { maximum: 100 } + validates :min_allowed, numericality: true, allow_nil: true + validates :max_allowed, numericality: true, allow_nil: true validates :value, presence: true, numericality: true validate :validate_roll_command + def rollable? + roll_command.present? + end + def roll(table) roller = DiceRoller.new(roll_command, stat: self) result = roller.roll diff --git a/app/views/stats/_stat.html.erb b/app/views/stats/_stat.html.erb index a1a34da..a9a0401 100644 --- a/app/views/stats/_stat.html.erb +++ b/app/views/stats/_stat.html.erb @@ -17,7 +17,11 @@ <% end %> <% else %> <%= link_to stat, data: { turbo_frame: :modal } do %> -
<%= stat.value %>
+
+ <%= stat.value %> +
<%= stat.min_allowed %>
+
<%= stat.max_allowed %>
+
<% end %> <% end %> diff --git a/app/views/stats/show.html.erb b/app/views/stats/show.html.erb index 4a1d3cb..7330dc7 100644 --- a/app/views/stats/show.html.erb +++ b/app/views/stats/show.html.erb @@ -1,16 +1,24 @@ <%= turbo_frame_tag :modal do %>
<%= icon_link_to "fa-close", table_character_character_sheet_sections_path(@stat.character.table, @stat.character), - class: "icon-link" %> + class: "icon-link" %>

<%= @stat.name %>

<%= form_with model: @stat, class: "stat-form", data: { controller: "auto-update" } do |f| %> - <%= f.number_field :value %> + <%= f.number_field :value, min: @stat.min_allowed, max: @stat.max_allowed %> +
+ <%= f.label :min_allowed, t(".min_allowed") %> + <%= f.number_field :min_allowed %> + <%= f.label :max_allowed, t(".max_allowed") %> + <%= f.number_field :max_allowed %> +
<% end %> - <%= form_with model: DiceRoll.new, url: table_dice_rolls_path(@stat.character.table), class: "stat-form", - data: { controller: "dice-roll modal-closer", action: "modal-closer#closeModal" } do |f| %> - <%= f.hidden_field :rollable_type, value: "Stat" %> - <%= f.hidden_field :rollable_id, value: @stat.id %> - <%= f.submit "#{t(".roll")}".html_safe, class: "roll-button" %> + <% if @stat.rollable? %> + <%= form_with model: DiceRoll.new, url: table_dice_rolls_path(@stat.character.table), class: "stat-form", + data: { controller: "dice-roll modal-closer", action: "modal-closer#closeModal" } do |f| %> + <%= f.hidden_field :rollable_type, value: "Stat" %> + <%= f.hidden_field :rollable_id, value: @stat.id %> + <%= f.submit "#{t(".roll")}".html_safe, class: "roll-button" %> + <% end %> <% end %>
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 924dbd9..3a91625 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -140,6 +140,8 @@ en: stats: show: roll: Roll! + min_allowed: Min + max_allowed: Max stat: down: Move down up: Move up diff --git a/db/migrate/20240621102903_add_min_max_to_stats.rb b/db/migrate/20240621102903_add_min_max_to_stats.rb new file mode 100644 index 0000000..6ce0476 --- /dev/null +++ b/db/migrate/20240621102903_add_min_max_to_stats.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddMinMaxToStats < ActiveRecord::Migration[7.1] + def change + add_column :stats, :min_allowed, :integer + add_column :stats, :max_allowed, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index d25a79a..f8655f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_06_21_091420) do +ActiveRecord::Schema[7.1].define(version: 2024_06_21_102903) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -239,6 +239,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_21_091420) do t.string "roll_command" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "min_allowed" + t.integer "max_allowed" t.check_constraint "length(name::text) <= 100", name: "chk_stat_name_max_length" end diff --git a/todo.md b/todo.md index fe0af6a..592e163 100644 --- a/todo.md +++ b/todo.md @@ -1,9 +1,11 @@ - request invite +- Weapons/spells: skills? + - Do this have_many :stats? + - Lists +- Easy add amount to stat +- icons on features - auto save text fields - indicate save status on titlebar -- Sheets - - Lists - - Weapons/spells - Character avatars - default avatars - add uuid/slug to characters and any other url-visible ids