diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/pokeviewer/application.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/pokeviewer/pokemon.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/pokeviewer/pokemon.js.coffee | 7 | ||||
-rw-r--r-- | app/assets/stylesheets/pokeviewer/pokemon.css.scss | 132 | ||||
-rw-r--r-- | app/controllers/pokeviewer/pokemon_controller.rb | 2 | ||||
-rw-r--r-- | app/models/pokeviewer/pokemon.rb | 19 | ||||
-rw-r--r-- | app/models/pokeviewer/trainer.rb | 27 | ||||
-rw-r--r-- | app/views/pokeviewer/pokemon/index.html.haml | 32 |
8 files changed, 209 insertions, 13 deletions
diff --git a/app/assets/javascripts/pokeviewer/application.js b/app/assets/javascripts/pokeviewer/application.js index e54c646..52d2214 100644 --- a/app/assets/javascripts/pokeviewer/application.js +++ b/app/assets/javascripts/pokeviewer/application.js | |||
@@ -10,4 +10,5 @@ | |||
10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details | 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details |
11 | // about supported directives. | 11 | // about supported directives. |
12 | // | 12 | // |
13 | //= require jquery3 | ||
13 | //= require_tree . | 14 | //= require_tree . |
diff --git a/app/assets/javascripts/pokeviewer/pokemon.js b/app/assets/javascripts/pokeviewer/pokemon.js deleted file mode 100644 index dee720f..0000000 --- a/app/assets/javascripts/pokeviewer/pokemon.js +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | // Place all the behaviors and hooks related to the matching controller here. | ||
2 | // All this logic will automatically be available in application.js. | ||
diff --git a/app/assets/javascripts/pokeviewer/pokemon.js.coffee b/app/assets/javascripts/pokeviewer/pokemon.js.coffee new file mode 100644 index 0000000..f82f196 --- /dev/null +++ b/app/assets/javascripts/pokeviewer/pokemon.js.coffee | |||
@@ -0,0 +1,7 @@ | |||
1 | $ -> | ||
2 | $(".pc-pokemon").mouseover -> | ||
3 | $(this).children(".pc-data").show() | ||
4 | $(".pc-pokemon").mouseout -> | ||
5 | $(this).children(".pc-data").hide() | ||
6 | $(".pc-pokemon").mousemove (event) -> | ||
7 | $(this).children(".pc-data").offset({left: event.pageX + 16, top: event.pageY - 16}) | ||
diff --git a/app/assets/stylesheets/pokeviewer/pokemon.css.scss b/app/assets/stylesheets/pokeviewer/pokemon.css.scss index 1f4c068..6dbb6c8 100644 --- a/app/assets/stylesheets/pokeviewer/pokemon.css.scss +++ b/app/assets/stylesheets/pokeviewer/pokemon.css.scss | |||
@@ -3,6 +3,132 @@ | |||
3 | They will automatically be included in application.css. | 3 | They will automatically be included in application.css. |
4 | */ | 4 | */ |
5 | 5 | ||
6 | .trainer { | ||
7 | margin: 1em; | ||
8 | font-family: 'Power Green'; | ||
9 | width: 758px; | ||
10 | box-sizing: border-box; | ||
11 | background-color: #f7f7f7; | ||
12 | border: 1px solid #999; | ||
13 | -webkit-border-top-left-radius: 6px; | ||
14 | -webkit-border-top-right-radius: 6px; | ||
15 | -moz-border-radius-topleft: 6px; | ||
16 | -moz-border-radius-topright: 6px; | ||
17 | border-top-left-radius: 6px; | ||
18 | border-top-right-radius: 6px; | ||
19 | |||
20 | .trainer-info { | ||
21 | padding: .5em .75em .25em .75em; | ||
22 | -webkit-border-top-left-radius: 6px; | ||
23 | -webkit-border-top-right-radius: 6px; | ||
24 | -moz-border-radius-topleft: 6px; | ||
25 | -moz-border-radius-topright: 6px; | ||
26 | border-top-left-radius: 6px; | ||
27 | border-top-right-radius: 6px; | ||
28 | border-bottom: 1px solid #888; | ||
29 | |||
30 | &.ruby { | ||
31 | background-color: #D67873; | ||
32 | } | ||
33 | |||
34 | &.sapphire { | ||
35 | background-color: #445E9C; | ||
36 | } | ||
37 | |||
38 | &.firered { | ||
39 | background-color: #F5AC78; | ||
40 | } | ||
41 | |||
42 | &.leafgreen { | ||
43 | background-color: #A7DB8D; | ||
44 | } | ||
45 | |||
46 | &.emerald { | ||
47 | background-color: #4E8234; | ||
48 | } | ||
49 | |||
50 | h2 { | ||
51 | margin: 0; | ||
52 | display: inline-block; | ||
53 | font-size: 24px; | ||
54 | } | ||
55 | |||
56 | .tid { | ||
57 | display: inline-block; | ||
58 | font-size: 13px; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | .pc-boxes { | ||
63 | display: flex; | ||
64 | flex-wrap: wrap; | ||
65 | |||
66 | .party { | ||
67 | margin: 0; | ||
68 | |||
69 | li { | ||
70 | display: block; | ||
71 | margin: -5px 0; | ||
72 | |||
73 | .party-icon { | ||
74 | display: inline-block; | ||
75 | vertical-align: middle; | ||
76 | } | ||
77 | |||
78 | .party-name { | ||
79 | vertical-align: sub; | ||
80 | display: inline-block; | ||
81 | margin-left: .25em; | ||
82 | } | ||
83 | |||
84 | a { | ||
85 | color: black; | ||
86 | text-decoration: none; | ||
87 | |||
88 | &:hover { | ||
89 | text-decoration: underline; | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | |||
95 | .pc-box { | ||
96 | margin: .5em; | ||
97 | padding: .5em; | ||
98 | border: 1px solid #ccc; | ||
99 | border-radius: 4px; | ||
100 | width: 236px; | ||
101 | box-sizing: border-box; | ||
102 | |||
103 | h3 { | ||
104 | margin: 0; | ||
105 | text-align: center; | ||
106 | } | ||
107 | |||
108 | .pc-contents { | ||
109 | margin: 0; | ||
110 | |||
111 | .pc-pokemon { | ||
112 | .pc-data { | ||
113 | display: none; | ||
114 | background-color: #111; | ||
115 | color: #fff; | ||
116 | z-index: 1; | ||
117 | padding: .5em; | ||
118 | box-shadow: 0px 0px 2px 1px #B3B3B3; | ||
119 | border-radius: 4px; | ||
120 | position: absolute; | ||
121 | |||
122 | .pc-data-name { | ||
123 | font-weight: bold; | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | |||
6 | .pokemon { | 132 | .pokemon { |
7 | font-family: 'Power Green'; | 133 | font-family: 'Power Green'; |
8 | display: flex; | 134 | display: flex; |
@@ -15,19 +141,19 @@ | |||
15 | .female { | 141 | .female { |
16 | color: red; | 142 | color: red; |
17 | } | 143 | } |
18 | 144 | ||
19 | .pokemon-name { | 145 | .pokemon-name { |
20 | font-weight: bold; | 146 | font-weight: bold; |
21 | } | 147 | } |
22 | 148 | ||
23 | .pokemon-ivs { | 149 | .pokemon-ivs { |
24 | margin: 0 1em; | 150 | margin: 0 1em; |
25 | 151 | ||
26 | th { | 152 | th { |
27 | text-align: center; | 153 | text-align: center; |
28 | padding-right: .5em; | 154 | padding-right: .5em; |
29 | } | 155 | } |
30 | 156 | ||
31 | td { | 157 | td { |
32 | text-align: right; | 158 | text-align: right; |
33 | } | 159 | } |
diff --git a/app/controllers/pokeviewer/pokemon_controller.rb b/app/controllers/pokeviewer/pokemon_controller.rb index aaf6586..ef421ac 100644 --- a/app/controllers/pokeviewer/pokemon_controller.rb +++ b/app/controllers/pokeviewer/pokemon_controller.rb | |||
@@ -3,7 +3,7 @@ require_dependency "pokeviewer/application_controller" | |||
3 | module Pokeviewer | 3 | module Pokeviewer |
4 | class PokemonController < ApplicationController | 4 | class PokemonController < ApplicationController |
5 | def index | 5 | def index |
6 | @pokemon = Pokemon.all | 6 | @trainers = Trainer.all |
7 | end | 7 | end |
8 | 8 | ||
9 | def show | 9 | def show |
diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb index 3975550..d14ea87 100644 --- a/app/models/pokeviewer/pokemon.rb +++ b/app/models/pokeviewer/pokemon.rb | |||
@@ -36,7 +36,7 @@ module Pokeviewer | |||
36 | enumerize :unown_letter, in: [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, | 36 | enumerize :unown_letter, in: [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, |
37 | :l, :m, :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z, | 37 | :l, :m, :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z, |
38 | :question, :exclamation] | 38 | :question, :exclamation] |
39 | 39 | ||
40 | validates :slot, presence: true, | 40 | validates :slot, presence: true, |
41 | uniqueness: { scope: [:trainer_id, :box] }, | 41 | uniqueness: { scope: [:trainer_id, :box] }, |
42 | unless: Proc.new { |a| a.trainer.nil? } | 42 | unless: Proc.new { |a| a.trainer.nil? } |
@@ -46,7 +46,22 @@ module Pokeviewer | |||
46 | end | 46 | end |
47 | 47 | ||
48 | def icon_path | 48 | def icon_path |
49 | "pokeviewer/icons/#{species_id}.png" | 49 | form = "" |
50 | if species_id == 201 | ||
51 | # Handle Unown form | ||
52 | form = "-#{unown_letter}" | ||
53 | elsif species_id == 386 | ||
54 | # Handle Deoxys forms | ||
55 | if trainer.firered? | ||
56 | form = "-attack" | ||
57 | elsif trainer.leafgreen? | ||
58 | form = "-defense" | ||
59 | elsif trainer.emerald? | ||
60 | form = "-speed" | ||
61 | end | ||
62 | end | ||
63 | |||
64 | "pokeviewer/icons/#{species_id}#{form}.png" | ||
50 | end | 65 | end |
51 | 66 | ||
52 | def sprite_path | 67 | def sprite_path |
diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb index edfbd25..d3a5b91 100644 --- a/app/models/pokeviewer/trainer.rb +++ b/app/models/pokeviewer/trainer.rb | |||
@@ -14,5 +14,32 @@ module Pokeviewer | |||
14 | validates :game, presence: true | 14 | validates :game, presence: true |
15 | enumerize :game, in: [:ruby, :sapphire, :firered, :leafgreen, :emerald], | 15 | enumerize :game, in: [:ruby, :sapphire, :firered, :leafgreen, :emerald], |
16 | predicates: true | 16 | predicates: true |
17 | |||
18 | def display_number | ||
19 | number.to_s.rjust(5, '0') | ||
20 | end | ||
21 | |||
22 | def party | ||
23 | pokemon.where(box: nil).order("slot ASC") | ||
24 | end | ||
25 | |||
26 | def boxes | ||
27 | (0..13).map { |i| box(i) } | ||
28 | end | ||
29 | |||
30 | def box(number) | ||
31 | pokes = pokemon.where(box: number).order("slot ASC").to_a | ||
32 | |||
33 | result = [] | ||
34 | (0..29).each do |i| | ||
35 | if pokes.empty? or (pokes.first.slot == i) | ||
36 | result << pokes.shift | ||
37 | else | ||
38 | result << nil | ||
39 | end | ||
40 | end | ||
41 | |||
42 | result | ||
43 | end | ||
17 | end | 44 | end |
18 | end | 45 | end |
diff --git a/app/views/pokeviewer/pokemon/index.html.haml b/app/views/pokeviewer/pokemon/index.html.haml index c613e70..69b6a68 100644 --- a/app/views/pokeviewer/pokemon/index.html.haml +++ b/app/views/pokeviewer/pokemon/index.html.haml | |||
@@ -1,5 +1,27 @@ | |||
1 | %ul | 1 | - @trainers.each do |trainer| |
2 | - @pokemon.each do |p| | 2 | .trainer |
3 | %li | 3 | .trainer-info{ class: trainer.game } |
4 | = link_to p.revisions.last.nickname, p | 4 | %h2= trainer.name |
5 | = image_tag p.icon_path | 5 | %span.tid= trainer.display_number |
6 | .pc-boxes | ||
7 | %ul.party.pc-box | ||
8 | %h3 Party | ||
9 | - trainer.party.each do |p| | ||
10 | %li | ||
11 | %span.party-icon= image_tag p.icon_path | ||
12 | %span.party-name= link_to p.revisions.last.nickname, p | ||
13 | - trainer.boxes.each_with_index do |box,bid| | ||
14 | .pc-box | ||
15 | %h3= "Box #{bid+1}" | ||
16 | %table.pc-contents | ||
17 | - box.each_slice(6) do |row| | ||
18 | %tr | ||
19 | - row.each do |p| | ||
20 | %td.pc-pokemon | ||
21 | - unless p.nil? | ||
22 | = link_to image_tag(p.icon_path), p | ||
23 | .pc-data | ||
24 | .pc-data-name= p.revisions.last.nickname | ||
25 | .pc-data-ot | ||
26 | OT/ | ||
27 | %span{ class: p.ot_gender }>= p.ot_name | ||