diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-07 11:49:49 -0500 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-07 11:49:49 -0500 |
| commit | 56f5841d4b9c12296cdfcaeff174b2627d59afc8 (patch) | |
| tree | 4f7da4ebbe5ee15a1594b26466ed78e2cf10de35 /app/helpers/pokemon_helper.rb | |
| parent | c1b0443ba2aebdbd39291ddab0c189f3f4831320 (diff) | |
| download | pokeviewer-56f5841d4b9c12296cdfcaeff174b2627d59afc8.tar.gz pokeviewer-56f5841d4b9c12296cdfcaeff174b2627d59afc8.tar.bz2 pokeviewer-56f5841d4b9c12296cdfcaeff174b2627d59afc8.zip | |
Migrate to full rails app
Diffstat (limited to 'app/helpers/pokemon_helper.rb')
| -rw-r--r-- | app/helpers/pokemon_helper.rb | 206 |
1 files changed, 206 insertions, 0 deletions
| 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 | ||
