Add multiple dice roll types to stats
This commit is contained in:
parent
ab5af6e19c
commit
efaf81dfcb
|
@ -26,6 +26,7 @@ class DiceRollsController < ApplicationController
|
|||
params.require(:dice_roll).permit(
|
||||
:rollable_type,
|
||||
:rollable_id,
|
||||
:dice_roll_type_id,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DiceRollType < ApplicationRecord
|
||||
belongs_to :rollable, polymorphic: true
|
||||
|
||||
validates :name, length: { maximum: 100 }
|
||||
validates :roll_command, length: { maximum: 100 }
|
||||
|
||||
def roll(table)
|
||||
roller = DiceRoller.new(roll_command, stat: rollable)
|
||||
end
|
||||
|
||||
def value
|
||||
rollable.value
|
||||
end
|
||||
|
||||
def character
|
||||
rollable.character
|
||||
end
|
||||
end
|
|
@ -7,6 +7,7 @@ class Stat < ApplicationRecord
|
|||
|
||||
has_one :character, through: :character_sheet_section
|
||||
has_many :dice_rolls, as: :rollable, dependent: :destroy
|
||||
has_many :dice_roll_types, as: :rollable, dependent: :destroy
|
||||
|
||||
validates :name, presence: true,
|
||||
length: { maximum: 100 }
|
||||
|
|
|
@ -19,6 +19,14 @@
|
|||
<%= f.hidden_field :rollable_id, value: @stat.id %>
|
||||
<%= f.submit "#{t(".roll")}".html_safe, class: "roll-button" %>
|
||||
<% end %>
|
||||
<% @stat.dice_roll_types.each do |dice_roll_type| %>
|
||||
<%= 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: "DiceRollType" %>
|
||||
<%= f.hidden_field :rollable_id, value: dice_roll_type.id %>
|
||||
<%= f.submit "#{t(".roll_type", name: dice_roll_type.name)}".html_safe, class: "roll-button" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -140,6 +140,7 @@ en:
|
|||
stats:
|
||||
show:
|
||||
roll: Roll!
|
||||
roll_type: Roll %{name}!
|
||||
min_allowed: Min
|
||||
max_allowed: Max
|
||||
stat:
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateDiceRollTypes < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :dice_roll_types do |t|
|
||||
t.string :name, null: false
|
||||
t.string :roll_command, null: false
|
||||
t.belongs_to :rollable, null: false, polymorphic: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_check_constraint :dice_roll_types, "length(name) <= 100", name: "chk_name_max_length"
|
||||
add_check_constraint :dice_roll_types, "length(roll_command) <= 100", name: "chk_roll_command_max_length"
|
||||
end
|
||||
end
|
|
@ -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_102903) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_06_21_141219) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -88,6 +88,18 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_21_102903) do
|
|||
t.check_constraint "length(name::text) <= 200", name: "chk_character_name_max_length"
|
||||
end
|
||||
|
||||
create_table "dice_roll_types", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "roll_command", null: false
|
||||
t.string "rollable_type", null: false
|
||||
t.bigint "rollable_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["rollable_type", "rollable_id"], name: "index_dice_roll_types_on_rollable"
|
||||
t.check_constraint "length(name::text) <= 100", name: "chk_name_max_length"
|
||||
t.check_constraint "length(roll_command::text) <= 100", name: "chk_roll_command_max_length"
|
||||
end
|
||||
|
||||
create_table "dice_rolls", force: :cascade do |t|
|
||||
t.string "rollable_type"
|
||||
t.bigint "rollable_id"
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
strength_advantage:
|
||||
name: with advantage
|
||||
roll_command: d20+self+d20
|
||||
rollable: strength (Stat)
|
3
todo.md
3
todo.md
|
@ -1,7 +1,10 @@
|
|||
- Edit dice roll command, types
|
||||
- request invite
|
||||
- Weapons/spells: skills?
|
||||
- Do this have_many :stats?
|
||||
- Lists
|
||||
- make dice rolls own model so stats can have multiple rolls (e.g. advantage)
|
||||
- improve dice roll parsing to allow e.g. choose highest
|
||||
- Easy add amount to stat
|
||||
- icons on features
|
||||
- auto save text fields
|
||||
|
|
Loading…
Reference in New Issue