diff options
author | David Gay <david@davidgay.org> | 2021-07-05 20:30:15 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-07-05 20:30:15 -0400 |
commit | 28426519e11e72576b1a3339f47c420f9c184e49 (patch) | |
tree | ae92cce4888f8cbd038359902a6db6df557fe5cc | |
parent | f160f81a6daae8b478a5547078abc7c7b29ef747 (diff) |
Give characters a location, and replace the Locations view+controller with a Look view+controller
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | app/controllers/game_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/locations_controller.rb | 9 | ||||
-rw-r--r-- | app/controllers/look_controller.rb | 5 | ||||
-rw-r--r-- | app/models/character.rb | 1 | ||||
-rw-r--r-- | app/models/location.rb | 1 | ||||
-rw-r--r-- | app/views/application/_navbar.html.erb | 2 | ||||
-rw-r--r-- | app/views/locations/index.html.erb | 8 | ||||
-rw-r--r-- | app/views/look/look.html.erb (renamed from app/views/locations/show.html.erb) | 0 | ||||
-rw-r--r-- | config/routes.rb | 3 | ||||
-rw-r--r-- | db/migrate/20210706000053_add_location_to_character.rb | 9 | ||||
-rw-r--r-- | db/schema.rb | 5 |
12 files changed, 26 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ddc4737..56cafc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. ### General - A new skill, Aetherweave, has been added. +- Characters now have a location. Correspondingly, the "Locations" menu option and view has been replaced + by a "Look" menu and view. ### Hearth - New amentity: aetherloom (level 1, level 2) diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb index 39ea6c9..4bbbf53 100644 --- a/app/controllers/game_controller.rb +++ b/app/controllers/game_controller.rb @@ -18,7 +18,7 @@ class GameController < ApplicationController def stop_activity current_char.stop_activity - redirect_to locations_path + redirect_to look_path end def finish_activity diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb deleted file mode 100644 index 4616c3d..0000000 --- a/app/controllers/locations_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -class LocationsController < ApplicationController - def index - @locations = Location.all - end - - def show - @location = Location.find(params[:id]) - end -end diff --git a/app/controllers/look_controller.rb b/app/controllers/look_controller.rb new file mode 100644 index 0000000..e604670 --- /dev/null +++ b/app/controllers/look_controller.rb @@ -0,0 +1,5 @@ +class LookController < ApplicationController + def look + @location = current_char.location + end +end diff --git a/app/models/character.rb b/app/models/character.rb index 2669626..96dafd0 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -1,6 +1,7 @@ class Character < ApplicationRecord belongs_to :user belongs_to :activity, optional: true + belongs_to :location has_many :title_awards has_many :titles, through: :title_awards belongs_to :active_title, class_name: "Title", optional: true diff --git a/app/models/location.rb b/app/models/location.rb index e008270..7bd1386 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -2,6 +2,7 @@ class Location < ApplicationRecord include HasWhatnot has_many :activities + has_many :characters has_many :monster_spawns validates :gid, :name, presence: true end diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb index e315b42..d80e7b6 100644 --- a/app/views/application/_navbar.html.erb +++ b/app/views/application/_navbar.html.erb @@ -1,7 +1,7 @@ <ul class="py-2 px-2 col-span-12 text-display space-x-2.5"> <% if current_char %> <li class="inline"> - <%= link_to "Locations", locations_path %> + <%= link_to "Look", look_path %> </li> <li class="inline"> <%= link_to "Character", character_path(current_char) %> diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb deleted file mode 100644 index 3c9b837..0000000 --- a/app/views/locations/index.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<h1 class="text-3xl mb-4">Locations</h1> - -<% @locations.each do |location| %> - <div class="my-4"> - <h2 class="text-xl"><%= link_to location.name, location_path(location) %></h2> - <p class="italic"><%= location.description %></p> - </div> -<% end %> diff --git a/app/views/locations/show.html.erb b/app/views/look/look.html.erb index 2f1074a..2f1074a 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/look/look.html.erb diff --git a/config/routes.rb b/config/routes.rb index 6e435f2..26e6666 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,8 +11,9 @@ Rails.application.routes.draw do put "users", to: "devise/registrations#update", as: "user_registration" end + get :look, to: "look#look" + resources :chat_messages, only: [:index, :create] - resources :locations, only: [:index, :show] resources :activities, only: [:index, :show] do get :costs_and_requirements, on: :member end diff --git a/db/migrate/20210706000053_add_location_to_character.rb b/db/migrate/20210706000053_add_location_to_character.rb new file mode 100644 index 0000000..ec71ee8 --- /dev/null +++ b/db/migrate/20210706000053_add_location_to_character.rb @@ -0,0 +1,9 @@ +class AddLocationToCharacter < ActiveRecord::Migration[6.1] + def change + add_reference :characters, :location, foreign_key: true + Character.all.each do |character| + character.update(location_id: Location.find_by_gid("floret").id) + end + change_column :characters, :location_id, :bigint, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 6c503fd..3c6cc28 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_06_16_014044) do +ActiveRecord::Schema.define(version: 2021_07_06_000053) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -86,8 +86,10 @@ ActiveRecord::Schema.define(version: 2021_06_16_014044) do t.integer "defensive_style" t.integer "rested_duration" t.datetime "started_resting_at" + t.bigint "location_id", null: false t.index ["active_title_id"], name: "index_characters_on_active_title_id" t.index ["activity_id"], name: "index_characters_on_activity_id" + t.index ["location_id"], name: "index_characters_on_location_id" t.index ["user_id"], name: "index_characters_on_user_id" end @@ -319,6 +321,7 @@ ActiveRecord::Schema.define(version: 2021_06_16_014044) do add_foreign_key "character_skills", "characters" add_foreign_key "character_skills", "skills" add_foreign_key "characters", "activities" + add_foreign_key "characters", "locations" add_foreign_key "characters", "titles", column: "active_title_id" add_foreign_key "characters", "users" add_foreign_key "chat_messages", "characters", column: "sender_id" |