Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed the package 'parser' in debug to 'inputparser'

  • Loading branch information...
commit 4088c655ec12786a6b411d30db6584b8eaa386a7 1 parent 8967dd6
@Regiden authored
View
50 TestProjects/_RadicalFishTests-desktop/src/de/radicalFish/DebugTest.java
@@ -11,21 +11,22 @@
import de.matthiasmann.twl.Alignment;
import de.matthiasmann.twl.FPSCounter;
import de.matthiasmann.twl.Label;
-import de.radicalfish.context.ContextGame;
import de.radicalfish.context.GameContext;
+import de.radicalfish.context.GameWithContext;
import de.radicalfish.context.Settings;
+import de.radicalfish.debug.AssetsViewer;
import de.radicalfish.debug.DebugAdapter;
import de.radicalfish.debug.DebugPanel;
import de.radicalfish.debug.DeveloperConsole;
+import de.radicalfish.debug.EngineSettingsEditor;
import de.radicalfish.debug.GameVariablesEditor;
import de.radicalfish.debug.PerformanceListener;
import de.radicalfish.debug.SettingsEditor;
import de.radicalfish.debug.ToolBox;
-import de.radicalfish.debug.parser.PropertyInputParser;
-import de.radicalfish.debug.parser.URLInputParser;
+import de.radicalfish.debug.inputparser.PropertyInputParser;
+import de.radicalfish.debug.inputparser.URLInputParser;
import de.radicalfish.graphics.Graphics;
-import de.radicalfish.state.StateBasedGame;
-import de.radicalfish.tests.StatesTest;
+import de.radicalfish.tests.GameTest;
import de.radicalfish.util.RadicalFishException;
public class DebugTest extends DebugAdapter {
@@ -35,6 +36,7 @@
private ToolBox toolbox;
private DebugPanel debug;
private GameVariablesEditor gvmonitor;
+ private AssetsViewer av;
private GameContext context;
private Settings settings;
@@ -45,12 +47,12 @@
public DebugTest() {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.title = "Debug Test";
- config.useGL20 = false;
+ config.useGL20 = true;
config.width = 800;
config.height = 600;
config.useCPUSynch = false; // to true on release, else minimizing window will freak out
- GameContainer app = new GameContainer(config.title, new StatesTest(), config.width, config.height, config.useGL20);
+ GameContainer app = new GameContainer(config.title, new GameTest(), config.width, config.height, config.useGL20);
app.setDebugCallBack(this);
app.setSmoothDeltas(true);
new LwjglApplication(app, config);
@@ -63,8 +65,8 @@ public static void main(String[] args) {
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
public void init(GameContainer container) {
// if the game from the container is ContextGame, we can get the context
- if (container.game instanceof ContextGame) {
- context = ((StateBasedGame) container.game).getGameContext();
+ if (container.game instanceof GameWithContext) {
+ context = ((GameWithContext) container.game).getGameContext();
hasContext = true;
}
@@ -136,24 +138,29 @@ private void loadSettings() {
throw new RadicalFishException(e.getMessage());
}
- // add all the values
+ // add all the values
settings.setAllSettings(map);
}
private void buildGUI(final GameContainer container) {
final DeveloperConsole dev = new DeveloperConsole();
dev.addInputParser(new URLInputParser());
- if(hasContext) {
+ final EngineSettingsEditor ese = new EngineSettingsEditor(container);
+
+ if (hasContext) {
dev.addInputParser(new PropertyInputParser(settings));
}
final SettingsEditor set = new SettingsEditor(settings);
- if(hasContext) {
+ if (hasContext) {
gvmonitor = new GameVariablesEditor(context.getGameVariables());
} else {
gvmonitor = new GameVariablesEditor();
}
+ if (hasContext) {
+ av = new AssetsViewer(context.getAssets());
+ }
Label fps = new Label("FPS:");
FPSCounter fpsCounter = new FPSCounter();
@@ -176,6 +183,16 @@ public void run() {
gvmonitor.setVisible(!gvmonitor.isVisible());
}
});
+ toolbox.addButton("Assets", new Runnable() {
+ public void run() {
+ av.setVisible(!av.isVisible());
+ }
+ });
+ toolbox.addButton("Engine", new Runnable() {
+ public void run() {
+ ese.setVisible(!ese.isVisible());
+ }
+ });
toolbox.addFiller();
toolbox.addSeparator();
@@ -190,13 +207,20 @@ public void run() {
container.exit();
}
});
-
toolbox.createToolbox();
+ ese.setVisible(true);
+ av.setVisible(false);
+ dev.setVisible(false);
+ set.setVisible(false);
+ gvmonitor.setVisible(false);
+
debug.addToRoot(dev);
debug.addToRoot(set);
debug.addToRoot(gvmonitor);
debug.addToRoot(toolbox);
+ debug.addToRoot(av);
+ debug.addToRoot(ese);
}
// SETTER
View
71 _RadicalFishDebug/src/de/radicalfish/debug/inputparser/InputParser.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2011, Stefan Lange
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Stefan Lange nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.radicalfish.debug.inputparser;
+import java.util.ArrayList;
+import de.matthiasmann.twl.textarea.HTMLTextAreaModel;
+import de.radicalfish.debug.DeveloperConsole;
+
+/**
+ * Callback for user based handling of console input. A parser should always start with a keyword.
+ * <p>
+ * {@link InputParser#parseInput(String, DeveloperConsole)} will be called once enter is hit in the
+ * {@link DeveloperConsole}. If the input matches the parser it should return the text to display (as HMTL if you want
+ * see {@link HTMLTextAreaModel} for a list of supported tags). If not simply return the input string.
+ * <p>
+ * {@link InputParser#getAutoCompletionContent(String)} should return a list which matches the current input. This way
+ * the user can select from the list directly to shorten the input time.
+ *
+ * @author Stefan Lange
+ * @version 1.0.0
+ * @since 14.05.2012
+ */
+public interface InputParser {
+
+ /**
+ * Get's called when hitting the submit button or pressing return/enter on the edit field. Use this message to
+ * proceed the input with your own parser.
+ *
+ * @param message
+ * the input of the text field
+ * @param console
+ * the console from which the message comes
+ * @return the message to show on the text area or <code>message</code> to forward the input to the
+ * {@link DeveloperConsole} parser.
+ */
+ public String parseInput(String message, DeveloperConsole console);
+
+ /**
+ * @param input
+ * the current typed input
+ * @return a list of possible commands for auto completion. can be null
+ */
+ public ArrayList<String> getAutoCompletionContent(String input);
+
+}
View
125 _RadicalFishDebug/src/de/radicalfish/debug/inputparser/PropertyInputParser.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2011, Stefan Lange
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Stefan Lange nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.radicalfish.debug.inputparser;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.regex.Pattern;
+import de.radicalfish.context.Settings;
+import de.radicalfish.debug.DeveloperConsole;
+
+/**
+ * Property parser for the {@link DeveloperConsole}. To change a property use this pattern:
+ *
+ * <pre>
+ * set name.of.property value
+ *
+ * e.g.
+ * set debug.hotboxes true
+ * </pre>
+ *
+ * @author Stefan Lange
+ * @version 1.0.0
+ * @since 14.05.2012
+ */
+public class PropertyInputParser implements InputParser {
+
+ private static Pattern split = Pattern.compile(" ");
+
+ private Settings settings;
+ private ArrayList<String> keys, compList;
+
+ public PropertyInputParser(Settings settings) {
+ this.settings = settings;
+
+ keys = new ArrayList<String>();
+ compList = new ArrayList<String>();
+ Iterator<String> set = settings.getAllSettings().keySet().iterator();
+
+ while (set.hasNext()) {
+ keys.add(set.next());
+ }
+ }
+
+ // INTERFACE
+ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
+ public String parseInput(String message, DeveloperConsole console) {
+ if (message.startsWith("set")) {
+ String pair[] = split.split(message);
+ if (pair.length == 3) {
+ if (settings.contains(pair[1])) {
+ settings.setProperty(pair[1], pair[2]);
+ return makeSuccessMessage(pair[1], "" + pair[2]);
+ } else {
+ return makeErrorMessage("No such Property: " + pair[1]);
+ }
+ } else {
+ return makeErrorMessage("Invalid parameter length. Use the format: \"set propertyname value\"");
+ }
+ }
+ return message;
+ }
+ public ArrayList<String> getAutoCompletionContent(String input) {
+ compList.clear();
+ if ("set".regionMatches(true, 0, input, 0, input.length())) {
+ compList.add("set");
+ return compList;
+ }
+ if (input.startsWith("set ")) {
+ input = input.replace("set ", "");
+ for (String temp : keys) {
+ if (temp.regionMatches(0, input, 0, input.length())) {
+ compList.add("set " + temp);
+ }
+ }
+ if (!compList.isEmpty()) {
+ return compList;
+ }
+ }
+ return null;
+ }
+
+ // INTERN
+ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
+
+ private String makeErrorMessage(String error) {
+ return "<div style=\"font:error\" >" + error + "</div>";
+ }
+ private String makeSuccessMessage(String prop, String value) {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("Assigned '");
+ sb.append("<span style=\"font:success\" >").append(prop).append("</span>");
+ sb.append("' with '");
+ sb.append("<span style=\"font:success\" >").append(value).append("</span>'");
+
+ return sb.toString();
+ }
+
+}
View
101 _RadicalFishDebug/src/de/radicalfish/debug/inputparser/URLInputParser.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2011, Stefan Lange
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Stefan Lange nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.radicalfish.debug.inputparser;
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+import de.radicalfish.debug.DeveloperConsole;
+
+/**
+ * URL parser for the {@link DeveloperConsole}. The parser uses the key word <b>url</b>. The URL must fit the common url
+ * style. supported protocols are:
+ * <p>
+ * <li>http/https (e.g. http://radicalfish.de</li>
+ * <li>www (e.g. www.radicalfish.de)</li>
+ * <li>ftp (e.g. ftp://files.com</li>
+ * <li>file (e.g. file://path/to/file</li>
+ * <hr>
+ *
+ * @author Stefan Lange
+ * @version 1.0.0
+ * @since 14.05.2012
+ */
+public class URLInputParser implements InputParser {
+
+ private static Pattern split = Pattern.compile(" ");
+ private static Pattern url = Pattern.compile("\\b(https?://|ftp://|file://|www)[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
+
+ private static ArrayList<String> keys = new ArrayList<String>();
+ static {
+ keys.add("url");
+ }
+
+ private ArrayList<String> compList = new ArrayList<String>();
+
+ // INTERFACE
+ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
+ public String parseInput(String message, DeveloperConsole console) {
+ if (message.startsWith("url")) {
+ String pair[] = split.split(message);
+ if (pair.length == 2) {
+ if (url.matcher(pair[1]).matches()) {
+ return makeLingMessage(pair[1]);
+ } else {
+ return makeErrorMessage("Invalid URL format: " + pair[1]);
+ }
+
+ } else {
+ return makeErrorMessage("Invalid parameter length. Use the format: \"url someurl\"");
+ }
+ }
+ return message;
+ }
+ public ArrayList<String> getAutoCompletionContent(String input) {
+ compList.clear();
+ if ("url".regionMatches(0, input, 0, input.length())) {
+ compList.add("url");
+ }
+
+ if (!compList.isEmpty()) {
+ return compList;
+ } else {
+ return null;
+ }
+ }
+
+ // INTERN
+ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
+ private String makeErrorMessage(String error) {
+ return "<div style=\"font:error\" >" + error + "</div>";
+ }
+ private String makeLingMessage(String link) {
+ return "<a style=\"font: link\" href=\"" + link + "\" >" + link + "</a>";
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.