Commits

Anonymous committed 1ea7671

Added demo cycling ability

Comments (0)

Files changed (3)

         </dependency>
 
         <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>14.0-rc2</version>
+        </dependency>
+
+        <dependency>
             <groupId>com.googlecode.jmockit</groupId>
             <artifactId>jmockit</artifactId>
             <version>1.0</version>

src/main/java/net/fishbulb/jcod/Console.java

         return min(countMatches(wrapped, '\n'), h);
     }
 
-
     /**
      * Calculates the number of lines that would be printed in the given rectangle according to printRect[Ex], but
      * without actually printing them.
      * @param msg Message to test
      * @return Number of lines that would be printed
      */
-
     public int getHeightRect(@SuppressWarnings("UnusedParameters") int x, int y, int w, int h, String msg) {
         String wrapped = wrap(msg, w);
         if (h == 0) {
         vline(x, y, l, blendFunction);
     }
 
-    //void printFrame(int x,int y,int w,int h, boolean clear=true, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT, String fmt=NULL, ...);
     public void printFrame(int x, int y, int w, int h, boolean clear, BlendFunction blend, String title) {
         // draw the corners
         putChar(x, y, CharCodes.OEM.NW, blend);
         }
     }
 
-
-
     protected class Cell {
         private char c;
         private Tile tile;

src/main/java/net/fishbulb/jcod/demo/Demo.java

 import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.scenes.scene2d.Stage;
 import com.badlogic.gdx.scenes.scene2d.actions.Actions;
+import com.google.common.collect.Iterators;
 import net.fishbulb.jcod.Console;
 import net.fishbulb.jcod.display.ImageTileset;
 import net.fishbulb.jcod.display.TileDisplay;
 import net.fishbulb.jcod.display.Tileset;
 import net.fishbulb.jcod.util.ImageUtils;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 public class Demo extends InputAdapter implements ApplicationListener {
     public static final int WIDTH = 80;
     public static final int HEIGHT = 50;
 
     DemoApplet active;
 
+    List<Class<? extends DemoApplet>> allApplets = new ArrayList<Class<? extends DemoApplet>>() {{
+        add(Colors.class);
+        add(Offscreen.class);
+    }};
+
+    Iterator<Class<? extends DemoApplet>> applets = Iterators.cycle(allApplets);
+
+    @SuppressWarnings("rawtypes")
+    private DemoApplet createApplet(Class<? extends DemoApplet> klass) {
+        try {
+            Constructor ctor = klass.getDeclaredConstructor(Console.class);
+            ctor.setAccessible(true);
+            return (DemoApplet) ctor.newInstance(root);
+        } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private void cycleApplet() {
+        active = createApplet(applets.next());
+    }
+
     @Override
     public void create() {
         Gdx.input.setInputProcessor(this);
         root = new Console(WIDTH, HEIGHT, tileset, display);
 
         stage.addActor(root.getDisplay());
-        active = new Colors(root);
+
+        cycleApplet();
 
         float xpos = (Gdx.app.getGraphics().getWidth() - (display.getPrefWidth() + APPLET_X + TILE_WIDTH)) / 2;
         float ypos = (Gdx.app.getGraphics().getHeight() - (display.getPrefHeight() + APPLET_Y + TILE_HEIGHT)) / 2;
         // drop down from top
         display.addAction(Actions.moveTo(xpos, Gdx.app.getGraphics().getHeight() + root.getHeight()));
         display.addAction(Actions.moveTo(xpos, ypos, 1));
-
     }
 
 
         // blitting the applet console is a really slow operation compared to directly rendering.
         // I don't feel like changing it at the moment
         Console ac = active.getConsole();
-        ac.blit(0,0,ac.getWidth(), ac.getHeight(),root, APPLET_X, APPLET_Y, 1, 1);
+        ac.blit(0, 0, ac.getWidth(), ac.getHeight(), root, APPLET_X, APPLET_Y, 1, 1);
         root.flush();
 
+        root.print(APPLET_X, APPLET_Y + active.getHeight() + 2, "Press space to switch between demos.");
+
         Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
         stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
         stage.draw();
         switch (keyCode) {
             case Input.Keys.ESCAPE:
                 Gdx.app.exit();
+                break;
             case Input.Keys.SPACE:
-                active = new Offscreen(root);
+                cycleApplet();
+                break;
 
         }
         return true;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.