From 56f5841d4b9c12296cdfcaeff174b2627d59afc8 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 7 Dec 2024 11:49:49 -0500 Subject: Migrate to full rails app --- app/helpers/application_helper.rb | 2 + app/helpers/pokedex_helper.rb | 49 +++++++ app/helpers/pokemon_helper.rb | 206 ++++++++++++++++++++++++++ app/helpers/pokeviewer/application_helper.rb | 4 - app/helpers/pokeviewer/pokedex_helper.rb | 51 ------- app/helpers/pokeviewer/pokemon_helper.rb | 208 --------------------------- 6 files changed, 257 insertions(+), 263 deletions(-) create mode 100644 app/helpers/application_helper.rb create mode 100644 app/helpers/pokedex_helper.rb create mode 100644 app/helpers/pokemon_helper.rb delete mode 100644 app/helpers/pokeviewer/application_helper.rb delete mode 100644 app/helpers/pokeviewer/pokedex_helper.rb delete mode 100644 app/helpers/pokeviewer/pokemon_helper.rb (limited to 'app/helpers') 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 @@ +module ApplicationHelper +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 @@ +module PokedexHelper + + def pokedex_table(all_species, trainers) + final_result = "".html_safe + + all_species.each do |species| + noted_trainers = species.pokedex_entries.to_a + + if noted_trainers.empty? + poke_name = "???" + poke_image = image_tag "icons/0.png" + else + poke_name = species.name + poke_image = image_tag "icons/#{species.id}.png" + end + + result = "".html_safe + + result << tag.th("\##{species.id}") + result << tag.th(poke_name) + result << tag.th(poke_image) + + trainers.each do |trainer| + if !noted_trainers.empty? and noted_trainers.first.trainer_id == trainer.id + nt = noted_trainers.shift + + if nt.caught + result << tag.td(trainer.display_number, + class: ["pkvd-caught", trainer.game]) + else + result << tag.td(trainer.display_number, + class: ["pkvd-seen", trainer.game]) + end + else + result << tag.td(trainer.display_number, class: "pkvd-unseen") + end + end + + result << tag.td( + species.current_revisions.map { + |p| link_to p.nickname, p.pokemon }.join(", ").html_safe) + + final_result << tag.tr(result) + end + + tag.table(final_result, class: "pkvd-table") + end + +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 @@ +require 'victor' + +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") + + svg.rect( + x: -40, + y: 460, + rx: 10, + ry: 10, + width: 490, + height: 60, + class: "pkcv-sheen-bg") + + if revision.sheen > 0 + svg.rect( + x: -37, + y: 460, + width: revision.sheen * 490 / 10 - 6, + height: 60, + class: "pkcv-sheen-data") + end + + svg.rect( + x: -40, + y: 460, + rx: 10, + ry: 10, + width: 490, + height: 60, + class: "pkcv-sheen-border") + + svg.text("SHEEN", + x: -20, + y: 500, + class: "pkcv-sheen-label") + + tag.svg(svg.to_s.html_safe, + viewBox: "-80 -30 570 560", + width: "100%", + class: "pokemon-condition") + end + + def image_for_type(type) + image_tag "types/#{type}.gif", class: "pkv-type" + 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 << " ".html_safe if i > 0 + result << w + end + + result << " at Lv. ".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 + "Met in a fateful encounter at Lv. ".html_safe + + pokemon.met_level.to_s + elsif met_type == :orre + "Met in a trade." + end + end + +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 @@ -module Pokeviewer - module ApplicationHelper - end -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 @@ -module Pokeviewer - module PokedexHelper - - def pokedex_table(all_species, trainers) - final_result = "".html_safe - - all_species.each do |species| - noted_trainers = species.pokedex_entries.to_a - - if noted_trainers.empty? - poke_name = "???" - poke_image = image_tag "pokeviewer/icons/0.png" - else - poke_name = species.name - poke_image = image_tag "pokeviewer/icons/#{species.id}.png" - end - - result = "".html_safe - - result << tag.th("\##{species.id}") - result << tag.th(poke_name) - result << tag.th(poke_image) - - trainers.each do |trainer| - if !noted_trainers.empty? and noted_trainers.first.trainer_id == trainer.id - nt = noted_trainers.shift - - if nt.caught - result << tag.td(trainer.display_number, - class: ["pkvd-caught", trainer.game]) - else - result << tag.td(trainer.display_number, - class: ["pkvd-seen", trainer.game]) - end - else - result << tag.td(trainer.display_number, class: "pkvd-unseen") - end - end - - result << tag.td( - species.current_revisions.map { - |p| link_to p.nickname, p.pokemon }.join(", ").html_safe) - - final_result << tag.tr(result) - end - - tag.table(final_result, class: "pkvd-table") - end - - end -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 @@ -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") - - svg.rect( - x: -40, - y: 460, - rx: 10, - ry: 10, - width: 490, - height: 60, - class: "pkcv-sheen-bg") - - if revision.sheen > 0 - svg.rect( - x: -37, - y: 460, - width: revision.sheen * 490 / 10 - 6, - height: 60, - class: "pkcv-sheen-data") - end - - svg.rect( - x: -40, - y: 460, - rx: 10, - ry: 10, - width: 490, - height: 60, - class: "pkcv-sheen-border") - - svg.text("SHEEN", - x: -20, - y: 500, - class: "pkcv-sheen-label") - - tag.svg(svg.to_s.html_safe, - viewBox: "-80 -30 570 560", - width: "100%", - class: "pokemon-condition") - end - - def image_for_type(type) - image_tag "pokeviewer/types/#{type}.gif", class: "pkv-type" - 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 << " ".html_safe if i > 0 - result << w - end - - result << " at Lv. ".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 - "Met in a fateful encounter at Lv. ".html_safe + - pokemon.met_level.to_s - elsif met_type == :orre - "Met in a trade." - end - end - - end -end -- cgit 1.4.1