From 260ca449a78827466a9949bca242d0e528346c5e Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 1 Feb 2023 21:45:57 -0800 Subject: [PATCH] GridWeapon decides if it is mainhand or not --- app/controllers/api/v1/grid_weapons_controller.rb | 1 + app/models/grid_weapon.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/app/controllers/api/v1/grid_weapons_controller.rb b/app/controllers/api/v1/grid_weapons_controller.rb index 76b14f8..a24dfa3 100644 --- a/app/controllers/api/v1/grid_weapons_controller.rb +++ b/app/controllers/api/v1/grid_weapons_controller.rb @@ -167,6 +167,7 @@ module Api output = render_conflict_view([conflict_weapon], incoming_weapon, weapon_params[:position]) render json: output else + ap "Moving weapon to new position..." # Move the original grid weapon to the new position # to preserve keys and other modifications old_position = conflict_weapon.position diff --git a/app/models/grid_weapon.rb b/app/models/grid_weapon.rb index 1048290..acec98d 100644 --- a/app/models/grid_weapon.rb +++ b/app/models/grid_weapon.rb @@ -13,6 +13,8 @@ class GridWeapon < ApplicationRecord validate :compatible_with_position, on: :create validate :no_conflicts, on: :create + before_save :is_mainhand + ##### Amoeba configuration amoeba do nullify :ax_modifier1 @@ -71,4 +73,13 @@ class GridWeapon < ApplicationRecord # Check if the grid weapon conflicts with any of the other grid weapons in the party errors.add(:series, 'must not conflict with existing weapons') unless conflicts(party).nil? end + + # Checks if the weapon should be a mainhand before saving the model + def is_mainhand + if self.position == -1 + self.mainhand = true + else + self.mainhand = false + end + end end