Prevent rolling unrollable stats
This commit is contained in:
parent
8e1a16bb06
commit
b136792625
|
@ -5,6 +5,8 @@ class DiceRollsController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
rollable = dice_roll_params[:rollable_type].constantize.find(dice_roll_params[:rollable_id])
|
rollable = dice_roll_params[:rollable_type].constantize.find(dice_roll_params[:rollable_id])
|
||||||
|
return head :bad_request if rollable.roll_command.blank?
|
||||||
|
|
||||||
@table.dice_rolls.create!(
|
@table.dice_rolls.create!(
|
||||||
rollable:,
|
rollable:,
|
||||||
result: DiceRoller.new(rollable.roll_command, stat: rollable).roll,
|
result: DiceRoller.new(rollable.roll_command, stat: rollable).roll,
|
||||||
|
|
|
@ -8,12 +8,14 @@
|
||||||
<%= form_with model: stat, class: "stat-form", data: { controller: "auto-update" } do |f| %>
|
<%= form_with model: stat, class: "stat-form", data: { controller: "auto-update" } do |f| %>
|
||||||
<%= f.number_field :value %>
|
<%= f.number_field :value %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% elsif stat.roll_command.present? %>
|
||||||
<%= form_with model: DiceRoll.new, url: table_dice_rolls_path(stat.character.table), class: "stat-form",
|
<%= form_with model: DiceRoll.new, url: table_dice_rolls_path(stat.character.table), class: "stat-form",
|
||||||
data: { controller: "dice-roll" } do |f| %>
|
data: { controller: "dice-roll" } do |f| %>
|
||||||
<%= f.hidden_field :rollable_type, value: "Stat" %>
|
<%= f.hidden_field :rollable_type, value: "Stat" %>
|
||||||
<%= f.hidden_field :rollable_id, value: stat.id %>
|
<%= f.hidden_field :rollable_id, value: stat.id %>
|
||||||
<div class="stat-value" data-action="click->dice-roll#rollDice"><%= stat.value %></div>
|
<div class="stat-value" data-action="click->dice-roll#rollDice"><%= stat.value %></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<div class="stat-value"><%= stat.value %></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
1
todo.md
1
todo.md
|
@ -1,4 +1,3 @@
|
||||||
- don't roll when no roll set
|
|
||||||
- set orders on sheets
|
- set orders on sheets
|
||||||
- easily edit text fields without entering edit mode
|
- easily edit text fields without entering edit mode
|
||||||
- add roll command to counters (e.g. luck)
|
- add roll command to counters (e.g. luck)
|
||||||
|
|
Loading…
Reference in New Issue