diff options
Diffstat (limited to 'app/helpers')
| -rw-r--r-- | app/helpers/application_helper.rb | 2 | ||||
| -rw-r--r-- | app/helpers/pokedex_helper.rb | 49 | ||||
| -rw-r--r-- | app/helpers/pokemon_helper.rb | 206 | ||||
| -rw-r--r-- | app/helpers/pokeviewer/application_helper.rb | 4 | ||||
| -rw-r--r-- | app/helpers/pokeviewer/pokedex_helper.rb | 51 | ||||
| -rw-r--r-- | app/helpers/pokeviewer/pokemon_helper.rb | 208 |
6 files changed, 257 insertions, 263 deletions
| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/app/helpers/application_helper.rb | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | module ApplicationHelper | ||
| 2 | end | ||
| diff --git a/app/helpers/pokedex_helper.rb b/app/helpers/pokedex_helper.rb new file mode 100644 index 0000000..d6fe104 --- /dev/null +++ b/app/helpers/pokedex_helper.rb | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | module PokedexHelper | ||
| 2 | |||
| 3 | def pokedex_table(all_species, trainers) | ||
| 4 | final_result = "".html_safe | ||
| 5 | |||
| 6 | all_species.each do |species| | ||
| 7 | noted_trainers = species.pokedex_entries.to_a | ||
| 8 | |||
| 9 | if noted_trainers.empty? | ||
| 10 | poke_name = "???" | ||
| 11 | poke_image = image_tag "icons/0.png" | ||
| 12 | else | ||
| 13 | poke_name = species.name | ||
| 14 | poke_image = image_tag "icons/#{species.id}.png" | ||
| 15 | end | ||
| 16 | |||
| 17 | result = "".html_safe | ||
| 18 | |||
| 19 | result << tag.th("\##{species.id}") | ||
| 20 | result << tag.th(poke_name) | ||
| 21 | result << tag.th(poke_image) | ||
| 22 | |||
| 23 | trainers.each do |trainer| | ||
| 24 | if !noted_trainers.empty? and noted_trainers.first.trainer_id == trainer.id | ||
| 25 | nt = noted_trainers.shift | ||
| 26 | |||
| 27 | if nt.caught | ||
| 28 | result << tag.td(trainer.display_number, | ||
| 29 | class: ["pkvd-caught", trainer.game]) | ||
| 30 | else | ||
| 31 | result << tag.td(trainer.display_number, | ||
| 32 | class: ["pkvd-seen", trainer.game]) | ||
| 33 | end | ||
| 34 | else | ||
| 35 | result << tag.td(trainer.display_number, class: "pkvd-unseen") | ||
| 36 | end | ||
| 37 | end | ||
| 38 | |||
| 39 | result << tag.td( | ||
| 40 | species.current_revisions.map { | ||
| 41 | |p| link_to p.nickname, p.pokemon }.join(", ").html_safe) | ||
| 42 | |||
| 43 | final_result << tag.tr(result) | ||
| 44 | end | ||
| 45 | |||
| 46 | tag.table(final_result, class: "pkvd-table") | ||
| 47 | end | ||
| 48 | |||
| 49 | end | ||
| diff --git a/app/helpers/pokemon_helper.rb b/app/helpers/pokemon_helper.rb new file mode 100644 index 0000000..092adc4 --- /dev/null +++ b/app/helpers/pokemon_helper.rb | |||
| @@ -0,0 +1,206 @@ | |||
| 1 | require 'victor' | ||
| 2 | |||
| 3 | module PokemonHelper | ||
| 4 | |||
| 5 | def condition_diagram(revision) | ||
| 6 | svg = Victor::SVG.new width: 420, height: 430 | ||
| 7 | |||
| 8 | center_x = 200 | ||
| 9 | center_y = 200 | ||
| 10 | radius = 160 | ||
| 11 | |||
| 12 | angle = -Math::PI / 2.0 | ||
| 13 | incr = (2 * Math::PI) / 5 | ||
| 14 | |||
| 15 | data = [ | ||
| 16 | [:cool, revision.coolness], | ||
| 17 | [:beauty, revision.beauty], | ||
| 18 | [:cute, revision.cuteness], | ||
| 19 | [:smart, revision.smartness], | ||
| 20 | [:tough, revision.toughness] | ||
| 21 | ] | ||
| 22 | |||
| 23 | outline = data.map do |c| | ||
| 24 | x_offset = radius * Math.cos(angle) | ||
| 25 | y_offset = radius * Math.sin(angle) | ||
| 26 | |||
| 27 | svg.circle( | ||
| 28 | cx: (center_x + x_offset), | ||
| 29 | cy: (center_y + y_offset), | ||
| 30 | r: 53, | ||
| 31 | class: "pkcv-#{c[0]}-circle") | ||
| 32 | |||
| 33 | if c[0] == :cool | ||
| 34 | text_y = center_y + (radius + 20) * Math.sin(angle) | ||
| 35 | else | ||
| 36 | text_y = center_y + (radius + 60) * Math.sin(angle) | ||
| 37 | end | ||
| 38 | |||
| 39 | svg.text(c[0].upcase, | ||
| 40 | x: (center_x + (radius + 60) * Math.cos(angle)), | ||
| 41 | y: text_y, | ||
| 42 | class: "pkcv-label-outline") | ||
| 43 | |||
| 44 | svg.text(c[0].upcase, | ||
| 45 | x: (center_x + (radius + 60) * Math.cos(angle)), | ||
| 46 | y: text_y, | ||
| 47 | class: "pkcv-label") | ||
| 48 | |||
| 49 | angle += incr | ||
| 50 | |||
| 51 | [center_x + x_offset, center_y + y_offset] | ||
| 52 | end | ||
| 53 | |||
| 54 | svg.polygon( | ||
| 55 | points: outline.map { |point| point * "," } * " ", | ||
| 56 | class: "pkcv-outline") | ||
| 57 | |||
| 58 | points = data.map do |c| | ||
| 59 | svg.line( | ||
| 60 | x1: center_x, | ||
| 61 | y1: center_y, | ||
| 62 | x2: center_x + radius * Math.cos(angle), | ||
| 63 | y2: center_y + radius * Math.sin(angle), | ||
| 64 | class: "pkcv-line") | ||
| 65 | |||
| 66 | datapoint = c[1] | ||
| 67 | datapoint = 0.01 if datapoint < 1 | ||
| 68 | datapoint /= 10.0 | ||
| 69 | datapoint **= (1.0/3.0) | ||
| 70 | |||
| 71 | x_offset = (radius - 3) * Math.cos(angle) * datapoint | ||
| 72 | y_offset = (radius - 3) * Math.sin(angle) * datapoint | ||
| 73 | |||
| 74 | angle += incr | ||
| 75 | |||
| 76 | [center_x + x_offset, center_y + y_offset] | ||
| 77 | end | ||
| 78 | |||
| 79 | svg.polygon( | ||
| 80 | points: points.map { |point| point * "," } * " ", | ||
| 81 | class: "pkcv-data") | ||
| 82 | |||
| 83 | svg.rect( | ||
| 84 | x: -40, | ||
| 85 | y: 460, | ||
| 86 | rx: 10, | ||
| 87 | ry: 10, | ||
| 88 | width: 490, | ||
| 89 | height: 60, | ||
| 90 | class: "pkcv-sheen-bg") | ||
| 91 | |||
| 92 | if revision.sheen > 0 | ||
| 93 | svg.rect( | ||
| 94 | x: -37, | ||
| 95 | y: 460, | ||
| 96 | width: revision.sheen * 490 / 10 - 6, | ||
| 97 | height: 60, | ||
| 98 | class: "pkcv-sheen-data") | ||
| 99 | end | ||
| 100 | |||
| 101 | svg.rect( | ||
| 102 | x: -40, | ||
| 103 | y: 460, | ||
| 104 | rx: 10, | ||
| 105 | ry: 10, | ||
| 106 | width: 490, | ||
| 107 | height: 60, | ||
| 108 | class: "pkcv-sheen-border") | ||
| 109 | |||
| 110 | svg.text("SHEEN", | ||
| 111 | x: -20, | ||
| 112 | y: 500, | ||
| 113 | class: "pkcv-sheen-label") | ||
| 114 | |||
| 115 | tag.svg(svg.to_s.html_safe, | ||
| 116 | viewBox: "-80 -30 570 560", | ||
| 117 | width: "100%", | ||
| 118 | class: "pokemon-condition") | ||
| 119 | end | ||
| 120 | |||
| 121 | def image_for_type(type) | ||
| 122 | image_tag "types/#{type}.gif", class: "pkv-type" | ||
| 123 | end | ||
| 124 | |||
| 125 | def move_details(revision, index) | ||
| 126 | move = revision.send "move_#{index}".intern | ||
| 127 | |||
| 128 | if move | ||
| 129 | move_name = move.name | ||
| 130 | move_type = image_for_type move.move_type | ||
| 131 | move_pp = revision.send "move_#{index}_pp".intern | ||
| 132 | move_pp = "#{move_pp}/#{move_pp}" | ||
| 133 | else | ||
| 134 | move_name = "-" | ||
| 135 | move_type = "" | ||
| 136 | move_pp = "--/--" | ||
| 137 | end | ||
| 138 | |||
| 139 | tag.tr( | ||
| 140 | tag.th(move_type) + | ||
| 141 | tag.td(move_name)) + | ||
| 142 | tag.tr( | ||
| 143 | tag.th("") + | ||
| 144 | tag.td( | ||
| 145 | tag.div( | ||
| 146 | tag.span( | ||
| 147 | "PP", | ||
| 148 | class: 'pp-label') + | ||
| 149 | tag.span( | ||
| 150 | move_pp, | ||
| 151 | class: 'pp-value') + | ||
| 152 | tag.div( | ||
| 153 | "", | ||
| 154 | class: 'clear'), | ||
| 155 | class: 'tb-only'))) | ||
| 156 | end | ||
| 157 | |||
| 158 | def display_met(pokemon) | ||
| 159 | met_type = pokemon.met_type | ||
| 160 | |||
| 161 | if met_type == :normal or met_type == :hatched | ||
| 162 | result = "".html_safe | ||
| 163 | |||
| 164 | if met_type == :normal | ||
| 165 | if pokemon.outsider? | ||
| 166 | result << "Apparently met" | ||
| 167 | else | ||
| 168 | result << "Met" | ||
| 169 | end | ||
| 170 | else | ||
| 171 | if pokemon.outsider? | ||
| 172 | result << "Apparently hatched" | ||
| 173 | else | ||
| 174 | result << "Hatched" | ||
| 175 | end | ||
| 176 | end | ||
| 177 | |||
| 178 | result << " in " | ||
| 179 | |||
| 180 | pokemon.location.name.split(" ").each_with_index do |w, i| | ||
| 181 | result << " ".html_safe if i > 0 | ||
| 182 | result << w | ||
| 183 | end | ||
| 184 | |||
| 185 | result << " at Lv. ".html_safe | ||
| 186 | |||
| 187 | if met_type == :hatched | ||
| 188 | result << "5" | ||
| 189 | else | ||
| 190 | result << pokemon.met_level.to_s | ||
| 191 | end | ||
| 192 | |||
| 193 | result << "." | ||
| 194 | |||
| 195 | result | ||
| 196 | elsif met_type == :npc_trade | ||
| 197 | "Met in a trade." | ||
| 198 | elsif met_type == :fateful_encounter | ||
| 199 | "Met in a fateful encounter at Lv. ".html_safe + | ||
| 200 | pokemon.met_level.to_s | ||
| 201 | elsif met_type == :orre | ||
| 202 | "Met in a trade." | ||
| 203 | end | ||
| 204 | end | ||
| 205 | |||
| 206 | end | ||
| diff --git a/app/helpers/pokeviewer/application_helper.rb b/app/helpers/pokeviewer/application_helper.rb deleted file mode 100644 index 40557f2..0000000 --- a/app/helpers/pokeviewer/application_helper.rb +++ /dev/null | |||
| @@ -1,4 +0,0 @@ | |||
| 1 | module Pokeviewer | ||
| 2 | module ApplicationHelper | ||
| 3 | end | ||
| 4 | end | ||
| diff --git a/app/helpers/pokeviewer/pokedex_helper.rb b/app/helpers/pokeviewer/pokedex_helper.rb deleted file mode 100644 index fe3e575..0000000 --- a/app/helpers/pokeviewer/pokedex_helper.rb +++ /dev/null | |||
| @@ -1,51 +0,0 @@ | |||
| 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/helpers/pokeviewer/pokemon_helper.rb b/app/helpers/pokeviewer/pokemon_helper.rb deleted file mode 100644 index 4c2f9de..0000000 --- a/app/helpers/pokeviewer/pokemon_helper.rb +++ /dev/null | |||
| @@ -1,208 +0,0 @@ | |||
| 1 | require 'victor' | ||
| 2 | |||
| 3 | module Pokeviewer | ||
| 4 | module PokemonHelper | ||
| 5 | |||
| 6 | def condition_diagram(revision) | ||
| 7 | svg = Victor::SVG.new width: 420, height: 430 | ||
| 8 | |||
| 9 | center_x = 200 | ||
| 10 | center_y = 200 | ||
| 11 | radius = 160 | ||
| 12 | |||
| 13 | angle = -Math::PI / 2.0 | ||
| 14 | incr = (2 * Math::PI) / 5 | ||
| 15 | |||
| 16 | data = [ | ||
| 17 | [:cool, revision.coolness], | ||
| 18 | [:beauty, revision.beauty], | ||
| 19 | [:cute, revision.cuteness], | ||
| 20 | [:smart, revision.smartness], | ||
| 21 | [:tough, revision.toughness] | ||
| 22 | ] | ||
| 23 | |||
| 24 | outline = data.map do |c| | ||
| 25 | x_offset = radius * Math.cos(angle) | ||
| 26 | y_offset = radius * Math.sin(angle) | ||
| 27 | |||
| 28 | svg.circle( | ||
| 29 | cx: (center_x + x_offset), | ||
| 30 | cy: (center_y + y_offset), | ||
| 31 | r: 53, | ||
| 32 | class: "pkcv-#{c[0]}-circle") | ||
| 33 | |||
| 34 | if c[0] == :cool | ||
| 35 | text_y = center_y + (radius + 20) * Math.sin(angle) | ||
| 36 | else | ||
| 37 | text_y = center_y + (radius + 60) * Math.sin(angle) | ||
| 38 | end | ||
| 39 | |||
| 40 | svg.text(c[0].upcase, | ||
| 41 | x: (center_x + (radius + 60) * Math.cos(angle)), | ||
| 42 | y: text_y, | ||
| 43 | class: "pkcv-label-outline") | ||
| 44 | |||
| 45 | svg.text(c[0].upcase, | ||
| 46 | x: (center_x + (radius + 60) * Math.cos(angle)), | ||
| 47 | y: text_y, | ||
| 48 | class: "pkcv-label") | ||
| 49 | |||
| 50 | angle += incr | ||
| 51 | |||
| 52 | [center_x + x_offset, center_y + y_offset] | ||
| 53 | end | ||
| 54 | |||
| 55 | svg.polygon( | ||
| 56 | points: outline.map { |point| point * "," } * " ", | ||
| 57 | class: "pkcv-outline") | ||
| 58 | |||
| 59 | points = data.map do |c| | ||
| 60 | svg.line( | ||
| 61 | x1: center_x, | ||
| 62 | y1: center_y, | ||
| 63 | x2: center_x + radius * Math.cos(angle), | ||
| 64 | y2: center_y + radius * Math.sin(angle), | ||
| 65 | class: "pkcv-line") | ||
| 66 | |||
| 67 | datapoint = c[1] | ||
| 68 | datapoint = 0.01 if datapoint < 1 | ||
| 69 | datapoint /= 10.0 | ||
| 70 | datapoint **= (1.0/3.0) | ||
| 71 | |||
| 72 | x_offset = (radius - 3) * Math.cos(angle) * datapoint | ||
| 73 | y_offset = (radius - 3) * Math.sin(angle) * datapoint | ||
| 74 | |||
| 75 | angle += incr | ||
| 76 | |||
| 77 | [center_x + x_offset, center_y + y_offset] | ||
| 78 | end | ||
| 79 | |||
| 80 | svg.polygon( | ||
| 81 | points: points.map { |point| point * "," } * " ", | ||
| 82 | class: "pkcv-data") | ||
| 83 | |||
| 84 | svg.rect( | ||
| 85 | x: -40, | ||
| 86 | y: 460, | ||
| 87 | rx: 10, | ||
| 88 | ry: 10, | ||
| 89 | width: 490, | ||
| 90 | height: 60, | ||
| 91 | class: "pkcv-sheen-bg") | ||
| 92 | |||
| 93 | if revision.sheen > 0 | ||
| 94 | svg.rect( | ||
| 95 | x: -37, | ||
| 96 | y: 460, | ||
| 97 | width: revision.sheen * 490 / 10 - 6, | ||
| 98 | height: 60, | ||
| 99 | class: "pkcv-sheen-data") | ||
| 100 | end | ||
| 101 | |||
| 102 | svg.rect( | ||
| 103 | x: -40, | ||
| 104 | y: 460, | ||
| 105 | rx: 10, | ||
| 106 | ry: 10, | ||
| 107 | width: 490, | ||
| 108 | height: 60, | ||
| 109 | class: "pkcv-sheen-border") | ||
| 110 | |||
| 111 | svg.text("SHEEN", | ||
| 112 | x: -20, | ||
| 113 | y: 500, | ||
| 114 | class: "pkcv-sheen-label") | ||
| 115 | |||
| 116 | tag.svg(svg.to_s.html_safe, | ||
| 117 | viewBox: "-80 -30 570 560", | ||
| 118 | width: "100%", | ||
| 119 | class: "pokemon-condition") | ||
| 120 | end | ||
| 121 | |||
| 122 | def image_for_type(type) | ||
| 123 | image_tag "pokeviewer/types/#{type}.gif", class: "pkv-type" | ||
| 124 | end | ||
| 125 | |||
| 126 | def move_details(revision, index) | ||
| 127 | move = revision.send "move_#{index}".intern | ||
| 128 | |||
| 129 | if move | ||
| 130 | move_name = move.name | ||
| 131 | move_type = image_for_type move.move_type | ||
| 132 | move_pp = revision.send "move_#{index}_pp".intern | ||
| 133 | move_pp = "#{move_pp}/#{move_pp}" | ||
| 134 | else | ||
| 135 | move_name = "-" | ||
| 136 | move_type = "" | ||
| 137 | move_pp = "--/--" | ||
| 138 | end | ||
| 139 | |||
| 140 | tag.tr( | ||
| 141 | tag.th(move_type) + | ||
| 142 | tag.td(move_name)) + | ||
| 143 | tag.tr( | ||
| 144 | tag.th("") + | ||
| 145 | tag.td( | ||
| 146 | tag.div( | ||
| 147 | tag.span( | ||
| 148 | "PP", | ||
| 149 | class: 'pp-label') + | ||
| 150 | tag.span( | ||
| 151 | move_pp, | ||
| 152 | class: 'pp-value') + | ||
| 153 | tag.div( | ||
| 154 | "", | ||
| 155 | class: 'clear'), | ||
| 156 | class: 'tb-only'))) | ||
| 157 | end | ||
| 158 | |||
| 159 | def display_met(pokemon) | ||
| 160 | met_type = pokemon.met_type | ||
| 161 | |||
| 162 | if met_type == :normal or met_type == :hatched | ||
| 163 | result = "".html_safe | ||
| 164 | |||
| 165 | if met_type == :normal | ||
| 166 | if pokemon.outsider? | ||
| 167 | result << "Apparently met" | ||
| 168 | else | ||
| 169 | result << "Met" | ||
| 170 | end | ||
| 171 | else | ||
| 172 | if pokemon.outsider? | ||
| 173 | result << "Apparently hatched" | ||
| 174 | else | ||
| 175 | result << "Hatched" | ||
| 176 | end | ||
| 177 | end | ||
| 178 | |||
| 179 | result << " in " | ||
| 180 | |||
| 181 | pokemon.location.name.split(" ").each_with_index do |w, i| | ||
| 182 | result << " ".html_safe if i > 0 | ||
| 183 | result << w | ||
| 184 | end | ||
| 185 | |||
| 186 | result << " at Lv. ".html_safe | ||
| 187 | |||
| 188 | if met_type == :hatched | ||
| 189 | result << "5" | ||
| 190 | else | ||
| 191 | result << pokemon.met_level.to_s | ||
| 192 | end | ||
| 193 | |||
| 194 | result << "." | ||
| 195 | |||
| 196 | result | ||
| 197 | elsif met_type == :npc_trade | ||
| 198 | "Met in a trade." | ||
| 199 | elsif met_type == :fateful_encounter | ||
| 200 | "Met in a fateful encounter at Lv. ".html_safe + | ||
| 201 | pokemon.met_level.to_s | ||
| 202 | elsif met_type == :orre | ||
| 203 | "Met in a trade." | ||
| 204 | end | ||
| 205 | end | ||
| 206 | |||
| 207 | end | ||
| 208 | end | ||
