package at.oefai.aaa.animation;

import org.w3c.dom.svg.SVGSVGElement;

/**
 * SVG anim setting up the bomb against an object.
 * @author Stefan Rank
 */
public class UseBombOnObject extends BaseSVGAnim {
    private String theObject = null;
    private String theTarget = null;
    private volatile boolean done = false;

    public BaseAnim newInstance() { return new UseBombOnObject(); }

    protected void doFirstTime() {
        assert (this.args.size() == 2) : "wrong arguments for UseBombOnObject";
        this.theObject = this.args.get(0).getString();
        // get the target objects pos:
        this.theTarget = this.args.get(1).getString();
    }

    public boolean isFinished() {
        return this.done;
    }

    protected void doIt() {
        // move the object if it is still away from the destination
        SVGSVGElement eleObject = getNamedElement(this.theObject);
        this.done = true; // only one step necessary
        if (eleObject != null) {
            // we just dont care if the named subelements exist
            showElement(this.theTarget + "Inactive");
            hideElement(this.theTarget + "Active");
        }
    }

}
