package mapped;

import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSAnimation;
import net.runelite.rs.api.RSSkeleton;

@ObfuscatedName("kr")
public class Animation implements RSAnimation {
   @ObfuscatedName("at")
   static int[] field2738;
   @ObfuscatedName("ah")
   static int[] field2731;
   @ObfuscatedName("ar")
   static int[] field2736;
   @ObfuscatedName("ao")
   static int[] field2733;
   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "Lkd;"
   )
   Skeleton skeleton;
   @ObfuscatedName("au")
   int transformCount;
   @ObfuscatedName("aa")
   int[] transformSkeletonLabels;
   @ObfuscatedName("ac")
   int[] transformXs;
   @ObfuscatedName("al")
   int[] transformYs;
   @ObfuscatedName("az")
   int[] transformZs;
   @ObfuscatedName("ap")
   boolean hasAlphaTransform;

   static {
      field2738 = new int[500];
      field2731 = new int[500];
      field2736 = new int[500];
      field2733 = new int[500];
   }

   @ObfuscatedSignature(
      descriptor = "([BLkd;)V"
   )
   Animation(byte[] var1, Skeleton var2) {
      this.skeleton = null;
      this.transformCount = -1;
      this.hasAlphaTransform = false;
      this.skeleton = var2;
      Buffer var3 = new Buffer(var1);
      Buffer var4 = new Buffer(var1);
      var3.offset = 2;
      int var5 = var3.readUnsignedByte_base();
      int var6 = -1;
      int var7 = 0;
      var4.offset = var5 + var3.offset;

      int var8;
      for(var8 = 0; var8 < var5; ++var8) {
         int var9 = var3.readUnsignedByte_base();
         if(var9 > 0) {
            if(this.skeleton.transformTypes[var8] != 0) {
               for(int var10 = var8 - 1; var10 > var6; --var10) {
                  if(this.skeleton.transformTypes[var10] == 0) {
                     field2738[var7] = var10;
                     field2731[var7] = 0;
                     field2736[var7] = 0;
                     field2733[var7] = 0;
                     ++var7;
                     break;
                  }
               }
            }

            field2738[var7] = var8;
            short var11 = 0;
            if(this.skeleton.transformTypes[var8] == 3) {
               var11 = 128;
            }

            if((var9 & 1) != 0) {
               field2731[var7] = var4.readShortSmart_base();
            } else {
               field2731[var7] = var11;
            }

            if((var9 & 2) != 0) {
               field2736[var7] = var4.readShortSmart_base();
            } else {
               field2736[var7] = var11;
            }

            if((var9 & 4) != 0) {
               field2733[var7] = var4.readShortSmart_base();
            } else {
               field2733[var7] = var11;
            }

            var6 = var8;
            ++var7;
            if(this.skeleton.transformTypes[var8] == 5) {
               this.hasAlphaTransform = true;
            }
         }
      }

      if(var1.length != var4.offset) {
         throw new RuntimeException();
      } else {
         this.transformCount = var7;
         this.transformSkeletonLabels = new int[var7];
         this.transformXs = new int[var7];
         this.transformYs = new int[var7];
         this.transformZs = new int[var7];

         for(var8 = 0; var8 < var7; ++var8) {
            this.transformSkeletonLabels[var8] = field2738[var8];
            this.transformXs[var8] = field2731[var8];
            this.transformYs[var8] = field2736[var8];
            this.transformZs[var8] = field2733[var8];
         }

      }
   }

   public RSSkeleton getSkeleton() {
      return this.skeleton;
   }

   public int getTransformCount() {
      return this.transformCount;
   }

   public int[] getTransformTypes() {
      return this.transformSkeletonLabels;
   }

   public int[] getTranslatorX() {
      return this.transformXs;
   }

   public int[] getTranslatorY() {
      return this.transformYs;
   }

   public int[] getTranslatorZ() {
      return this.transformZs;
   }

   public boolean isShowing() {
      return this.hasAlphaTransform;
   }
}
