Package com.teamjmonkey.appstates

Source Code of com.teamjmonkey.appstates.MonkeyAppStateManager

package com.teamjmonkey.appstates;

import com.jme3.app.state.AbstractAppState;
import com.teamjmonkey.util.Manager;
import java.util.ArrayList;

public class MonkeyAppStateManager implements Manager {

    private ArrayList<AbstractAppState> appStates = new ArrayList<AbstractAppState>(5);

    public MonkeyAppStateManager() {
    }

    public <T extends AbstractAppState> AbstractAppState getAppState(Class<T> appStateClass) {

        for (AbstractAppState state : getStates()) {
            if (appStateClass.isAssignableFrom(state.getClass())) {
                return (T) state;
            }
        }

        // return a new instance
        try {
            AbstractAppState state = appStateClass.newInstance();
            appStates.add(state);
            return (T) state;
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return null;
    }

    protected ArrayList<AbstractAppState> getStates() {
        return appStates;
    }

    public void load(int level) {
    }

    public void cleanup() {
    }
}
TOP

Related Classes of com.teamjmonkey.appstates.MonkeyAppStateManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.