diff --git a/app/assets/stylesheets/layout.css b/app/assets/stylesheets/layout.css index d9ac8cf..3b46ad1 100644 --- a/app/assets/stylesheets/layout.css +++ b/app/assets/stylesheets/layout.css @@ -181,3 +181,7 @@ footer { margin: 0 auto; } } + +.subsections { + margin: .5em; +} diff --git a/app/controllers/character_sheet_sections_controller.rb b/app/controllers/character_sheet_sections_controller.rb index 24bc5f5..3968ae4 100644 --- a/app/controllers/character_sheet_sections_controller.rb +++ b/app/controllers/character_sheet_sections_controller.rb @@ -15,6 +15,7 @@ class CharacterSheetSectionsController < ApplicationController end def new + @templates = Template.game_system(@character.game_system) if params[:parent_section_id].present? @parent_section = @character.character_sheet_sections.find_by(id: params[:parent_section_id]) end @@ -22,7 +23,16 @@ class CharacterSheetSectionsController < ApplicationController end def create - @section = @character.character_sheet_sections.new(character_sheet_section_params) + @templates = Template.game_system(@character.game_system) + if params[:template_id].present? + @section = CharacterSheetSection.new_from_template( + template: Template.find(params[:template_id]), + params: character_sheet_section_params, + character: @character, + ) + else + @section = @character.character_sheet_sections.new(character_sheet_section_params) + end @editable = true unless @section.save @parent_section = @section.parent_section diff --git a/app/controllers/characters_controller.rb b/app/controllers/characters_controller.rb index 0c5ec8f..fda2088 100644 --- a/app/controllers/characters_controller.rb +++ b/app/controllers/characters_controller.rb @@ -14,7 +14,7 @@ class CharactersController < ApplicationController def create @character = Current.user.characters.new(character_params) if @character.save - redirect_to @character, notice: t(".success") + redirect_to @character, notice: t(".success", name: @character.name) else flash.now[:alert] = t(".error") render :new, status: :unprocessable_entity diff --git a/app/models/character_sheet_section.rb b/app/models/character_sheet_section.rb index 1101919..73b7e09 100644 --- a/app/models/character_sheet_section.rb +++ b/app/models/character_sheet_section.rb @@ -18,6 +18,13 @@ class CharacterSheetSection < ApplicationRecord scope :top_level, -> { where.missing(:parent_section) } + def self.new_from_template(template:, character:, params:) + section = CharacterSheetSection.deserialize(JSON.parse(template.content)) + section.assign_attributes(params) + section.character = character + section + end + def lowest_order_index character_sheet_features.minimum(:order_index) || 1 end diff --git a/app/models/template.rb b/app/models/template.rb index 0e31f51..7c8de73 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -9,4 +9,6 @@ class Template < ApplicationRecord validates :content, presence: true validates :klass, presence: true, length: { maximum: 200 } + + scope :game_system, ->(game_system) { where(game_system:) } end diff --git a/app/views/character_sheet_sections/_character_sheet_section.html.erb b/app/views/character_sheet_sections/_character_sheet_section.html.erb index 410ef19..5815e67 100644 --- a/app/views/character_sheet_sections/_character_sheet_section.html.erb +++ b/app/views/character_sheet_sections/_character_sheet_section.html.erb @@ -14,4 +14,8 @@ <% end %> + +
+ <%= render character_sheet_section.character_sheet_subsections %> +
diff --git a/app/views/character_sheet_sections/_form.html.erb b/app/views/character_sheet_sections/_form.html.erb index db1a042..2110907 100644 --- a/app/views/character_sheet_sections/_form.html.erb +++ b/app/views/character_sheet_sections/_form.html.erb @@ -6,6 +6,10 @@ <%= f.text_field :name %> <%= display_form_errors(@section, :name) %> + <%= label_tag :template_id, t(".template") %> + <%= collection_select nil, :template_id, @templates, :id, :name, include_blank: " " %> + <%= display_form_errors(@section, :template) %> + <%= f.submit button_text %> <% end %> diff --git a/app/views/character_sheet_sections/create.turbo_stream.erb b/app/views/character_sheet_sections/create.turbo_stream.erb index adf54e5..0ff0f23 100644 --- a/app/views/character_sheet_sections/create.turbo_stream.erb +++ b/app/views/character_sheet_sections/create.turbo_stream.erb @@ -1,4 +1,4 @@ -<% content_target = @section.parent_section.present? ? "#{dom_id(@section.parent_section)}_sections" +<% content_target = @section.parent_section.present? ? "#{dom_id(@section.parent_section)}_subsections" : "character_sheet" %> <%= turbo_stream.append(content_target) do %> <%= render @section %> diff --git a/app/views/text_fields/create.turbo_stream.erb b/app/views/text_fields/create.turbo_stream.erb index c448203..5ceebbe 100644 --- a/app/views/text_fields/create.turbo_stream.erb +++ b/app/views/text_fields/create.turbo_stream.erb @@ -5,7 +5,7 @@ <% form_target = "#{dom_id(@section)}_add_section" %> <%= turbo_stream.replace(form_target) do %> -
+
<%= render partial: "character_sheet_sections/edit_links", locals: { section: @section, parent: @section.parent_section, id: nil} %>
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 5e4701a..39a3e39 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -75,6 +75,8 @@ en: add_section: Add section new: create_section: Create section + form: + template: From template (leave blank for none) characters: index: my_characters: My characters diff --git a/todo.md b/todo.md index f362b6c..cf2691e 100644 --- a/todo.md +++ b/todo.md @@ -1,20 +1,36 @@ -- Templates -- Add from template -- Edit/delete templates +Character sheets += Must haves +- Refer to stat in roll (Skill in Troika) - Lists -- request invite +- Reorganise sections +- Edit additional roll types - improve dice roll parsing to allow e.g. choose highest += Nice to haves +- Calculate from result - e.g. troika damage roll should calc. damage amount from die roll:w +- Add min/max when creating stats +- Better sheet layout (multiple small sections per line) +- Display empty text fields prettier +- Rename to SectionTemplate - Easy add amount to stat -- icons on features - auto save text fields - indicate save status on titlebar +- icons on features +- Cancel adding subsection, stat etc. + +Templates +- Template accessibility level + - Users can add their own, "official" ones are always available + - Unofficial ones can be added to a local list of favourites +- Edit/delete templates +- Sheet section color + +Misc +- request invite - Character avatars - default avatars - add uuid/slug to characters and any other url-visible ids - shared/private notes - NPCs -- Character sheets prototypes -- notifications - chat - maps - show errors from invalid sheet bits