package eu.jonahbauer.wizard.client.libgdx.actions;

import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.actions.*;

public class MyActions extends Actions {
    public static ChangeParentAction changeParent(Group parent) {
        var action = action(ChangeParentAction.class);
        action.setParent(parent);
        return action;
    }

    public static SilentlyRemoveActorAction removeActorSilently () {
        return action(SilentlyRemoveActorAction.class);
    }

    public static WaitAction delay(Actor actor) {
        var action = action(WaitAction.class);
        action.setTarget(actor);
        return action;
    }

    public static void finish(Action action) {
        if (action instanceof ParallelAction parallel) {
            var subactions = parallel.getActions();
            for (int i = 0; i < subactions.size; i++) {
                finish(subactions.get(i));
            }
        } else if (action instanceof DelayAction delay) {
            delay.finish();
            finish(delay.getAction());
        } else if (action instanceof DelegateAction delegate) {
            var subaction = delegate.getAction();
            finish(subaction);
        } else if (action instanceof TemporalAction temporal) {
            temporal.finish();
        }
    }
}
