package org.beatbot.injection.impl;

import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.tree.ClassNode;
import jdk.internal.org.objectweb.asm.tree.FieldInsnNode;
import jdk.internal.org.objectweb.asm.tree.FieldNode;
import org.beatbot.injection.generic.AbstractAnalyzer;

/**
 * Created by Snorflake on 8/12/2015.
 */
public class RenderableAnalyzer extends AbstractAnalyzer{
    public String heightname = "";
    @Override
    protected boolean canRun(ClassNode node) {
        if(node.superName.equals(classnames.get("CacheableNode")))
        {
            if(node.access == (Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SUPER))
                return true;
        }
        return false;
    }

    @Override
    protected String analyse(ClassNode node) {
        System.out.println("[ Renderable ]\n^ " + node.name + " extends " + node.superName);
        node.interfaces.add("org/beatbot/injection/interfaces/IRenderable");
        for(FieldNode fieldNode : node.fields)
        {
            if(fieldNode.desc.equals("I"))
            {
                //System.out.println("    * getHeight() -> " + fieldNode.desc + " " + node.name + "." + fieldNode.name);
                //createNormalMethodPrimitive(node,fieldNode,"getHeight","()I");
                heightname = fieldNode.name;
            }
        }
        classnames.put("Renderable", node.name);
        classnode = node;
        return "Renderable";
    }
}
