Prevent moving features beyond section bounds
This commit is contained in:
parent
a0271f0b69
commit
dd850813cb
|
@ -17,11 +17,7 @@ class CharacterSheetFeature < ApplicationRecord
|
||||||
|
|
||||||
def move(to:)
|
def move(to:)
|
||||||
return if to == order_index
|
return if to == order_index
|
||||||
|
return if to < character_sheet_section.lowest_order_index || to > character_sheet_section.highest_order_index
|
||||||
unless character_sheet_section.character_sheet_features.exists?(order_index: to)
|
|
||||||
update!(order_index: to)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if to < order_index
|
if to < order_index
|
||||||
character_sheet_section.character_sheet_features.where(order_index: to...order_index)
|
character_sheet_section.character_sheet_features.where(order_index: to...order_index)
|
||||||
|
|
|
@ -17,4 +17,12 @@ class CharacterSheetSection < ApplicationRecord
|
||||||
length: { maximum: 255 }
|
length: { maximum: 255 }
|
||||||
|
|
||||||
scope :top_level, -> { where.missing(:parent_section) }
|
scope :top_level, -> { where.missing(:parent_section) }
|
||||||
|
|
||||||
|
def lowest_order_index
|
||||||
|
character_sheet_features.minimum(:order_index) || 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def highest_order_index
|
||||||
|
character_sheet_features.maximum(:order_index) || 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,18 @@ stats-strength:
|
||||||
featurable: strength (Stat)
|
featurable: strength (Stat)
|
||||||
order_index: 1
|
order_index: 1
|
||||||
|
|
||||||
|
stats-dexterity:
|
||||||
|
<<: *DEFAULTS
|
||||||
|
character_sheet_section: stats
|
||||||
|
featurable: dexterity (Stat)
|
||||||
|
order_index: 2
|
||||||
|
|
||||||
|
stats-constitution:
|
||||||
|
<<: *DEFAULTS
|
||||||
|
character_sheet_section: stats
|
||||||
|
featurable: constitution (Stat)
|
||||||
|
order_index: 3
|
||||||
|
|
||||||
text_field:
|
text_field:
|
||||||
<<: *DEFAULTS
|
<<: *DEFAULTS
|
||||||
character_sheet_section: info
|
character_sheet_section: info
|
||||||
|
|
|
@ -10,3 +10,7 @@ subsection:
|
||||||
info:
|
info:
|
||||||
name: Info
|
name: Info
|
||||||
character: nardren
|
character: nardren
|
||||||
|
|
||||||
|
empty:
|
||||||
|
name: Empty
|
||||||
|
character: nardren
|
||||||
|
|
|
@ -2,3 +2,13 @@ strength:
|
||||||
name: Strength
|
name: Strength
|
||||||
value: 10
|
value: 10
|
||||||
roll_command: d20+self
|
roll_command: d20+self
|
||||||
|
|
||||||
|
dexterity:
|
||||||
|
name: Dexterity
|
||||||
|
value: 10
|
||||||
|
roll_command: d20+self
|
||||||
|
|
||||||
|
constitution:
|
||||||
|
name: Constitution
|
||||||
|
value: 10
|
||||||
|
roll_command: d20+self
|
||||||
|
|
|
@ -3,7 +3,4 @@
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class CharacterSheetFeatureTest < ActiveSupport::TestCase
|
class CharacterSheetFeatureTest < ActiveSupport::TestCase
|
||||||
# test "the truth" do
|
|
||||||
# assert true
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,4 +6,14 @@ class CharacterSheetSectionTest < ActiveSupport::TestCase
|
||||||
test "name must exist" do
|
test "name must exist" do
|
||||||
assert_must_exist(character_sheet_sections(:stats), "name")
|
assert_must_exist(character_sheet_sections(:stats), "name")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns correct order index" do
|
||||||
|
assert_equal 3, character_sheet_sections(:stats).highest_order_index
|
||||||
|
assert_equal 1, character_sheet_sections(:stats).lowest_order_index
|
||||||
|
end
|
||||||
|
|
||||||
|
test "an empty section returns 1 for lowest/highest order index" do
|
||||||
|
assert_equal 1, character_sheet_sections(:empty).lowest_order_index
|
||||||
|
assert_equal 1, character_sheet_sections(:empty).highest_order_index
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
5
todo.md
5
todo.md
|
@ -1,11 +1,6 @@
|
||||||
- request invite
|
- request invite
|
||||||
- don't move down/up top/bottom features
|
|
||||||
- auto save text fields
|
- auto save text fields
|
||||||
- indicate save status on titlebar
|
- indicate save status on titlebar
|
||||||
- easily edit text fields without entering edit mode
|
|
||||||
- add roll command to counters (e.g. luck)
|
|
||||||
- test for rolls controller & system tests
|
|
||||||
- Show individual dice on dice roll
|
|
||||||
- Sheets
|
- Sheets
|
||||||
- Lists
|
- Lists
|
||||||
- Weapons/spells
|
- Weapons/spells
|
||||||
|
|
Loading…
Reference in New Issue