diff options
author | David Gay <david@davidgay.org> | 2021-06-16 20:49:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 20:49:59 -0400 |
commit | 6dfaa7453591910e1373d92d8a09ddf384ebe834 (patch) | |
tree | ccec71ec425808ea82a3bfbcd36490f1cdcb666d /app/controllers | |
parent | 007896b0057b8aecbf74dddd269b57efe3f6e0e6 (diff) | |
parent | 0d6a82102061ff58b7ba34b09c4be9687c21ab2a (diff) |
Merge pull request #16 from dtgay/0.1.11
0.1.11
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/characters/bestiary_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/characters/hearth_controller.rb | 3 | ||||
-rw-r--r-- | app/controllers/characters/item_infixes_controller.rb | 27 | ||||
-rw-r--r-- | app/controllers/characters/items_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/characters/rankings_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/characters/skills_controller.rb | 15 | ||||
-rw-r--r-- | app/controllers/characters/spells_controller.rb | 9 | ||||
-rw-r--r-- | app/controllers/characters_controller.rb | 15 |
8 files changed, 87 insertions, 8 deletions
diff --git a/app/controllers/characters/bestiary_controller.rb b/app/controllers/characters/bestiary_controller.rb new file mode 100644 index 0000000..7e37d9c --- /dev/null +++ b/app/controllers/characters/bestiary_controller.rb @@ -0,0 +1,12 @@ +class Characters::BestiaryController < ApplicationController + before_action :set_character + + def index + @monster_kills = @character.monster_kills.all + end + + private + def set_character + @character = Character.find(params[:character_id]) + end +end diff --git a/app/controllers/characters/hearth_controller.rb b/app/controllers/characters/hearth_controller.rb index 82f72d6..c525add 100644 --- a/app/controllers/characters/hearth_controller.rb +++ b/app/controllers/characters/hearth_controller.rb @@ -7,6 +7,7 @@ class Characters::HearthController < ApplicationController forge: [], laboratory: [], spicebench: [], + binding_array: [], } Activity.where("gid like ?", "craft_%").each do |activity| @@ -20,6 +21,8 @@ class Characters::HearthController < ApplicationController @amenity_activities[:laboratory].push(activity) && next when "spicebench" @amenity_activities[:spicebench].push(activity) && next + when "binding_array" + @amenity_activities[:binding_array].push(activity) && next else raise "Invalid amenity gid (#{requirement_data[:gid]}" end diff --git a/app/controllers/characters/item_infixes_controller.rb b/app/controllers/characters/item_infixes_controller.rb new file mode 100644 index 0000000..0b5f1c5 --- /dev/null +++ b/app/controllers/characters/item_infixes_controller.rb @@ -0,0 +1,27 @@ +class Characters::ItemInfixesController < ApplicationController + def create + # TODO: Can this find-by-id happen automagically? + @item_infix = current_char.infix(Item.find(params[:item_id]), Skill.find(params[:skill_id])) + if @item_infix + flash[:notice] = "Infixed #{@item_infix.item.name}." + else + flash[:alert] = "Failed to infix item." + end + redirect_to character_skills_path(current_char) + end + + def destroy + @item_infix = ItemInfix.find(params[:id]) + if current_char.remove_infix(@item_infix) + flash[:notice] = "Removed #{@item_infix.item.name}." + else + flash[:alert] = "Failed to remove #{@item_infix.item.name}." + end + redirect_to character_skills_path(current_char) + end + + private + def item_infix_params + params.require(:item_infix).permit(:item_id, :skill_id) + end +end diff --git a/app/controllers/characters/items_controller.rb b/app/controllers/characters/items_controller.rb index 470e21c..e38b69a 100644 --- a/app/controllers/characters/items_controller.rb +++ b/app/controllers/characters/items_controller.rb @@ -1,6 +1,7 @@ class Characters::ItemsController < ApplicationController + before_action :set_character, only: :index + def index - @character = Character.find(params[:character_id]) end def equip @@ -66,4 +67,13 @@ class Characters::ItemsController < ApplicationController redirect_to character_items_path(current_char) end end + + private + def set_character + @character = Character.find(params[:character_id]) + unless current_char == @character + flash[:alert] = "You can only look at your own items." + redirect_to character_path(@character) + end + end end diff --git a/app/controllers/characters/rankings_controller.rb b/app/controllers/characters/rankings_controller.rb index bbae9fc..429b487 100644 --- a/app/controllers/characters/rankings_controller.rb +++ b/app/controllers/characters/rankings_controller.rb @@ -6,4 +6,4 @@ class Characters::RankingsController < ApplicationController def index @character = Character.find(params[:character_id]) end -end
\ No newline at end of file +end diff --git a/app/controllers/characters/skills_controller.rb b/app/controllers/characters/skills_controller.rb new file mode 100644 index 0000000..6fcf417 --- /dev/null +++ b/app/controllers/characters/skills_controller.rb @@ -0,0 +1,15 @@ +class Characters::SkillsController < ApplicationController + before_action :set_character, only: :index + + def index + end + + private + def set_character + @character = Character.find(params[:character_id]) + unless current_char == @character + flash[:alert] = "You can only look at your own skills." + redirect_to character_path(@character) + end + end +end diff --git a/app/controllers/characters/spells_controller.rb b/app/controllers/characters/spells_controller.rb new file mode 100644 index 0000000..a0e6913 --- /dev/null +++ b/app/controllers/characters/spells_controller.rb @@ -0,0 +1,9 @@ +class Characters::SpellsController < ApplicationController + def index + @spell_activities = Activity.where("gid like ?", "havencast_%").where(innate: true).order(:name) + # TODO: Don't load into memory + @spell_activities = @spell_activities.to_a + current_char.learned_activities + .map { |la| la.activity } + .select { |a| a.gid.start_with?("havencast_") } + end +end diff --git a/app/controllers/characters_controller.rb b/app/controllers/characters_controller.rb index 77e1a94..2eb906b 100644 --- a/app/controllers/characters_controller.rb +++ b/app/controllers/characters_controller.rb @@ -1,8 +1,8 @@ class CharactersController < ApplicationController skip_before_action :redirect_if_no_active_character, only: [:new, :create] + before_action :set_character, only: [:show, :set_combat_styles] def show - @character = Character.find(params[:id]) end def new @@ -22,11 +22,6 @@ class CharactersController < ApplicationController end def set_combat_styles - @character = Character.find(params[:character_id]) - unless @character == current_char - flash[:alert] = "You can't set the combat styles of another character." - redirect_to character_path(@character) and return - end if @character.update(offensive_style: params[:offensive_style], defensive_style: params[:defensive_style]) flash[:notice] = "Changed combat styles to #{@character.offensive_style} and #{@character.defensive_style}." @@ -40,4 +35,12 @@ class CharactersController < ApplicationController def character_params params.require(:character).permit(:name) end + + def set_character + @character = Character.find(params[:id]) + unless current_char == @character + flash[:alert] = "You can only manage your own character." + redirect_to character_path(@character) + end + end end |