package at.oefai.aaa.animation;

import java.text.NumberFormat;

/**
 * SVG anim for showing an expression, shows a speech bubble, text size corresponds to intensity.
 * @author Stefan Rank
 */
public class ShowExpression extends BaseSVGAnim {
    private static final int DISPLAY_INTERVAL_FACTOR = 100;
    private static final NumberFormat NF = NumberFormat.getNumberInstance();
    private volatile boolean done = false;
    private String expression = "";
    private float intensity = 0;
    private boolean shown = false;

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

    protected void doFirstTime() {
        assert (this.args.size() == 2) : "wrong arguments for ShowExpression";
        this.expression = this.args.get(0).getString();
        this.intensity = (float) this.args.get(1).getReal();
        this.interval = this.interval * DISPLAY_INTERVAL_FACTOR; // show the expression for this long
    }


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

    protected void doIt() {
        if (this.shown) { // remove the expression
            hideElement(this.actor + this.expression);
            hideTextElement(this.actor, this.expression);
            this.done = true;
        } else { // add the expression
            showElement(this.actor + this.expression);
            showTextElement(this.actor, this.expression, this.intensity);
            this.shown = true;
        }
    }
}
