Back to project page DolphinOES.
The source code is released under:
Apache License
If you think the Android project DolphinOES listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.sidereal.dolphinoes.architecture.core; /* w ww.ja v a2 s . c om*/ import java.util.HashMap; import java.util.Map.Entry; import com.badlogic.gdx.Gdx; import com.sidereal.dolphinoes.architecture.DebugHandler; import com.sidereal.dolphinoes.architecture.DolphinOES; import com.sidereal.dolphinoes.architecture.GameBehavior; public class Debug implements Configurable { private boolean enabled; public final HashMap<Class<? extends GameBehavior>, DebugHandler> behaviors; private float currentDebugCooldown; private final float defaultDebugCooldown; public Debug() { this.behaviors = new HashMap<Class<? extends GameBehavior>, DebugHandler>(); this.defaultDebugCooldown = 0.5f; this.currentDebugCooldown = this.defaultDebugCooldown; } @Override public void configure(DolphinOESConfiguration cfg) { this.enabled = cfg.debugEnabled; } public void update() { if(!enabled) return; // decrease duration until it can handle toggling on/off debuggers currentDebugCooldown -= DolphinOES.time.getDeltaTime(); // there's still time until we can do anything, stop if (currentDebugCooldown > 0) return; // go over every entry in the map for (Entry<Class<? extends GameBehavior>, DebugHandler> entry : behaviors .entrySet()) { // debug keys hasn't been setup or nothing was added to it, ignore // it if (entry.getValue().keysToActivate == null || entry.getValue().keysToActivate.size() == 0) continue; // whether or not we encountered a key that wasn't presed boolean mustSkip = false; // iterate through the required keys for (int j = 0; j < entry.getValue().keysToActivate.size(); j++) { // didn't press at least one of the keys required for activation if (!Gdx.input.isKeyPressed(entry.getValue().keysToActivate .get(j).intValue())) { // break from current loop, set a flag to true which will // skip the next part of the // loop for the current entry mustSkip = true; break; } } // at least one key wasn't pressed, skip toggling on/off if (mustSkip) continue; // update the debugging status to the opposite of what it was before entry.getValue().enabled = !entry.getValue().enabled; System.out.println("Enabling "+entry.getKey().getName()+" "+entry.getValue().enabled); // reset timer to the default value currentDebugCooldown = defaultDebugCooldown; } } /** Prints the message in the console if debugging is enabled * * @param value */ public void log(String value) { if (enabled) System.out.println(value); } public boolean isEnabled() { return enabled; } public DebugHandler get(GameBehavior behavior) { return behaviors.get(behavior.getClass()); } @Override public void create(){} }