2 Commits 7297299ad3 ... 4d17a5a980

Auteur SHA1 Bericht Datum
  Kylie Jo Swistak 4d17a5a980 fix faulty fable scrolling 4 jaren geleden
  Kylie Jo Swistak b2ee1e55dc update ignored images, and fix matchup image fetching and generation 4 jaren geleden
4 gewijzigde bestanden met toevoegingen van 23 en 22 verwijderingen
  1. 2 5
      .gitignore
  2. 11 6
      app/carousels/fable.rb
  3. 7 5
      app/commands/matchup.rb
  4. 3 6
      app/models/image_merger.rb

+ 2 - 5
.gitignore

@@ -2,9 +2,6 @@
 Gemfile.lock
 .DS_Store
 .vs/*
-images/Image_Builder/LevelUp.png
-images/Image_Builder/LevelUp0.png
-images/Image_Builder/LevelUp1.png
-images/Image_Builder/LevelUp2.png
+images/Image_Builder/LevelUp*.png
 images/Image_Builder/user_url_img.png
-images/Type Double.png
+images/Type Double*.png

+ 11 - 6
app/carousels/fable.rb

@@ -25,6 +25,9 @@ class FableCarousel < Carousel
     # Find next fable
     fable = next_fable(section, carousel)
 
+    carousel.update(fable_id: fable.id)
+    carousel.reload
+
     # Update to new fable
     BotResponse.new(
       carousel: carousel,
@@ -33,17 +36,19 @@ class FableCarousel < Carousel
   end
 
   def self.next_fable(section, carousel)
+    # The list of fables in order, and the index of the current fable
+    fables = Fable.order('id ASC')
+    i = fables.map(&:id).index(carousel.fable_id)
+
     case section
     when 'first'
-      Fable.order('id DESC').first
+      fables.first
     when 'left'
-      Fable.where('id < ?', carousel.fable_id).order('id DESC').first ||
-        Fable.order('id DESC').first
+      i == 0 ? fables.last : fables[i-1]
     when 'right'
-      Fable.where('id > ?', carousel.fable_id).order('id ASC').first ||
-        Fable.order('id ASC').first
+      i == fables.length-1 ? fables.first : fables[i+1]
     when 'last'
-      Fable.order('id ASC').first
+      fables.last
     end
   end
 end

+ 7 - 5
app/commands/matchup.rb

@@ -14,13 +14,15 @@ class MatchupCommand < BaseCommand
     desc = "Displays a chart of effectiveness for the given type"
 
     @cmd ||= Command.new(:matchup, desc, opts) do |event, primary, secondary|
-      # Find the appropriate type images
+      # Find the primary type image, or raise exception if none is found
+      raise "No type given" unless primary
       file = "images/Type #{primary.capitalize}.png"
-      secondary_file = "images/Type #{secondary.capitalize}.png"
 
-      # Combine if there are two
-      if File.exists?(file) && File.exists?(secondary_file)
-        append_image(file, secondary_file, 'images/Type Double.png')
+      # If a secondary type is given, append images for each
+      if secondary
+        file_2 = "images/Type #{secondary.capitalize}.png"
+
+        append_image(file, file_2, 'images/Type Double.png')
         file = 'images/Type Double.png'
       end
 

+ 3 - 6
app/models/image_merger.rb

@@ -1,12 +1,9 @@
 require 'rmagick'
 include Magick
 
-def append_image(image1_in, images_in, image_out)
-  i = Magick::ImageList.new(image1_in,images_in)
-
-  if i.append(true)
-    u.write(image_out)
-  end
+def append_image(image1_in, image2_in, image_out)
+  i = Magick::ImageList.new(image1_in,image2_in)
+  i.append(true).write(image_out)
 end
 
 def merge_image(image_array, image_out, output_width, output_height, xaxis, yaxis, image_width, image_height)