2024-06-13 16:04:25 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class DiceRollsController < ApplicationController
|
|
|
|
before_action :set_table
|
|
|
|
|
|
|
|
def create
|
|
|
|
rollable = dice_roll_params[:rollable_type].constantize.find(dice_roll_params[:rollable_id])
|
2024-06-14 12:22:24 +00:00
|
|
|
return head :bad_request if rollable.roll_command.blank?
|
|
|
|
|
2024-06-20 07:26:33 +00:00
|
|
|
roller = DiceRoller.new(rollable.roll_command, stat: rollable)
|
2024-06-13 16:04:25 +00:00
|
|
|
@table.dice_rolls.create!(
|
|
|
|
rollable:,
|
2024-06-20 07:26:33 +00:00
|
|
|
result: roller.roll,
|
|
|
|
dice: roller.dice,
|
2024-06-13 16:04:25 +00:00
|
|
|
)
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_table
|
|
|
|
@table = Current.user.owned_tables.find(params[:table_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def dice_roll_params
|
|
|
|
params.require(:dice_roll).permit(
|
|
|
|
:rollable_type,
|
|
|
|
:rollable_id,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|