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/models/revision.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/models/revision.rb')
| -rw-r--r-- | app/models/revision.rb | 494 |
1 files changed, 494 insertions, 0 deletions
| diff --git a/app/models/revision.rb b/app/models/revision.rb new file mode 100644 index 0000000..477a042 --- /dev/null +++ b/app/models/revision.rb | |||
| @@ -0,0 +1,494 @@ | |||
| 1 | require 'active_record/diff' | ||
| 2 | |||
| 3 | class Revision < ApplicationRecord | ||
| 4 | include ActiveRecord::Diff | ||
| 5 | |||
| 6 | diff :species_id, :nickname, :level, :hp, :attack, :defense, | ||
| 7 | :special_attack, :special_defense, :speed, :coolness, :beauty, :cuteness, | ||
| 8 | :smartness, :toughness, :sheen, :item_id, :move_1_id, :move_2_id, | ||
| 9 | :move_3_id, :move_4_id, :move_1_pp_bonuses, :move_2_pp_bonuses, | ||
| 10 | :move_3_pp_bonuses, :move_4_pp_bonuses, :cool_ribbons, :beauty_ribbons, | ||
| 11 | :cute_ribbons, :smart_ribbons, :tough_ribbons, :champion_ribbon, | ||
| 12 | :winning_ribbon, :victory_ribbon, :artist_ribbon, :effort_ribbon, | ||
| 13 | :marine_ribbon, :land_ribbon, :sky_ribbon, :country_ribbon, | ||
| 14 | :national_ribbon, :earth_ribbon, :world_ribbon | ||
| 15 | |||
| 16 | belongs_to :pokemon | ||
| 17 | acts_as_sequenced scope: :pokemon_id | ||
| 18 | |||
| 19 | after_create :cache_pokemon_current | ||
| 20 | |||
| 21 | belongs_to :species | ||
| 22 | |||
| 23 | validates :nickname, presence: true | ||
| 24 | |||
| 25 | validates :experience, presence: true, | ||
| 26 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
| 27 | |||
| 28 | validates :level, presence: true, | ||
| 29 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
| 30 | |||
| 31 | validates :hp, presence: true, | ||
| 32 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
| 33 | |||
| 34 | validates :attack, presence: true, | ||
| 35 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
| 36 | |||
| 37 | validates :defense, presence: true, | ||
| 38 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
| 39 | |||
| 40 | validates :special_attack, presence: true, | ||
| 41 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
| 42 | |||
| 43 | validates :special_defense, presence: true, | ||
| 44 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
| 45 | |||
| 46 | validates :speed, presence: true, | ||
| 47 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
| 48 | |||
| 49 | validates :coolness, presence: true, | ||
| 50 | numericality: { | ||
| 51 | greater_than_or_equal_to: 0, | ||
| 52 | less_than_or_equal_to: 10, | ||
| 53 | only_integer: true } | ||
| 54 | |||
| 55 | validates :beauty, presence: true, | ||
| 56 | numericality: { | ||
| 57 | greater_than_or_equal_to: 0, | ||
| 58 | less_than_or_equal_to: 10, | ||
| 59 | only_integer: true } | ||
| 60 | |||
| 61 | validates :cuteness, presence: true, | ||
| 62 | numericality: { | ||
| 63 | greater_than_or_equal_to: 0, | ||
| 64 | less_than_or_equal_to: 10, | ||
| 65 | only_integer: true } | ||
| 66 | |||
| 67 | validates :smartness, presence: true, | ||
| 68 | numericality: { | ||
| 69 | greater_than_or_equal_to: 0, | ||
| 70 | less_than_or_equal_to: 10, | ||
| 71 | only_integer: true } | ||
| 72 | |||
| 73 | validates :toughness, presence: true, | ||
| 74 | numericality: { | ||
| 75 | greater_than_or_equal_to: 0, | ||
| 76 | less_than_or_equal_to: 10, | ||
| 77 | only_integer: true } | ||
| 78 | |||
| 79 | validates :sheen, presence: true, | ||
| 80 | numericality: { | ||
| 81 | greater_than_or_equal_to: 0, | ||
| 82 | less_than_or_equal_to: 10, | ||
| 83 | only_integer: true } | ||
| 84 | |||
| 85 | belongs_to :item, optional: true | ||
| 86 | |||
| 87 | belongs_to :move_1, class_name: "Move" | ||
| 88 | belongs_to :move_2, class_name: "Move", optional: true | ||
| 89 | belongs_to :move_3, class_name: "Move", optional: true | ||
| 90 | belongs_to :move_4, class_name: "Move", optional: true | ||
| 91 | |||
| 92 | validates :move_1_pp_bonuses, presence: true, | ||
| 93 | numericality: { | ||
| 94 | greater_than_or_equal_to: 0, | ||
| 95 | less_than_or_equal_to: 3, | ||
| 96 | only_integer: true} | ||
| 97 | |||
| 98 | validates :move_2_pp_bonuses, presence: true, | ||
| 99 | numericality: { | ||
| 100 | greater_than_or_equal_to: 0, | ||
| 101 | less_than_or_equal_to: 3, | ||
| 102 | only_integer: true} | ||
| 103 | |||
| 104 | validates :move_3_pp_bonuses, presence: true, | ||
| 105 | numericality: { | ||
| 106 | greater_than_or_equal_to: 0, | ||
| 107 | less_than_or_equal_to: 3, | ||
| 108 | only_integer: true} | ||
| 109 | |||
| 110 | validates :move_4_pp_bonuses, presence: true, | ||
| 111 | numericality: { | ||
| 112 | greater_than_or_equal_to: 0, | ||
| 113 | less_than_or_equal_to: 3, | ||
| 114 | only_integer: true} | ||
| 115 | |||
| 116 | validates :cool_ribbons, presence: true, | ||
| 117 | numericality: { | ||
| 118 | greater_than_or_equal_to: 0, | ||
| 119 | less_than_or_equal_to: 4, | ||
| 120 | only_integer: true} | ||
| 121 | |||
| 122 | validates :beauty_ribbons, presence: true, | ||
| 123 | numericality: { | ||
| 124 | greater_than_or_equal_to: 0, | ||
| 125 | less_than_or_equal_to: 4, | ||
| 126 | only_integer: true} | ||
| 127 | |||
| 128 | validates :cute_ribbons, presence: true, | ||
| 129 | numericality: { | ||
| 130 | greater_than_or_equal_to: 0, | ||
| 131 | less_than_or_equal_to: 4, | ||
| 132 | only_integer: true} | ||
| 133 | |||
| 134 | validates :smart_ribbons, presence: true, | ||
| 135 | numericality: { | ||
| 136 | greater_than_or_equal_to: 0, | ||
| 137 | less_than_or_equal_to: 4, | ||
| 138 | only_integer: true} | ||
| 139 | |||
| 140 | validates :tough_ribbons, presence: true, | ||
| 141 | numericality: { | ||
| 142 | greater_than_or_equal_to: 0, | ||
| 143 | less_than_or_equal_to: 4, | ||
| 144 | only_integer: true} | ||
| 145 | |||
| 146 | def icon_path | ||
| 147 | form = "" | ||
| 148 | if species_id == 201 | ||
| 149 | # Handle Unown form | ||
| 150 | form = "-#{pokemon.unown_letter}" | ||
| 151 | elsif species_id == 386 | ||
| 152 | # Handle Deoxys forms | ||
| 153 | if pokemon.trainer.firered? | ||
| 154 | form = "-attack" | ||
| 155 | elsif pokemon.trainer.leafgreen? | ||
| 156 | form = "-defense" | ||
| 157 | elsif pokemon.trainer.emerald? | ||
| 158 | form = "-speed" | ||
| 159 | end | ||
| 160 | end | ||
| 161 | |||
| 162 | "icons/#{species_id}#{form}.png" | ||
| 163 | end | ||
| 164 | |||
| 165 | def sprite_path | ||
| 166 | shininess = "normal" | ||
| 167 | if pokemon.shiny | ||
| 168 | shininess = "shiny" | ||
| 169 | end | ||
| 170 | |||
| 171 | game = "ruby-sapphire" | ||
| 172 | unless pokemon.trainer.nil? | ||
| 173 | if (pokemon.trainer.firered? or pokemon.trainer.leafgreen?) and (species_id <= 151 or species_id == 216 or species_id == 386) | ||
| 174 | game = "firered-leafgreen" | ||
| 175 | elsif pokemon.trainer.emerald? | ||
| 176 | game = "emerald" | ||
| 177 | end | ||
| 178 | end | ||
| 179 | |||
| 180 | form = "" | ||
| 181 | if species_id == 201 | ||
| 182 | # Handle Unown forms | ||
| 183 | form = "-#{pokemon.unown_letter}" | ||
| 184 | elsif species_id == 386 | ||
| 185 | # Handle Deoxys forms | ||
| 186 | if pokemon.trainer.firered? | ||
| 187 | form = "-attack" | ||
| 188 | elsif pokemon.trainer.leafgreen? | ||
| 189 | form = "-defense" | ||
| 190 | elsif pokemon.trainer.emerald? | ||
| 191 | form = "-speed" | ||
| 192 | end | ||
| 193 | end | ||
| 194 | |||
| 195 | if game == "emerald" | ||
| 196 | "sprites/emerald/#{shininess}/#{species_id}#{form}.gif" | ||
| 197 | else | ||
| 198 | "sprites/#{game}/#{shininess}/#{species_id}#{form}.png" | ||
| 199 | end | ||
| 200 | end | ||
| 201 | |||
| 202 | def ability | ||
| 203 | if pokemon.second_ability | ||
| 204 | species.ability_2 | ||
| 205 | else | ||
| 206 | species.ability_1 | ||
| 207 | end | ||
| 208 | end | ||
| 209 | |||
| 210 | def move_1_pp | ||
| 211 | move_1.pp * (5 + move_1_pp_bonuses) / 5 | ||
| 212 | end | ||
| 213 | |||
| 214 | def move_2_pp | ||
| 215 | move_2.pp * (5 + move_2_pp_bonuses) / 5 | ||
| 216 | end | ||
| 217 | |||
| 218 | def move_3_pp | ||
| 219 | move_3.pp * (5 + move_3_pp_bonuses) / 5 | ||
| 220 | end | ||
| 221 | |||
| 222 | def move_4_pp | ||
| 223 | move_4.pp * (5 + move_4_pp_bonuses) / 5 | ||
| 224 | end | ||
| 225 | |||
| 226 | def ribbons | ||
| 227 | result = [] | ||
| 228 | |||
| 229 | if cool_ribbons >= 1 | ||
| 230 | result << { | ||
| 231 | filename: "cool-ribbon.png", | ||
| 232 | name: "Cool Ribbon", | ||
| 233 | description: "Cool Contest Normal Rank Winner!" | ||
| 234 | } | ||
| 235 | end | ||
| 236 | |||
| 237 | if cool_ribbons >= 2 | ||
| 238 | result << { | ||
| 239 | filename: "cool-ribbon-super.png", | ||
| 240 | name: "Cool Ribbon Super", | ||
| 241 | description: "Cool Contest Super Rank Winner!" | ||
| 242 | } | ||
| 243 | end | ||
| 244 | |||
| 245 | if cool_ribbons >= 3 | ||
| 246 | result << { | ||
| 247 | filename: "cool-ribbon-hyper.png", | ||
| 248 | name: "Cool Ribbon Hyper", | ||
| 249 | description: "Cool Contest Hyper Rank Winner!" | ||
| 250 | } | ||
| 251 | end | ||
| 252 | |||
| 253 | if cool_ribbons == 4 | ||
| 254 | result << { | ||
| 255 | filename: "cool-ribbon-master.png", | ||
| 256 | name: "Cool Ribbon Master", | ||
| 257 | description: "Cool Contest Master Rank Winner!" | ||
| 258 | } | ||
| 259 | end | ||
| 260 | |||
| 261 | if beauty_ribbons >= 1 | ||
| 262 | result << { | ||
| 263 | filename: "beauty-ribbon.png", | ||
| 264 | name: "Beauty Ribbon", | ||
| 265 | description: "Beauty Contest Normal Rank Winner!" | ||
| 266 | } | ||
| 267 | end | ||
| 268 | |||
| 269 | if beauty_ribbons >= 2 | ||
| 270 | result << { | ||
| 271 | filename: "beauty-ribbon-super.png", | ||
| 272 | name: "Beauty Ribbon Super", | ||
| 273 | description: "Beauty Contest Super Rank Winner!" | ||
| 274 | } | ||
| 275 | end | ||
| 276 | |||
| 277 | if beauty_ribbons >= 3 | ||
| 278 | result << { | ||
| 279 | filename: "beauty-ribbon-hyper.png", | ||
| 280 | name: "Beauty Ribbon Hyper", | ||
| 281 | description: "Beauty Contest Hyper Rank Winner!" | ||
| 282 | } | ||
| 283 | end | ||
| 284 | |||
| 285 | if beauty_ribbons == 4 | ||
| 286 | result << { | ||
| 287 | filename: "beauty-ribbon-master.png", | ||
| 288 | name: "Beauty Ribbon Master", | ||
| 289 | description: "Beauty Contest Master Rank Winner!" | ||
| 290 | } | ||
| 291 | end | ||
| 292 | |||
| 293 | if cute_ribbons >= 1 | ||
| 294 | result << { | ||
| 295 | filename: "cute-ribbon.png", | ||
| 296 | name: "Cute Ribbon", | ||
| 297 | description: "Cute Contest Normal Rank Winner!" | ||
| 298 | } | ||
| 299 | end | ||
| 300 | |||
| 301 | if cute_ribbons >= 2 | ||
| 302 | result << { | ||
| 303 | filename: "cute-ribbon-super.png", | ||
| 304 | name: "Cute Ribbon Super", | ||
| 305 | description: "Cute Contest Super Rank Winner!" | ||
| 306 | } | ||
| 307 | end | ||
| 308 | |||
| 309 | if cute_ribbons >= 3 | ||
| 310 | result << { | ||
| 311 | filename: "cute-ribbon-hyper.png", | ||
| 312 | name: "Cute Ribbon Hyper", | ||
| 313 | description: "Cute Contest Hyper Rank Winner!" | ||
| 314 | } | ||
| 315 | end | ||
| 316 | |||
| 317 | if cute_ribbons == 4 | ||
| 318 | result << { | ||
| 319 | filename: "cute-ribbon-master.png", | ||
| 320 | name: "Cute Ribbon Master", | ||
| 321 | description: "Cute Contest Master Rank Winner!" | ||
| 322 | } | ||
| 323 | end | ||
| 324 | |||
| 325 | if smart_ribbons >= 1 | ||
| 326 | result << { | ||
| 327 | filename: "smart-ribbon.png", | ||
| 328 | name: "Smart Ribbon", | ||
| 329 | description: "Smart Contest Normal Rank Winner!" | ||
| 330 | } | ||
| 331 | end | ||
| 332 | |||
| 333 | if smart_ribbons >= 2 | ||
| 334 | result << { | ||
| 335 | filename: "smart-ribbon-super.png", | ||
| 336 | name: "Smart Ribbon Super", | ||
| 337 | description: "Smart Contest Super Rank Winner!" | ||
| 338 | } | ||
| 339 | end | ||
| 340 | |||
| 341 | if smart_ribbons >= 3 | ||
| 342 | result << { | ||
| 343 | filename: "smart-ribbon-hyper.png", | ||
| 344 | name: "Smart Ribbon Hyper", | ||
| 345 | description: "Smart Contest Hyper Rank Winner!" | ||
| 346 | } | ||
| 347 | end | ||
| 348 | |||
| 349 | if smart_ribbons == 4 | ||
| 350 | result << { | ||
| 351 | filename: "smart-ribbon-master.png", | ||
| 352 | name: "Smart Ribbon Master", | ||
| 353 | description: "Smart Contest Master Rank Winner!" | ||
| 354 | } | ||
| 355 | end | ||
| 356 | |||
| 357 | if tough_ribbons >= 1 | ||
| 358 | result << { | ||
| 359 | filename: "tough-ribbon.png", | ||
| 360 | name: "Tough Ribbon", | ||
| 361 | description: "Tough Contest Normal Rank Winner!" | ||
| 362 | } | ||
| 363 | end | ||
| 364 | |||
| 365 | if tough_ribbons >= 2 | ||
| 366 | result << { | ||
| 367 | filename: "tough-ribbon-super.png", | ||
| 368 | name: "Tough Ribbon Super", | ||
| 369 | description: "Tough Contest Super Rank Winner!" | ||
| 370 | } | ||
| 371 | end | ||
| 372 | |||
| 373 | if tough_ribbons >= 3 | ||
| 374 | result << { | ||
| 375 | filename: "tough-ribbon-hyper.png", | ||
| 376 | name: "Tough Ribbon Hyper", | ||
| 377 | description: "Tough Contest Hyper Rank Winner!" | ||
| 378 | } | ||
| 379 | end | ||
| 380 | |||
| 381 | if tough_ribbons == 4 | ||
| 382 | result << { | ||
| 383 | filename: "tough-ribbon-master.png", | ||
| 384 | name: "Tough Ribbon Master", | ||
| 385 | description: "Tough Contest Master Rank Winner!" | ||
| 386 | } | ||
| 387 | end | ||
| 388 | |||
| 389 | if champion_ribbon | ||
| 390 | result << { | ||
| 391 | filename: "champion-ribbon.png", | ||
| 392 | name: "Champion Ribbon", | ||
| 393 | description: "Champion-beating, Hall of Fame Member Ribbon" | ||
| 394 | } | ||
| 395 | end | ||
| 396 | |||
| 397 | if winning_ribbon | ||
| 398 | result << { | ||
| 399 | filename: "winning-ribbon.png", | ||
| 400 | name: "Winning Ribbon", | ||
| 401 | description: "Ribbon for clearing LV50 at the Battle Tower." | ||
| 402 | } | ||
| 403 | end | ||
| 404 | |||
| 405 | if victory_ribbon | ||
| 406 | result << { | ||
| 407 | filename: "victory-ribbon.png", | ||
| 408 | name: "Victory Ribbon", | ||
| 409 | description: "Won for clearing LV100 at the Battle Tower." | ||
| 410 | } | ||
| 411 | end | ||
| 412 | |||
| 413 | if artist_ribbon | ||
| 414 | result << { | ||
| 415 | filename: "artist-ribbon.png", | ||
| 416 | name: "Artist Ribbon", | ||
| 417 | description: "Ribbon for being chosen as a super sketch model." | ||
| 418 | } | ||
| 419 | end | ||
| 420 | |||
| 421 | if effort_ribbon | ||
| 422 | result << { | ||
| 423 | filename: "effort-ribbon.png", | ||
| 424 | name: "Effort Ribbon", | ||
| 425 | description: "Ribbon awarded for being a hard worker." | ||
| 426 | } | ||
| 427 | end | ||
| 428 | |||
| 429 | if marine_ribbon | ||
| 430 | result << { | ||
| 431 | filename: "marine-ribbon.png", | ||
| 432 | name: "Marine Ribbon", | ||
| 433 | description: pokemon.gift_ribbon_description(:marine_ribbon) | ||
| 434 | } | ||
| 435 | end | ||
| 436 | |||
| 437 | if land_ribbon | ||
| 438 | result << { | ||
| 439 | filename: "land-ribbon.png", | ||
| 440 | name: "Land Ribbon", | ||
| 441 | description: pokemon.gift_ribbon_description(:land_ribbon) | ||
| 442 | } | ||
| 443 | end | ||
| 444 | |||
| 445 | if sky_ribbon | ||
| 446 | result << { | ||
| 447 | filename: "sky-ribbon.png", | ||
| 448 | name: "Sky Ribbon", | ||
| 449 | description: pokemon.gift_ribbon_description(:sky_ribbon) | ||
| 450 | } | ||
| 451 | end | ||
| 452 | |||
| 453 | if country_ribbon | ||
| 454 | result << { | ||
| 455 | filename: "country-ribbon.png", | ||
| 456 | name: "Country Ribbon", | ||
| 457 | description: pokemon.gift_ribbon_description(:country_ribbon) | ||
| 458 | } | ||
| 459 | end | ||
| 460 | |||
| 461 | if national_ribbon | ||
| 462 | result << { | ||
| 463 | filename: "national-ribbon.png", | ||
| 464 | name: "National Ribbon", | ||
| 465 | description: pokemon.gift_ribbon_description(:national_ribbon) | ||
| 466 | } | ||
| 467 | end | ||
| 468 | |||
| 469 | if earth_ribbon | ||
| 470 | result << { | ||
| 471 | filename: "earth-ribbon.png", | ||
| 472 | name: "Earth Ribbon", | ||
| 473 | description: pokemon.gift_ribbon_description(:earth_ribbon) | ||
| 474 | } | ||
| 475 | end | ||
| 476 | |||
| 477 | if world_ribbon | ||
| 478 | result << { | ||
| 479 | filename: "world-ribbon.png", | ||
| 480 | name: "World Ribbon", | ||
| 481 | description: pokemon.gift_ribbon_description(:world_ribbon) | ||
| 482 | } | ||
| 483 | end | ||
| 484 | |||
| 485 | result | ||
| 486 | end | ||
| 487 | |||
| 488 | private | ||
| 489 | |||
| 490 | def cache_pokemon_current | ||
| 491 | self.pokemon.current_id = self.id | ||
| 492 | self.pokemon.save! | ||
| 493 | end | ||
| 494 | end | ||
