PatriqDesigns

Components

Apr 15th, 2021 (edited)
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     private List<InterfaceComponent> getDynamicSubComponents() {
  2.         List<InterfaceComponent> subcomponents = new ArrayList<>();
  3.         RSInterfaceComponent provider = getProvider();
  4.         if (provider == null) {
  5.             return subcomponents;
  6.         }
  7.  
  8.         RSInterfaceComponent[] raw = provider.getSubComponents();
  9.         if (raw == null) {
  10.             return subcomponents;
  11.         }
  12.  
  13.         for (RSInterfaceComponent component : raw) {
  14.             if (component != null && component.getParentUid() == getUid()) {
  15.                 subcomponents.add(new InterfaceComponent(component));
  16.             }
  17.         }
  18.         return subcomponents;
  19.     }
  20.  
  21.     private List<InterfaceComponent> getStaticSubComponents() {
  22.         List<InterfaceComponent> subcomponents = new ArrayList<>();
  23.         if (getParentUid() == getUid()) {
  24.             return subcomponents;
  25.         }
  26.  
  27.         int group = getGroupIndex();
  28.         RSInterfaceComponent[][] raw = Game.getClient().getInterfaces();
  29.         if (raw == null || group < 0 || group >= raw.length) {
  30.             return subcomponents;
  31.         }
  32.  
  33.         RSInterfaceComponent[] grouped = raw[group];
  34.         if (grouped == null) {
  35.             return subcomponents;
  36.         }
  37.  
  38.         for (RSInterfaceComponent component : grouped) {
  39.             if (component != null && component.getParentUid() == getUid()) {
  40.                 subcomponents.add(new InterfaceComponent(component));
  41.             }
  42.         }
  43.  
  44.         return subcomponents;
  45.     }
  46.  
  47.     private List<InterfaceComponent> getNestedSubComponents() {
  48.         List<InterfaceComponent> subcomponents = new ArrayList<>();
  49.         if (getParentUid() == getUid()) {
  50.             return subcomponents;
  51.         }
  52.  
  53.         RSNodeTable<RSSubInterface> nested = Game.getClient().getSubInterfaces();
  54.         if (nested == null) {
  55.             return subcomponents;
  56.         }
  57.  
  58.         RSSubInterface sub = nested.lookup(getUid());
  59.         if (sub == null) {
  60.             return subcomponents;
  61.         }
  62.  
  63.         int group = sub.getId();
  64.  
  65.         RSInterfaceComponent[][] raw = Game.getClient().getInterfaces();
  66.         if (raw == null || group < 0 || group >= raw.length) {
  67.             return subcomponents;
  68.         }
  69.  
  70.         RSInterfaceComponent[] grouped = raw[group];
  71.         if (grouped == null) {
  72.             return subcomponents;
  73.         }
  74.  
  75.         for (RSInterfaceComponent component : grouped) {
  76.             if (component != null && component.getParentUid() == -1) {
  77.                 subcomponents.add(new InterfaceComponent(component));
  78.             }
  79.         }
  80.         return subcomponents;
  81.     }
  82.  
  83.     private List<InterfaceComponent> getDefaultSubComponents() {
  84.         List<InterfaceComponent> subcomponents = new ArrayList<>();
  85.         RSInterfaceComponent provider = getProvider();
  86.         if (provider == null) {
  87.             return subcomponents;
  88.         }
  89.  
  90.         RSInterfaceComponent[] raw = provider.getSubComponents();
  91.         if (raw == null) {
  92.             return subcomponents;
  93.         }
  94.  
  95.         for (RSInterfaceComponent component : raw) {
  96.             if (component != null) {
  97.                 subcomponents.add(new InterfaceComponent(component));
  98.             }
  99.         }
  100.         return subcomponents;
  101.     }
  102.  
  103.     public List<InterfaceComponent> getSubComponents(TraversalOption option) {
  104.         switch (option) {
  105.             case NESTED:
  106.                 return getNestedSubComponents();
  107.             case STATIC:
  108.                 return getStaticSubComponents();
  109.             case DYNAMIC:
  110.                 return getDynamicSubComponents();
  111.             case DEFAULT:
  112.                 return getDefaultSubComponents();
  113.             default: {
  114.                 throw new IllegalArgumentException("Unsupported TraversalOption: " + option);
  115.             }
  116.         }
  117.     }
  118.  
  119.     public List<InterfaceComponent> getSubComponents() {
  120.         return getSubComponents(TraversalOption.DEFAULT);
  121.     }
  122.  
  123.     public enum TraversalOption {
  124.  
  125.         NESTED,
  126.         DYNAMIC,
  127.         STATIC,
  128.         DEFAULT;
  129.  
  130.         private static final TraversalOption[] NATURAL = {NESTED, DYNAMIC, STATIC};
  131.  
  132.         public static TraversalOption[] natural() {
  133.             return NATURAL;
  134.         }
  135.     }
Add Comment
Please, Sign In to add comment