about summary refs log tree commit diff stats
path: root/app/helpers/pokeviewer/pokemon_helper.rb
blob: 9524914f18250766c80e50eacc6acdc394b640b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
require 'victor'

module Pokeviewer
  module PokemonHelper

    def condition_diagram(revision)
      svg = Victor::SVG.new width: 420, height: 430

      center_x = 200
      center_y = 200
      radius = 160

      angle = -Math::PI / 2.0
      incr = (2 * Math::PI) / 5

      data = [
        [:cool, revision.coolness],
        [:beauty, revision.beauty],
        [:cute, revision.cuteness],
        [:smart, revision.smartness],
        [:tough, revision.toughness]
      ]

      outline = data.map do |c|
        x_offset = radius * Math.cos(angle)
        y_offset = radius * Math.sin(angle)

        svg.circle(
          cx: (center_x + x_offset),
          cy: (center_y + y_offset),
          r: 53,
          class: "pkcv-#{c[0]}-circle")

        if c[0] == :cool
          text_y = center_y + (radius + 20) * Math.sin(angle)
        else
          text_y = center_y + (radius + 60) * Math.sin(angle)
        end

        svg.text(c[0].upcase,
          x: (center_x + (radius + 60) * Math.cos(angle)),
          y: text_y,
          class: "pkcv-label-outline")

        svg.text(c[0].upcase,
          x: (center_x + (radius + 60) * Math.cos(angle)),
          y: text_y,
          class: "pkcv-label")

        angle += incr

        [center_x + x_offset, center_y + y_offset]
      end

      svg.polygon(
        points: outline.map { |point| point * "," } * " ",
        class: "pkcv-outline")

      points = data.map do |c|
        svg.line(
          x1: center_x,
          y1: center_y,
          x2: center_x + radius * Math.cos(angle),
          y2: center_y + radius * Math.sin(angle),
          class: "pkcv-line")

        datapoint = c[1]
        datapoint = 0.01 if datapoint < 1
        datapoint /= 10.0
        datapoint **= (1.0/3.0)

        x_offset = (radius - 3) * Math.cos(angle) * datapoint
        y_offset = (radius - 3) * Math.sin(angle) * datapoint

        angle += incr

        [center_x + x_offset, center_y + y_offset]
      end

      svg.polygon(
        points: points.map { |point| point * "," } * " ",
        class: "pkcv-data")

      tag.svg(svg.to_s.html_safe,
        viewBox: "-80 -30 570 430",
        width: "100%",
        class: "pokemon-condition")
    end

    def image_for_type(type)
      image_tag "pokeviewer/types/#{type}.gif"
    end

    def move_details(revision, index)
      move = revision.send "move_#{index}".intern

      if move
        move_name = move.name
        move_type = image_for_type move.move_type
        move_pp = revision.send "move_#{index}_pp".intern
        move_pp = "#{move_pp}/#{move_pp}"
      else
        move_name = "-"
        move_type = ""
        move_pp = "--/--"
      end

      tag.tr(
        tag.th(move_type) +
        tag.td(move_name)) +
      tag.tr(
        tag.th("") +
        tag.td(
          tag.div(
            tag.span(
              "PP",
              class: 'pp-label') +
            tag.span(
              move_pp,
              class: 'pp-value') +
            tag.div(
              "",
              class: 'clear'),
            class: 'tb-only')))
    end

    def display_met(pokemon)
      met_type = pokemon.met_type

      if met_type == :normal or met_type == :hatched
        result = "".html_safe

        if met_type == :normal
          if pokemon.outsider?
            result << "Apparently met"
          else
            result << "Met"
          end
        else
          if pokemon.outsider?
            result << "Apparently hatched"
          else
            result << "Hatched"
          end
        end

        result << " in "

        pokemon.location.name.split(" ").each_with_index do |w, i|
          result << "&nbsp;".html_safe if i > 0
          result << w
        end

        result << " at Lv.&nbsp;".html_safe

        if met_type == :hatched
          result << "5"
        else
          result << pokemon.met_level.to_s
        end

        result << "."

        result
      elsif met_type == :npc_trade
        "Met in a trade."
      elsif met_type == :fateful_encounter
        "Obtained in a fateful encounter at Lv.&nbsp;".html_safe +
          pokemon.met_level.to_s
      elsif met_type == :orre
        "Met in a trade."
      end
    end

  end
end