Compare commits

...

7 Commits

Author SHA1 Message Date
Trevor Vallender 985e3584aa Implement ordering of character sheet features 2024-06-17 16:36:05 +01:00
Trevor Vallender 184da4a392 Style improvements 2024-06-17 15:11:14 +01:00
Trevor Vallender e672ffe153 Refactor character sheet features 2024-06-17 14:53:09 +01:00
Trevor Vallender 74eb7dba0e Ruby 3.3.3 update 2024-06-17 09:05:53 +01:00
Trevor Vallender b136792625 Prevent rolling unrollable stats 2024-06-14 13:22:24 +01:00
Trevor Vallender 8e1a16bb06 Add text fields to character sheets 2024-06-14 12:59:35 +01:00
Trevor Vallender de37a7e81f Add TextField model 2024-06-14 09:57:13 +01:00
48 changed files with 387 additions and 106 deletions

View File

@ -1 +1 @@
ruby-3.3.1
ruby-3.3.3

View File

@ -1,7 +1,7 @@
# syntax = docker/dockerfile:1
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.3.1
ARG RUBY_VERSION=3.3.3
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
# Rails app lives here

View File

@ -348,7 +348,7 @@ DEPENDENCIES
web-console
RUBY VERSION
ruby 3.3.1p55
ruby 3.3.3p89
BUNDLED WITH
2.5.3

View File

@ -70,6 +70,9 @@
padding: .5em;
}
input, .stat-value {
padding: .5em;
color: var(--text-color);
background-color: var(--input-background);
text-align: center;
font-size: 3em;
width: 2.5em;

View File

@ -3,7 +3,7 @@ form, fieldset {
gap: 1rem;
grid-template-columns: 1fr 2fr;
input, label, .stat-value {
input, label {
padding: .5em;
}
@ -44,9 +44,4 @@ form, fieldset {
form.stat-form, form.counter-form {
display: flex;
flex-direction: column;
.stat-value {
color: var(--text-color);
background-color: var(--input-background);
}
}

View File

@ -7,10 +7,12 @@ class CountersController < ApplicationController
def new
@counter = @section.counters.new
@counter.build_character_sheet_feature
end
def create
@counter = @section.counters.new(counter_params)
@editable = true
unless @counter.save
render :new, status: :unprocessable_entity
end
@ -42,7 +44,9 @@ class CountersController < ApplicationController
params.require(:counter).permit(
:name,
:value,
:character_sheet_section_id,
character_sheet_feature_attributes: [
:id, :featurable_id, :featurable_type, :character_sheet_section_id, :_destroy,
],
)
end
end

View File

@ -5,6 +5,8 @@ class DiceRollsController < ApplicationController
def create
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!(
rollable:,
result: DiceRoller.new(rollable.roll_command, stat: rollable).roll,

View File

@ -7,10 +7,12 @@ class StatsController < ApplicationController
def new
@stat = @section.stats.new
@stat.build_character_sheet_feature
end
def create
@stat = @section.stats.new(stat_params)
@editable = true
unless @stat.save
render :new, status: :unprocessable_entity
end
@ -44,7 +46,9 @@ class StatsController < ApplicationController
:name,
:value,
:roll_command,
:character_sheet_section_id,
character_sheet_feature_attributes: [
:id, :featurable_id, :featurable_type, :character_sheet_section_id, :_destroy,
],
)
end
end

View File

@ -0,0 +1,53 @@
# frozen_string_literal: true
class TextFieldsController < ApplicationController
before_action :set_section, only: [ :new, :create ]
before_action :set_character, only: [ :new, :create ]
before_action :set_text_field, only: [ :update, :destroy ]
def new
@text_field = @section.text_fields.new
@text_field.build_character_sheet_feature
end
def create
@text_field = @section.text_fields.new(text_field_params)
@editable = true
unless @text_field.save
render :new, status: :unprocessable_entity
end
end
def update
@text_field.update(text_field_params)
end
def destroy
@id = helpers.dom_id(@text_field)
@text_field.destroy
end
private
def set_character
@character = @section.character
end
def set_section
@section = Current.user.character_sheet_sections.find(params[:character_sheet_section_id])
end
def set_text_field
@text_field = Current.user.text_fields.find(params[:id])
end
def text_field_params
params.require(:text_field).permit(
:name,
:content,
:character_sheet_section_id,
character_sheet_feature_attributes: [
:id, :featurable_id, :featurable_type, :character_sheet_section_id, :_destroy,
],
)
end
end

View File

@ -0,0 +1,69 @@
# frozen_string_literal: true
class CharacterSheetFeature < ApplicationRecord
belongs_to :character_sheet_section
belongs_to :featurable, polymorphic: true
validates :order_index, presence: true,
numericality: { only_integer: true, greater_than: 0 },
uniqueness: { scope: :character_sheet_section_id }
validates :slug, presence: true,
length: { maximum: 100 },
uniqueness: { scope: :character_sheet_section_id }
before_validation :set_slug
before_validation :set_order_index
def move(to:)
return if to == order_index
unless character_sheet_section.character_sheet_features.exists?(order_index: to)
update!(order_index: to)
return
end
if to < order_index
character_sheet_section.character_sheet_features.where(order_index: to...order_index)
.update_all("order_index = order_index + 1")
else
character_sheet_section.character_sheet_features.where(order_index: (order_index+1)..to)
.update_all("order_index = order_index - 1")
end
update!(order_index: to)
end
private
def set_order_index
return if order_index.present?
if character_sheet_section.character_sheet_features.any?
self.order_index = character_sheet_section.character_sheet_features.order_index(:order_index).last.order_index + 1
else
self.order_index = 1
end
end
def set_slug
return if slug.present? || featurable.name.blank?
slug = if character_sheet_section.parent_section.present?
[
character_sheet_section.parent_section.name.parameterize,
featurable.name.parameterize,
].join("-")
else
slug = featurable.name.parameterize
end
suffix = 2
while CharacterSheetFeature.exists?(slug:)
slug = "#{slug}-#{suffix}"
suffix += 1
end
self.slug = slug
end
end

View File

@ -7,8 +7,13 @@ class CharacterSheetSection < ApplicationRecord
has_many :character_sheet_subsections, class_name: "CharacterSheetSection",
foreign_key: :parent_section_id,
dependent: :destroy
has_many :counters, dependent: :destroy
has_many :stats, dependent: :destroy
has_many :character_sheet_features
has_many :counters, dependent: :destroy, through: :character_sheet_features,
source: :featurable, source_type: "Counter"
has_many :stats, dependent: :destroy, through: :character_sheet_features,
source: :featurable, source_type: "Stat"
has_many :text_fields, dependent: :destroy, through: :character_sheet_features,
source: :featurable, source_type: "TextField"
validates :name, presence: true,
length: { maximum: 255 }

View File

@ -1,36 +0,0 @@
# frozen_string_literal: true
module Sluggable
extend ActiveSupport::Concern
included do
validates :slug, presence: true,
length: { maximum: 100 },
uniqueness: { scope: :character_sheet_section_id }
before_validation :set_slug
private
def set_slug
return if slug.present? || name.blank?
slug = if character_sheet_section.parent_section.present?
[
character_sheet_section.parent_section.name.parameterize,
name.parameterize,
].join("-")
else
slug = name.parameterize
end
suffix = 2
while Stat.exists?(slug:)
slug = "#{slug}-#{suffix}"
suffix += 1
end
self.slug = slug
end
end
end

View File

@ -1,14 +1,12 @@
# frozen_string_literal: true
class Counter < ApplicationRecord
include Sluggable
belongs_to :character_sheet_section
has_one :character_sheet_feature, as: :featurable
has_one :character_sheet_section, through: :character_sheet_feature
accepts_nested_attributes_for :character_sheet_feature, allow_destroy: true
validates :name, presence: true,
length: { maximum: 100 },
uniqueness: { scope: :character_sheet_section_id }
length: { maximum: 100 }
validates :value, presence: true,
numericality: true
before_validation :set_slug
end

View File

@ -1,18 +1,15 @@
# frozen_string_literal: true
class Stat < ApplicationRecord
include Sluggable
has_one :character_sheet_feature, as: :featurable
has_one :character_sheet_section, through: :character_sheet_feature
accepts_nested_attributes_for :character_sheet_feature, allow_destroy: true
belongs_to :character_sheet_section
has_one :character, through: :character_sheet_section
has_many :dice_rolls, as: :rollable, dependent: :destroy
validates :name, presence: true,
length: { maximum: 100 },
uniqueness: { scope: :character_sheet_section_id }
validates :slug, presence: true,
length: { maximum: 100 },
uniqueness: true
length: { maximum: 100 }
validates :value, presence: true,
numericality: true
validate :validate_roll_command

12
app/models/text_field.rb Normal file
View File

@ -0,0 +1,12 @@
# frozen_string_literal: true
class TextField < ApplicationRecord
has_one :character_sheet_feature, as: :featurable
has_one :character_sheet_section, through: :character_sheet_feature
accepts_nested_attributes_for :character_sheet_feature, allow_destroy: true
has_rich_text :content
validates :name, presence: true,
length: { maximum: 100 }
end

View File

@ -12,6 +12,7 @@ class User < ApplicationRecord
has_many :counters, through: :character_sheet_sections
has_many :stats, through: :character_sheet_sections
has_many :tables, through: :players
has_many :text_fields, through: :character_sheet_sections
has_rich_text :profile
has_one_attached :avatar do |attachable|
attachable.variant :standard, resize_to_limit: [ 100, 100 ], preprocessed: true

View File

@ -0,0 +1 @@
<%= render character_sheet_feature.featurable %>

View File

@ -4,14 +4,8 @@
<h4><%= character_sheet_section.name %></h4>
<div class="content">
<div id="<%= dom_id(character_sheet_section) %>_stats" class="stats">
<%= render character_sheet_section.stats %>
</div>
<div id="<%= dom_id(character_sheet_section) %>_counters" class="counters">
<%= render character_sheet_section.counters %>
</div>
<div id="<%= dom_id(character_sheet_section) %>_sections">
<%= render character_sheet_section.character_sheet_subsections %>
<div id="<%= dom_id(character_sheet_section) %>_features" class="stats">
<%= render character_sheet_section.character_sheet_features.order(:order_index) %>
</div>
<% if @editable %>
<div id="<%= dom_id(character_sheet_section) %>_add_section">

View File

@ -7,6 +7,8 @@
new_character_sheet_section_stat_path(section), data: { turbo_stream: true }, class: "add-stat" %>
<%= link_to t(".add_counter"),
new_character_sheet_section_counter_path(section), data: { turbo_stream: true }, class: "add-counter" %>
<%= link_to t(".add_text_field"),
new_character_sheet_section_text_field_path(section), data: { turbo_stream: true }, class: "add-text-field" %>
<% end %>
<% unless id == "character_sheet_add_section" %>
<%= link_to t(".delete_section", name: section.name), character_sheet_section_path(section),

View File

@ -1,6 +1,11 @@
<section class="inset">
<%= form_with model: @counter, url: character_sheet_section_counters_path(@section) do |f| %>
<%= f.hidden_field :character_sheet_section_id, value: @section.id %>
<% if @counter.new_record? %>
<%= f.fields_for :character_sheet_feature do |ff| %>
<%= ff.hidden_field :featurable_id, value: @counter.id %>
<%= ff.hidden_field :character_sheet_section_id, value: @section.id %>
<% end %>
<% end %>
<%= f.label :name %>
<%= f.text_field :name %>

View File

@ -1,11 +1,11 @@
<%= content_target = "#{dom_id(@section)}_counters" %>
<% content_target = "#{dom_id(@section)}_features" %>
<%= turbo_stream.append(content_target) do %>
<%= render @counter %>
<% end %>
<%= form_target = "#{dom_id(@section)}_add_section" %>
<% form_target = "#{dom_id(@section)}_add_section" %>
<%= turbo_stream.replace(form_target) do %>
<div id="#{dom_id(@section)}_add_section">
<div id="<%= dom_id(@section) %>_add_section">
<%= render partial: "character_sheet_sections/edit_links", locals: { section: @section, parent: @section.parent_section, id: nil} %>
</div>
<% end %>

View File

@ -1,4 +1,4 @@
<% target = "#{dom_id(@counter.character_sheet_section)}_add_section" %>
<% target = "#{dom_id(@section)}_add_section" %>
<%= turbo_stream.replace(target) do %>
<div id="<%= target %>">
<%= render partial: "form", locals: { button_text: t(".create_counter") } %>

View File

@ -1,6 +1,11 @@
<section class="inset">
<%= form_with model: @stat, url: character_sheet_section_stats_path(@section) do |f| %>
<%= f.hidden_field :character_sheet_section_id, value: @section.id %>
<% if @stat.new_record? %>
<%= f.fields_for :character_sheet_feature do |ff| %>
<%= ff.hidden_field :featurable_id, value: @stat.id %>
<%= ff.hidden_field :character_sheet_section_id, value: @section.id %>
<% end %>
<% end %>
<%= f.label :name %>
<%= f.text_field :name %>

View File

@ -8,12 +8,14 @@
<%= form_with model: stat, class: "stat-form", data: { controller: "auto-update" } do |f| %>
<%= f.number_field :value %>
<% end %>
<% else %>
<% elsif stat.roll_command.present? %>
<%= form_with model: DiceRoll.new, url: table_dice_rolls_path(stat.character.table), class: "stat-form",
data: { controller: "dice-roll" } do |f| %>
<%= f.hidden_field :rollable_type, value: "Stat" %>
<%= f.hidden_field :rollable_id, value: stat.id %>
<div class="stat-value" data-action="click->dice-roll#rollDice"><%= stat.value %></div>
<% end %>
<% else %>
<div class="stat-value"><%= stat.value %></div>
<% end %>
</div>

View File

@ -1,11 +1,11 @@
<%= content_target = "#{dom_id(@section)}_stats" %>
<%= content_target = "#{dom_id(@section)}_features" %>
<%= turbo_stream.append(content_target) do %>
<%= render @stat %>
<% end %>
<%= form_target = "#{dom_id(@section)}_add_section" %>
<%= turbo_stream.replace(form_target) do %>
<div id="#{dom_id(@section)}_add_section">
<div id="<%= dom_id(@section) %>_add_section">
<%= render partial: "character_sheet_sections/edit_links", locals: { section: @section, parent: @section.parent_section, id: nil} %>
</div>
<% end %>

View File

@ -1,4 +1,4 @@
<% target = "#{dom_id(@stat.character_sheet_section)}_add_section" %>
<% target = "#{dom_id(@section)}_add_section" %>
<%= turbo_stream.replace(target) do %>
<div id="<%= target %>">
<%= render partial: "form", locals: { button_text: t(".create_stat") } %>

View File

@ -0,0 +1,16 @@
<section class="inset">
<%= form_with model: @text_field, url: character_sheet_section_text_fields_path(@section) do |f| %>
<% if @text_field.new_record? %>
<%= f.fields_for :character_sheet_feature do |ff| %>
<%= ff.hidden_field :featurable_id, value: @text_field.id %>
<%= ff.hidden_field :character_sheet_section_id, value: @section.id %>
<% end %>
<% end %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= display_form_errors(@section, :name) %>
<%= f.submit button_text %>
<% end %>
</section>

View File

@ -0,0 +1,17 @@
<div class="text-field" id="<%= dom_id(text_field) %>">
<% if @editable %>
<%= link_to t(".delete"), text_field,
data: { turbo_method: :delete, turbo_confirm: t(".confirm_delete", name: text_field.name) } %>
<% end %>
<h6><%= text_field.name %></h6>
<% if @editable %>
<%= form_with model: text_field, class: "text-field-form" do |f| %>
<%= f.rich_text_area :content %>
<%= f.submit t(".save") %>
<% end %>
<% else %>
<p><%= text_field.content %></p>
<% end %>
</div>

View File

@ -0,0 +1,11 @@
<% content_target = "#{dom_id(@section)}_features" %>
<%= turbo_stream.append(content_target) do %>
<%= render @text_field %>
<% end %>
<% form_target = "#{dom_id(@section)}_add_section" %>
<%= turbo_stream.replace(form_target) do %>
<div id="<% dom_id(@section) %>_add_section">
<%= render partial: "character_sheet_sections/edit_links", locals: { section: @section, parent: @section.parent_section, id: nil} %>
</div>
<% end %>

View File

@ -0,0 +1 @@
<%= turbo_stream.remove @id %>

View File

@ -0,0 +1,6 @@
<% target = "#{dom_id(@section)}_add_section" %>
<%= turbo_stream.replace(target) do %>
<div id="<%= target %>">
<%= render partial: "form", locals: { button_text: t(".create_text_field") } %>
</div>
<% end %>

View File

@ -0,0 +1,3 @@
<%= turbo_stream.replace dom_id(@text_field) do %>
<%= render @text_field %>
<% end %>

View File

@ -65,6 +65,7 @@ en:
confirm_delete: Are you sure you want to delete this section?
add_stat: Add stat
add_counter: Add counter
add_text_field: Add text field
index:
edit: Edit character sheet
stop_editing: Stop editing
@ -213,6 +214,13 @@ en:
destroy:
success: Deleted table “%{name}”.
error: Failed to delete table.
text_fields:
text_field:
delete: Delete text field
confirm_delete: Are you sure you want to delete %{name}?
save: Save
new:
create_text_field: Create text field
users:
validations:
email_format: "must be a valid email address"

View File

@ -18,6 +18,7 @@ Rails.application.routes.draw do
resources :character_sheet_sections, only: [ :destroy ] do
resources :counters, only: [ :new, :create ]
resources :stats, only: [ :new, :create ]
resources :text_fields, only: [ :new, :create ]
end
resources :characters do
resources :character_sheet_sections, only: [ :index, :new, :create ]
@ -33,6 +34,7 @@ Rails.application.routes.draw do
resources :events, only: [ :index ]
resources :table_invites, only: [ :new, :create ]
end
resources :text_fields, only: [ :update, :destroy ]
resources :admin, only: [ :index ]
namespace :admin do

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
class CreateTextFields < ActiveRecord::Migration[7.1]
def change
create_table :text_fields do |t|
t.belongs_to :character_sheet_section, null: false, foreign_key: true
t.string :name, null: false
t.timestamps
end
add_check_constraint :text_fields, "length(name) <= 100", name: "chk_text_field_name_max_length"
end
end

View File

@ -0,0 +1,25 @@
# frozen_string_literal: true
class CreateCharacterSheetFeatures < ActiveRecord::Migration[7.1]
def change
create_table :character_sheet_features, primary_key: [ :character_sheet_section_id, :featurable_id ] do |t|
t.belongs_to :character_sheet_section, null: false, foreign_key: true
t.belongs_to :featurable, null: false, polymorphic: true
t.integer :order, null: false
t.string :slug, null: false
t.timestamps
end
remove_column :counters, :character_sheet_section_id, :integer
remove_column :stats, :character_sheet_section_id, :integer
remove_column :text_fields, :character_sheet_section_id, :integer
remove_column :counters, :order_index, :integer
remove_column :stats, :order_index, :integer
remove_column :text_fields, :order_index, :integer
remove_column :counters, :slug, :string
remove_column :stats, :slug, :string
end
end

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class RenameOrderColumn < ActiveRecord::Migration[7.1]
def change
rename_column :character_sheet_features, :order, :order_index
end
end

36
db/schema.rb generated
View File

@ -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_13_072942) do
ActiveRecord::Schema[7.1].define(version: 2024_06_17_151532) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -52,6 +52,18 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_13_072942) do
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end
create_table "character_sheet_features", primary_key: ["character_sheet_section_id", "featurable_id"], force: :cascade do |t|
t.bigint "character_sheet_section_id", null: false
t.string "featurable_type", null: false
t.bigint "featurable_id", null: false
t.integer "order_index", null: false
t.string "slug", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["character_sheet_section_id"], name: "index_character_sheet_features_on_character_sheet_section_id"
t.index ["featurable_type", "featurable_id"], name: "index_character_sheet_features_on_featurable"
end
create_table "character_sheet_sections", force: :cascade do |t|
t.string "name", null: false
t.bigint "character_id", null: false
@ -78,16 +90,10 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_13_072942) do
create_table "counters", force: :cascade do |t|
t.string "name", null: false
t.string "slug", null: false
t.integer "value", default: 0, null: false
t.bigint "character_sheet_section_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["character_sheet_section_id"], name: "index_counters_on_character_sheet_section_id"
t.index ["name", "character_sheet_section_id"], name: "index_counters_on_name_and_character_sheet_section_id", unique: true
t.index ["slug"], name: "index_counters_on_slug", unique: true
t.check_constraint "length(name::text) <= 100", name: "chk_counter_name_max_length"
t.check_constraint "length(slug::text) <= 100", name: "chk_counter_slug_max_length"
end
create_table "dice_rolls", force: :cascade do |t|
@ -236,17 +242,11 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_13_072942) do
create_table "stats", force: :cascade do |t|
t.string "name", null: false
t.string "slug", null: false
t.bigint "character_sheet_section_id", null: false
t.integer "value", default: 0, null: false
t.string "roll_command"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["character_sheet_section_id"], name: "index_stats_on_character_sheet_section_id"
t.index ["name", "character_sheet_section_id"], name: "index_stats_on_name_and_character_sheet_section_id", unique: true
t.index ["slug"], name: "index_stats_on_slug", unique: true
t.check_constraint "length(name::text) <= 100", name: "chk_stat_name_max_length"
t.check_constraint "length(slug::text) <= 100", name: "chk_stat_slug_max_length"
end
create_table "table_invites", force: :cascade do |t|
@ -276,6 +276,13 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_13_072942) do
t.check_constraint "length(slug::text) <= 100", name: "chk_table_slug_max_length"
end
create_table "text_fields", force: :cascade do |t|
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.check_constraint "length(name::text) <= 100", name: "chk_text_field_name_max_length"
end
create_table "users", force: :cascade do |t|
t.string "username", limit: 20, null: false
t.string "password_digest", limit: 200, null: false
@ -296,12 +303,12 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_13_072942) do
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "character_sheet_features", "character_sheet_sections"
add_foreign_key "character_sheet_sections", "character_sheet_sections", column: "parent_section_id"
add_foreign_key "character_sheet_sections", "characters"
add_foreign_key "characters", "game_systems"
add_foreign_key "characters", "tables"
add_foreign_key "characters", "users"
add_foreign_key "counters", "character_sheet_sections"
add_foreign_key "dice_rolls", "tables"
add_foreign_key "players", "tables"
add_foreign_key "players", "users"
@ -311,7 +318,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_13_072942) do
add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "stats", "character_sheet_sections"
add_foreign_key "table_invites", "tables"
add_foreign_key "tables", "game_systems"
add_foreign_key "tables", "users", column: "owner_id"

View File

@ -2,3 +2,8 @@ one:
record: trevor (User)
name: profile
body: <p>I am just <strong>so awesome</strong></p>
two:
record: background (TextField)
name: content
body: <p>Rhino-Man</p>

View File

@ -0,0 +1,20 @@
DEFAULTS: &DEFAULTS
slug: $LABEL
stats-strength:
<<: *DEFAULTS
character_sheet_section: stats
featurable: strength (Stat)
order_index: 1
counter:
<<: *DEFAULTS
character_sheet_section: counters
featurable: hp (Counter)
order_index: 2
text_field:
<<: *DEFAULTS
character_sheet_section: info
featurable: background (TextField)
order_index: 3

View File

@ -10,3 +10,7 @@ subsection:
name: Subsection
character: nardren
parent_section: stats
info:
name: Info
character: nardren

View File

@ -1,5 +1,3 @@
hp:
name: HP
value: 10
slug: hp
character_sheet_section: counters

View File

@ -1,6 +1,4 @@
strength:
name: Strength
slug: strength
character_sheet_section: stats
value: 10
roll_command: d20+self

2
test/fixtures/text_fields.yml vendored Normal file
View File

@ -0,0 +1,2 @@
background:
name: Background

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
require "test_helper"
class CharacterSheetFeatureTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -13,14 +13,16 @@ class StatTest < ActiveSupport::TestCase
test "saving generates appropriate slug" do
stat = Stat.create(name: "Foo", character_sheet_section: character_sheet_sections(:subsection))
assert_equal "stats-foo", stat.slug
assert_equal "stats-foo", stat.character_sheet_feature.slug
end
test "generates unique slug always" do
existing_stat = Stat.first
stat = Stat.create(name: existing_stat.name, character_sheet_section: existing_stat.character_sheet_section)
assert_not_equal existing_stat.slug, stat.slug
assert_equal "#{existing_stat.slug}-2", stat.slug
stat = Stat.create(name: existing_stat.name)
stat.build_character_sheet_feature(character_sheet_section: character_sheet_sections(:subsection))
stat.valid?
assert_not_equal existing_stat.character_sheet_feature.slug, stat.character_sheet_feature.slug
assert_equal "#{existing_stat.character_sheet_feature.slug}-2", stat.character_sheet_feature.slug
end
test "rolls with roll_command" do

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
require "test_helper"
class TextFieldTest < ActiveSupport::TestCase
test "name must exist" do
assert_must_exist(text_fields(:background), :name)
end
end

View File

@ -1,9 +1,11 @@
- set orders on sheets
- easily edit text fields without entering edit mode
- add roll command to counters (e.g. luck)
- test for rolls controller & system tests
- table notifications for rolls
- roll on click
- Show individual dice on dice roll
- customise trix bar
- Sheets
- Lists
- Text fields
- Weapons/spells
- Character avatars
- default avatars