package eu.oschl.gui; import eu.oschl.gui.actions.Action; import eu.oschl.gui.actions.Explore; import eu.oschl.gui.exceptions.InvalidActionId; import eu.oschl.textadventure.Game; import java.util.ArrayList; import java.util.List; public class ActionProcessor extends Observable { private final ArrayList actions; public ActionProcessor(ArrayList actions) { this.actions = actions; } public ArrayList getActions() { return actions; } /** * Factory method to create a ActionProcessor with a predefined set of Actions. * * @param game the game instance to be used by the actions * @return a new ActionProcessor instance with initialized actions */ public static ActionProcessor create(Game game) { ArrayList actions = new ArrayList<>(List.of( new Explore(game) )); return new ActionProcessor(actions); } /** * Executes the action of the provided ID and arguments. * * @param id the action ID * @throws InvalidActionId if the action ID is not found or is invalid */ public void executeAction(String id, String[] args) throws InvalidActionId { Output.clear(); for (Action action : actions) { if (action.getId().equals(id)) { action.execute(args); sendEvent(); return; } } throw new InvalidActionId("Invalid action ID"); } }