diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-01-29 21:13:35 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-01-29 21:13:35 -0500 |
commit | 5ade37d852bd1e96f9451ab98619359a5a048cee (patch) | |
tree | 251c6bf7c24b7be69b2e908590a733a808165e4c /app | |
parent | 30cd66e1521bc760df45908adb2f7d3ba6683900 (diff) | |
download | pokeviewer-5ade37d852bd1e96f9451ab98619359a5a048cee.tar.gz pokeviewer-5ade37d852bd1e96f9451ab98619359a5a048cee.tar.bz2 pokeviewer-5ade37d852bd1e96f9451ab98619359a5a048cee.zip |
Added Pokédex viewing page
Currently a work in progress. The queries used to display the Pokémon for each species are very inefficient. The text at the top of the page is also very specific to the author.
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/stylesheets/pokeviewer/pokedex.scss | 85 | ||||
-rw-r--r-- | app/controllers/pokeviewer/pokedex_controller.rb | 14 | ||||
-rw-r--r-- | app/helpers/pokeviewer/pokedex_helper.rb | 51 | ||||
-rw-r--r-- | app/jobs/pokeviewer/extract_save_data_job.rb | 10 | ||||
-rw-r--r-- | app/models/pokeviewer/pokedex_entry.rb | 6 | ||||
-rw-r--r-- | app/models/pokeviewer/species.rb | 9 | ||||
-rw-r--r-- | app/models/pokeviewer/trainer.rb | 2 | ||||
-rw-r--r-- | app/views/pokeviewer/pokedex/index.html.haml | 4 |
8 files changed, 181 insertions, 0 deletions
diff --git a/app/assets/stylesheets/pokeviewer/pokedex.scss b/app/assets/stylesheets/pokeviewer/pokedex.scss new file mode 100644 index 0000000..5cecb28 --- /dev/null +++ b/app/assets/stylesheets/pokeviewer/pokedex.scss | |||
@@ -0,0 +1,85 @@ | |||
1 | // Place all the styles related to the Pokedex controller here. | ||
2 | // They will automatically be included in application.css. | ||
3 | // You can use Sass (SCSS) here: http://sass-lang.com/ | ||
4 | |||
5 | .pkvd-table { | ||
6 | border-spacing: 5px; | ||
7 | |||
8 | th { | ||
9 | text-align: right; | ||
10 | font-family: 'Power Green'; | ||
11 | font-weight: normal; | ||
12 | padding-right: 0.5em; | ||
13 | |||
14 | img { | ||
15 | image-rendering: pixelated; | ||
16 | } | ||
17 | } | ||
18 | |||
19 | td { | ||
20 | padding: 0 0.5em; | ||
21 | text-align: center; | ||
22 | font-family: 'Power Green'; | ||
23 | |||
24 | &.pkvd-unseen { | ||
25 | border: 1px dashed gray; | ||
26 | color: gray; | ||
27 | } | ||
28 | |||
29 | &.pkvd-seen { | ||
30 | border-width: 3px; | ||
31 | border-style: solid; | ||
32 | font-weight: bold; | ||
33 | |||
34 | &.ruby { | ||
35 | border-color: #D67873; | ||
36 | color: #D67873; | ||
37 | } | ||
38 | |||
39 | &.sapphire { | ||
40 | border-color: #445E9C; | ||
41 | color: #445E9C; | ||
42 | } | ||
43 | |||
44 | &.firered { | ||
45 | border-color: #F5AC78; | ||
46 | color: #F5AC78; | ||
47 | } | ||
48 | |||
49 | &.leafgreen { | ||
50 | border-color: #A7DB8D; | ||
51 | color: #A7DB8D; | ||
52 | } | ||
53 | |||
54 | &.emerald { | ||
55 | border-color: #4E8234; | ||
56 | color: #4E8234; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | &.pkvd-caught { | ||
61 | color: black; | ||
62 | font-weight: bold; | ||
63 | |||
64 | &.ruby { | ||
65 | background-color: #D67873; | ||
66 | } | ||
67 | |||
68 | &.sapphire { | ||
69 | background-color: #445E9C; | ||
70 | } | ||
71 | |||
72 | &.firered { | ||
73 | background-color: #F5AC78; | ||
74 | } | ||
75 | |||
76 | &.leafgreen { | ||
77 | background-color: #A7DB8D; | ||
78 | } | ||
79 | |||
80 | &.emerald { | ||
81 | background-color: #4E8234; | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | } | ||
diff --git a/app/controllers/pokeviewer/pokedex_controller.rb b/app/controllers/pokeviewer/pokedex_controller.rb new file mode 100644 index 0000000..8286977 --- /dev/null +++ b/app/controllers/pokeviewer/pokedex_controller.rb | |||
@@ -0,0 +1,14 @@ | |||
1 | require_dependency "pokeviewer/application_controller" | ||
2 | |||
3 | module Pokeviewer | ||
4 | class PokedexController < ApplicationController | ||
5 | def index | ||
6 | @species = Species. | ||
7 | order(id: :asc). | ||
8 | includes(:pokedex_entries). | ||
9 | order("pokeviewer_pokedex_entries.trainer_id ASC") | ||
10 | |||
11 | @trainers = Trainer.order(id: :asc) | ||
12 | end | ||
13 | end | ||
14 | end | ||
diff --git a/app/helpers/pokeviewer/pokedex_helper.rb b/app/helpers/pokeviewer/pokedex_helper.rb new file mode 100644 index 0000000..fe3e575 --- /dev/null +++ b/app/helpers/pokeviewer/pokedex_helper.rb | |||
@@ -0,0 +1,51 @@ | |||
1 | module Pokeviewer | ||
2 | module PokedexHelper | ||
3 | |||
4 | def pokedex_table(all_species, trainers) | ||
5 | final_result = "".html_safe | ||
6 | |||
7 | all_species.each do |species| | ||
8 | noted_trainers = species.pokedex_entries.to_a | ||
9 | |||
10 | if noted_trainers.empty? | ||
11 | poke_name = "???" | ||
12 | poke_image = image_tag "pokeviewer/icons/0.png" | ||
13 | else | ||
14 | poke_name = species.name | ||
15 | poke_image = image_tag "pokeviewer/icons/#{species.id}.png" | ||
16 | end | ||
17 | |||
18 | result = "".html_safe | ||
19 | |||
20 | result << tag.th("\##{species.id}") | ||
21 | result << tag.th(poke_name) | ||
22 | result << tag.th(poke_image) | ||
23 | |||
24 | trainers.each do |trainer| | ||
25 | if !noted_trainers.empty? and noted_trainers.first.trainer_id == trainer.id | ||
26 | nt = noted_trainers.shift | ||
27 | |||
28 | if nt.caught | ||
29 | result << tag.td(trainer.display_number, | ||
30 | class: ["pkvd-caught", trainer.game]) | ||
31 | else | ||
32 | result << tag.td(trainer.display_number, | ||
33 | class: ["pkvd-seen", trainer.game]) | ||
34 | end | ||
35 | else | ||
36 | result << tag.td(trainer.display_number, class: "pkvd-unseen") | ||
37 | end | ||
38 | end | ||
39 | |||
40 | result << tag.td( | ||
41 | species.current_revisions.map { | ||
42 | |p| link_to p.nickname, p.pokemon }.join(", ").html_safe) | ||
43 | |||
44 | final_result << tag.tr(result) | ||
45 | end | ||
46 | |||
47 | tag.table(final_result, class: "pkvd-table") | ||
48 | end | ||
49 | |||
50 | end | ||
51 | end | ||
diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb index b0999ef..bb18d68 100644 --- a/app/jobs/pokeviewer/extract_save_data_job.rb +++ b/app/jobs/pokeviewer/extract_save_data_job.rb | |||
@@ -173,6 +173,16 @@ module Pokeviewer | |||
173 | rev.save! | 173 | rev.save! |
174 | end | 174 | end |
175 | end | 175 | end |
176 | |||
177 | game.pokedex_entries.clear | ||
178 | |||
179 | args["seen"].each do |param| | ||
180 | game.pokedex_entries.create(species_id: param, caught: false) | ||
181 | end | ||
182 | |||
183 | args["caught"].each do |param| | ||
184 | game.pokedex_entries.create(species_id: param, caught: true) | ||
185 | end | ||
176 | end | 186 | end |
177 | end | 187 | end |
178 | end | 188 | end |
diff --git a/app/models/pokeviewer/pokedex_entry.rb b/app/models/pokeviewer/pokedex_entry.rb new file mode 100644 index 0000000..9be6a6a --- /dev/null +++ b/app/models/pokeviewer/pokedex_entry.rb | |||
@@ -0,0 +1,6 @@ | |||
1 | module Pokeviewer | ||
2 | class PokedexEntry < ApplicationRecord | ||
3 | belongs_to :trainer | ||
4 | belongs_to :species | ||
5 | end | ||
6 | end | ||
diff --git a/app/models/pokeviewer/species.rb b/app/models/pokeviewer/species.rb index aae66cc..400d679 100644 --- a/app/models/pokeviewer/species.rb +++ b/app/models/pokeviewer/species.rb | |||
@@ -4,6 +4,8 @@ module Pokeviewer | |||
4 | 4 | ||
5 | has_many :revisions, dependent: :restrict_with_exception | 5 | has_many :revisions, dependent: :restrict_with_exception |
6 | 6 | ||
7 | has_many :pokedex_entries, dependent: :destroy | ||
8 | |||
7 | validates :name, presence: true, uniqueness: true | 9 | validates :name, presence: true, uniqueness: true |
8 | 10 | ||
9 | validates :type_1, presence: true | 11 | validates :type_1, presence: true |
@@ -13,5 +15,12 @@ module Pokeviewer | |||
13 | 15 | ||
14 | belongs_to :ability_1, class_name: "Ability" | 16 | belongs_to :ability_1, class_name: "Ability" |
15 | belongs_to :ability_2, class_name: "Ability", optional: true | 17 | belongs_to :ability_2, class_name: "Ability", optional: true |
18 | |||
19 | def current_revisions | ||
20 | revisions. | ||
21 | where("pokeviewer_pokemon.current_id = pokeviewer_revisions.id"). | ||
22 | includes(:pokemon). | ||
23 | references(:pokemon) | ||
24 | end | ||
16 | end | 25 | end |
17 | end | 26 | end |
diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb index 0ea12c8..950dac0 100644 --- a/app/models/pokeviewer/trainer.rb +++ b/app/models/pokeviewer/trainer.rb | |||
@@ -4,6 +4,8 @@ module Pokeviewer | |||
4 | 4 | ||
5 | has_many :pokemon, dependent: :nullify | 5 | has_many :pokemon, dependent: :nullify |
6 | 6 | ||
7 | has_many :pokedex_entries, dependent: :destroy | ||
8 | |||
7 | validates :number, presence: true, | 9 | validates :number, presence: true, |
8 | numericality: { greater_than_or_equal_to: 0, only_integer: true } | 10 | numericality: { greater_than_or_equal_to: 0, only_integer: true } |
9 | 11 | ||
diff --git a/app/views/pokeviewer/pokedex/index.html.haml b/app/views/pokeviewer/pokedex/index.html.haml new file mode 100644 index 0000000..676cd9f --- /dev/null +++ b/app/views/pokeviewer/pokedex/index.html.haml | |||
@@ -0,0 +1,4 @@ | |||
1 | %h3 Fef's Pokédex | ||
2 | %p The following table shows my progress toward completing the Pokémon National Pokédex in generation III. Because I am playing multiple games, the progress is shown for each specific game. The columns are colored based on what game they are for: dark red for Ruby, dark blue for Sapphire, dark green for Emerald, light red for FireRed, and light green for LeafGreen. The cells also contain the trainer ID for that game. | ||
3 | %p If a cell is grayed out, that means that game has not encountered that Pokémon species yet. If a cell has a colored border but is not filled in, that means that game has seen the given species but not caught it. A filled in cell means that the game has recorded data on that species. If a species has not been seen in any of the save files, the name and image of the species is not shown. | ||
4 | = pokedex_table @species, @trainers | ||