Frameworkization, Keys configurable, Refactoring, Cleaning.

v5stable
Ondřej Hruška 11 years ago
parent baee0883b6
commit 09d0d34c51
  1. 54
      src/mightypork/gamecore/Config.java
  2. 10
      src/mightypork/gamecore/ConfigSetup.java
  3. 64
      src/mightypork/gamecore/WorkDir.java
  4. 204
      src/mightypork/gamecore/app/BaseApp.java
  5. 4
      src/mightypork/gamecore/gui/components/input/ClickableComponent.java
  6. 4
      src/mightypork/gamecore/gui/components/painters/TextPainter.java
  7. 5
      src/mightypork/gamecore/gui/screens/Overlay.java
  8. 5
      src/mightypork/gamecore/gui/screens/Screen.java
  9. 19
      src/mightypork/gamecore/input/InputSystem.java
  10. 4
      src/mightypork/gamecore/input/KeyBinder.java
  11. 31
      src/mightypork/gamecore/input/KeyBinding.java
  12. 9
      src/mightypork/gamecore/input/KeyBindingPool.java
  13. 114
      src/mightypork/gamecore/input/KeyConfig.java
  14. 7
      src/mightypork/gamecore/input/KeySetup.java
  15. 148
      src/mightypork/gamecore/input/KeyStroke.java
  16. 361
      src/mightypork/gamecore/input/Keys.java
  17. 15
      src/mightypork/gamecore/input/events/InputReadyEvent.java
  18. 7
      src/mightypork/gamecore/input/events/InputReadyListener.java
  19. 4
      src/mightypork/gamecore/input/events/KeyEvent.java
  20. 2
      src/mightypork/gamecore/input/events/KeyEventHandler.java
  21. 4
      src/mightypork/gamecore/input/events/MouseButtonEvent.java
  22. 2
      src/mightypork/gamecore/input/events/MouseButtonHandler.java
  23. 4
      src/mightypork/gamecore/input/events/MouseMotionEvent.java
  24. 2
      src/mightypork/gamecore/input/events/MouseMotionHandler.java
  25. 15
      src/mightypork/gamecore/render/DisplayReadyEvent.java
  26. 7
      src/mightypork/gamecore/render/DisplayReadyListener.java
  27. 2
      src/mightypork/gamecore/render/DisplaySystem.java
  28. 43
      src/mightypork/gamecore/resources/AsyncResourceLoader.java
  29. 12
      src/mightypork/gamecore/resources/BaseDeferredResource.java
  30. 4
      src/mightypork/gamecore/resources/DeferredResource.java
  31. 2
      src/mightypork/gamecore/resources/MustLoadInMainThread.java
  32. 101
      src/mightypork/gamecore/resources/Res.java
  33. 11
      src/mightypork/gamecore/resources/ResourceLoadRequest.java
  34. 29
      src/mightypork/gamecore/resources/ResourceLoader.java
  35. 38
      src/mightypork/gamecore/resources/ResourceSetup.java
  36. 15
      src/mightypork/gamecore/resources/audio/AudioReadyEvent.java
  37. 7
      src/mightypork/gamecore/resources/audio/AudioReadyListener.java
  38. 4
      src/mightypork/gamecore/resources/audio/DeferredAudio.java
  39. 4
      src/mightypork/gamecore/resources/audio/SoundSystem.java
  40. 20
      src/mightypork/gamecore/resources/events/ResourceLoadRequestListener.java
  41. 4
      src/mightypork/gamecore/resources/fonts/FontBank.java
  42. 6
      src/mightypork/gamecore/resources/fonts/impl/DeferredFont.java
  43. 6
      src/mightypork/gamecore/resources/textures/DeferredTexture.java
  44. 24
      src/mightypork/gamecore/resources/textures/TextureBank.java
  45. 107
      src/mightypork/gamecore/util/files/OsUtils.java
  46. 71
      src/mightypork/gamecore/util/files/config/Property.java
  47. 245
      src/mightypork/gamecore/util/files/config/PropertyManager.java
  48. 52
      src/mightypork/gamecore/util/objects/EnumerationIterator.java
  49. 84
      src/mightypork/rogue/Config.java
  50. 5
      src/mightypork/rogue/Const.java
  51. 59
      src/mightypork/rogue/Launcher.java
  52. 65
      src/mightypork/rogue/Paths.java
  53. 118
      src/mightypork/rogue/RogueApp.java
  54. 16
      src/mightypork/rogue/RogueConfig.java
  55. 23
      src/mightypork/rogue/RogueKeys.java
  56. 8
      src/mightypork/rogue/RogueMainLoop.java
  57. 127
      src/mightypork/rogue/RogueResources.java
  58. 8
      src/mightypork/rogue/RogueStateManager.java
  59. 12
      src/mightypork/rogue/events/GameStateRequest.java
  60. 5
      src/mightypork/rogue/screens/FpsOverlay.java
  61. 2
      src/mightypork/rogue/screens/LoadingOverlay.java
  62. 5
      src/mightypork/rogue/screens/game/AskSaveLayer.java
  63. 6
      src/mightypork/rogue/screens/game/DeathLayer.java
  64. 2
      src/mightypork/rogue/screens/game/HudLayer.java
  65. 2
      src/mightypork/rogue/screens/game/IngameNav.java
  66. 2
      src/mightypork/rogue/screens/game/InvSlot.java
  67. 17
      src/mightypork/rogue/screens/game/InventoryLayer.java
  68. 2
      src/mightypork/rogue/screens/game/NavButton.java
  69. 37
      src/mightypork/rogue/screens/game/ScreenGame.java
  70. 2
      src/mightypork/rogue/screens/game/WorldConsoleRenderer.java
  71. 2
      src/mightypork/rogue/screens/layout_testing/LayoutTestScreen.java
  72. 13
      src/mightypork/rogue/screens/menu/ScreenMainMenu.java
  73. 21
      src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java
  74. 2
      src/mightypork/rogue/screens/select_world/WorldSlot.java
  75. 6
      src/mightypork/rogue/world/WorldRenderer.java
  76. 2
      src/mightypork/rogue/world/entity/render/EntityRendererMobLR.java
  77. 4
      src/mightypork/rogue/world/gui/MapView.java
  78. 8
      src/mightypork/rogue/world/gui/Minimap.java
  79. 8
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java
  80. 2
      src/mightypork/rogue/world/item/impl/active/ItemHeartPiece.java
  81. 2
      src/mightypork/rogue/world/item/impl/food/ItemCheese.java
  82. 2
      src/mightypork/rogue/world/item/impl/food/ItemMeat.java
  83. 2
      src/mightypork/rogue/world/item/impl/food/ItemSandwich.java
  84. 2
      src/mightypork/rogue/world/item/impl/weapons/ItemAxe.java
  85. 2
      src/mightypork/rogue/world/item/impl/weapons/ItemBone.java
  86. 2
      src/mightypork/rogue/world/item/impl/weapons/ItemClub.java
  87. 2
      src/mightypork/rogue/world/item/impl/weapons/ItemKnife.java
  88. 2
      src/mightypork/rogue/world/item/impl/weapons/ItemRock.java
  89. 2
      src/mightypork/rogue/world/item/impl/weapons/ItemSword.java
  90. 2
      src/mightypork/rogue/world/item/impl/weapons/ItemTwig.java
  91. 4
      src/mightypork/rogue/world/tile/Tile.java
  92. 2
      src/mightypork/rogue/world/tile/TileRenderer.java
  93. 4
      src/mightypork/rogue/world/tile/impl/TileWithItems.java
  94. 2
      src/mightypork/rogue/world/tile/impl/brick/TileBrickChest.java
  95. 2
      src/mightypork/rogue/world/tile/impl/brick/TileBrickDoor.java
  96. 2
      src/mightypork/rogue/world/tile/impl/brick/TileBrickEntrance.java
  97. 2
      src/mightypork/rogue/world/tile/impl/brick/TileBrickExit.java
  98. 2
      src/mightypork/rogue/world/tile/impl/brick/TileBrickFloor.java
  99. 2
      src/mightypork/rogue/world/tile/impl/brick/TileBrickPassage.java
  100. 2
      src/mightypork/rogue/world/tile/impl/brick/TileBrickSecretDoor.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,54 @@
package mightypork.gamecore;
import java.io.File;
import mightypork.gamecore.util.files.config.PropertyManager;
/**
* Static application config file accessor
*
* @author MightyPork
*/
public class Config {
private static PropertyManager cfg;
public static void init(File file, String comment)
{
cfg = new PropertyManager(file, comment);
}
public static PropertyManager getProp()
{
return cfg;
}
public static void load()
{
cfg.load();
}
public static void save()
{
cfg.save();
}
public static <T> T get(String key)
{
return cfg.getValue(key);
}
public static <T> void set(String key, T value)
{
cfg.setValue(key, value);
}
}

@ -0,0 +1,10 @@
package mightypork.gamecore;
import mightypork.gamecore.util.files.config.PropertyManager;
public interface ConfigSetup {
void addOptions(PropertyManager prop);
}

@ -0,0 +1,64 @@
package mightypork.gamecore;
import java.io.File;
import mightypork.gamecore.logging.Log;
/**
* Static application workdir accessor.
*
* @author MightyPork
*/
public class WorkDir {
private static File workdir;
public static void init(File workdir)
{
WorkDir.workdir = workdir;
}
/**
* Get workdir folder, create if not exists.
*
* @param path dir path relative to workdir
* @return dir file
*/
public static File getDir(String path)
{
final File f = new File(workdir, path);
if (!f.exists() && !f.mkdirs()) {
Log.w("Could not create a directory: " + f);
}
return f;
}
/**
* Get workdir file, create parent if not exists.
*
* @param path dir path relative to workdir
* @return dir file
*/
public static File getFile(String path)
{
final File f = new File(workdir, path);
// create the parent dir
getDir(f.getParent());
return f;
}
public static File getWorkDir()
{
return workdir;
}
}

@ -3,19 +3,30 @@ package mightypork.gamecore.app;
import java.io.File;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import mightypork.gamecore.Config;
import mightypork.gamecore.ConfigSetup;
import mightypork.gamecore.WorkDir;
import mightypork.gamecore.eventbus.EventBus;
import mightypork.gamecore.eventbus.events.DestroyEvent;
import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.KeyConfig;
import mightypork.gamecore.input.KeySetup;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.logging.SlickLogRedirector;
import mightypork.gamecore.logging.writers.LogWriter;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.resources.AsyncResourceLoader;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.ResourceLoader;
import mightypork.gamecore.resources.ResourceSetup;
import mightypork.gamecore.resources.audio.SoundSystem;
import mightypork.gamecore.util.annot.DefaultImpl;
import mightypork.gamecore.util.files.InstanceLock;
@ -40,6 +51,72 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
private MainLoop gameLoop;
private ScreenRegistry screenRegistry;
private String logDirName = "log";
private String logFilePrefix = "runtime";
private int logArchiveCount = 0;
private boolean busLogging = false;
private String configFile = "settings.cfg";
private String configComment = "Main config file";
private final List<ResourceSetup> resourcesToLoad = new ArrayList<>();
private final List<KeySetup> keysToLoad = new ArrayList<>();
private final List<ConfigSetup> cfgsToLoad = new ArrayList<>();
private ResourceLoader resourceLoader = new AsyncResourceLoader();
private Level logLevel = Level.ALL;
public BaseApp(File workdir, boolean singleInstance)
{
WorkDir.init(workdir);
if (singleInstance) initLock();
}
public void setConfigFile(String filename, String comment)
{
this.configFile = filename;
this.configComment = comment;
}
public void setLogOptions(String logDir, String filePrefix, int archived, Level logLevel)
{
this.logDirName = logDir;
this.logFilePrefix = filePrefix;
this.logArchiveCount = archived;
this.logLevel = logLevel;
}
public void setBusLogging(boolean yes)
{
this.busLogging = yes;
}
public void addResources(ResourceSetup res)
{
this.resourcesToLoad.add(res);
}
public void addKeys(KeySetup keys)
{
this.keysToLoad.add(keys);
}
public void addConfig(ConfigSetup cfg)
{
this.cfgsToLoad.add(cfg);
}
public void setResourceLoader(ResourceLoader resLoader)
{
this.resourceLoader = resLoader;
}
/**
* Start the application
@ -48,6 +125,8 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
{
Thread.setDefaultUncaughtExceptionHandler(this);
Log.i("Using workdir: " + WorkDir.getWorkDir());
initialize();
Log.i("Starting main loop...");
@ -62,42 +141,45 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
*/
protected void initialize()
{
/*
* Lock working directory
*/
initLock();
Config.init(WorkDir.getFile(configFile), configComment);
for (final KeySetup l : keysToLoad) {
KeyConfig.addKeyLayout(l);
}
KeyConfig.inst().addOptions(Config.getProp());
for (final ConfigSetup cfgl : cfgsToLoad) {
cfgl.addOptions(Config.getProp());
}
Config.load();
/*
* Setup logging
*/
final LogWriter log = createLog();
if (log != null) {
Log.setMainLogger(log);
org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log));
}
final LogWriter log = Log.create(logFilePrefix, new File(WorkDir.getDir(logDirName), logFilePrefix + ".log"), logArchiveCount);
log.setLevel(logLevel);
Log.setMainLogger(log);
org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log));
Log.i("=== Starting initialization sequence ===");
// hook
Log.f2("Calling pre-init hook...");
preInit();
/*
* Ionizables
*/
Log.f3("initializing ION...");
registerIonizables();
/*
* Event bus
*/
Log.f2("Starting Event Bus...");
eventBus = new EventBus();
eventBus.detailedLogging = busLogging;
Log.f3("Registering channels...");
initBus(eventBus);
/*
* Ionizables
*/
Log.f3("initializing ION...");
registerIonizables();
/*
* Display
@ -134,7 +216,11 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
* Resources should be registered to banks, and AsyncResourceLoader will load them.
*/
Log.f1("Loading resources...");
initResources();
resourceLoader.init(this);
Res.init(this);
for (final ResourceSetup rl : resourcesToLoad) {
Res.load(rl);
}
/*
* Screen registry
@ -176,20 +262,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
}
/**
* Create and configure a log (using {@link Log})
*
* @return new log instance
*/
@DefaultImpl
protected LogWriter createLog()
{
final LogWriter log = Log.create("runtime", new File("runtime.log"));
log.setLevel(Level.ALL);
return log;
}
/**
* Create window and configure display system
*
@ -198,7 +270,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
@DefaultImpl
protected void initDisplay(DisplaySystem display)
{
display.createMainWindow(800, 600, true, false, "BaseApp using LWJGL display.");
display.createMainWindow(800, 600, true, false, "LWJGL game");
display.setTargetFps(60);
}
@ -214,26 +286,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
}
/**
* Configure input system (ie. define global keystrokes)
*
* @param input
*/
@DefaultImpl
protected void initInputSystem(InputSystem input)
{
}
/**
* Initialize resource banks.
*/
@DefaultImpl
protected void initResources()
{
}
/**
* Register game screens to the registry.
*
@ -254,37 +306,25 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
protected abstract MainLoop createMainLoop();
/**
* Initialize event bus. Usually, no action is needed, since the bus
* automatically recognizes new event types.
*
* @param bus
*/
@DefaultImpl
protected void initBus(EventBus bus)
{
}
/*
* Try to obtain lock.
*/
private void initLock()
{
final File lockFile = getLockFile();
if (lockFile == null) {
// lock off
return;
}
if (!InstanceLock.onFile(lockFile)) {
final File lock = WorkDir.getFile(".lock");
if (!InstanceLock.onFile(lock)) {
onLockError();
return;
}
}
@DefaultImpl
protected void initInputSystem(InputSystem input)
{
}
/**
* Triggered when lock cannot be obtained.<br>
* App should terminate gracefully.
@ -306,18 +346,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
}
/**
* Get lock file path; Used to enforce single-instance policy.
*
* @return lock file, or null to disable lock.
*/
@DefaultImpl
protected File getLockFile()
{
return new File(".lock");
}
@Override
public final SoundSystem getSoundSystem()
{

@ -5,10 +5,10 @@ import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.ActionTrigger;
import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.input.events.MouseButtonEvent;
import mightypork.gamecore.input.events.MouseButtonListener;
import mightypork.gamecore.input.events.MouseButtonHandler;
public abstract class ClickableComponent extends InputComponent implements ActionTrigger, MouseButtonListener {
public abstract class ClickableComponent extends InputComponent implements ActionTrigger, MouseButtonHandler {
protected boolean btnDownOver;
private Action action;

@ -14,7 +14,6 @@ import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.strings.StringProvider;
import mightypork.gamecore.util.strings.StringWrapper;
import mightypork.rogue.Config;
/**
@ -24,6 +23,7 @@ import mightypork.rogue.Config;
*/
public class TextPainter extends BaseComponent implements DynamicWidthComponent {
private static final boolean DEBUG_FONT_RENDER = false;
private final FontRenderer font;
private Color color;
private AlignX align;
@ -102,7 +102,7 @@ public class TextPainter extends BaseComponent implements DynamicWidthComponent
final Rect r = (shadow ? rect.move(shadowOffset.neg()) : rect).round();
font.draw(str, r, align, color);
if (Config.DEBUG_FONT_RENDER) Render.quadColor(r, RGB.PINK.withAlpha(0.4));
if (DEBUG_FONT_RENDER) Render.quadColor(r, RGB.PINK.withAlpha(0.4));
}

@ -14,6 +14,7 @@ import mightypork.gamecore.gui.events.LayoutChangeListener;
import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.render.Renderable;
import mightypork.gamecore.util.annot.DefaultImpl;
import mightypork.gamecore.util.math.color.Color;
@ -64,9 +65,9 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
@Override
public final void bindKey(KeyStroke stroke, Runnable task)
public final void bindKey(KeyStroke stroke, Edge edge, Runnable task)
{
keybindings.bindKey(stroke, task);
keybindings.bindKey(stroke, edge, task);
}

@ -8,6 +8,7 @@ import mightypork.gamecore.gui.events.LayoutChangeListener;
import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.render.Renderable;
@ -50,9 +51,9 @@ public abstract class Screen extends AppSubModule implements Renderable, RectBou
@Override
public final void bindKey(KeyStroke stroke, Runnable task)
public final void bindKey(KeyStroke stroke, Edge edge, Runnable task)
{
keybindings.bindKey(stroke, task);
keybindings.bindKey(stroke, edge, task);
}

@ -4,6 +4,8 @@ package mightypork.gamecore.input;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.eventbus.clients.RootBusNode;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.events.InputReadyEvent;
import mightypork.gamecore.input.events.KeyEvent;
import mightypork.gamecore.input.events.MouseButtonEvent;
import mightypork.gamecore.input.events.MouseMotionEvent;
@ -64,6 +66,8 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
// global keybindings
keybindings = new KeyBindingPool();
addChildClient(keybindings);
getEventBus().send(new InputReadyEvent());
}
@ -91,9 +95,9 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
@Override
public final void bindKey(KeyStroke stroke, Runnable task)
public final void bindKey(KeyStroke stroke, Edge edge, Runnable task)
{
keybindings.bindKey(stroke, task);
keybindings.bindKey(stroke, edge, task);
}
@ -217,7 +221,10 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
}
public static int getModifierKeys()
/**
* @return bit mask of active mod keys
*/
public static int getActiveModKeys()
{
int mods = 0;
@ -239,4 +246,10 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
return mods;
}
public static boolean isReady()
{
return inited;
}
}

@ -2,6 +2,7 @@ package mightypork.gamecore.input;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.input.KeyStroke.Edge;
/**
@ -14,10 +15,11 @@ public interface KeyBinder {
/**
* Bind handler to a keystroke, replace current handler if any
*
* @param edge trigger edge
* @param stroke trigger keystroke
* @param task handler; can be {@link Runnable} or {@link Action}
*/
void bindKey(KeyStroke stroke, Runnable task);
void bindKey(KeyStroke stroke, Edge edge, Runnable task);
/**

@ -1,8 +1,10 @@
package mightypork.gamecore.input;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.events.InputReadyListener;
import mightypork.gamecore.input.events.KeyEvent;
import mightypork.gamecore.input.events.KeyListener;
import mightypork.gamecore.input.events.KeyEventHandler;
/**
@ -10,23 +12,25 @@ import mightypork.gamecore.input.events.KeyListener;
*
* @author MightyPork
*/
public class KeyBinding implements KeyListener {
public class KeyBinding implements KeyEventHandler, InputReadyListener {
private final KeyStroke keystroke;
private Runnable handler;
private boolean wasActive = false;
private final Edge edge;
/**
* @param edge trigger edge
* @param stroke trigger keystroke
* @param handler action
*/
public KeyBinding(KeyStroke stroke, Runnable handler)
public KeyBinding(KeyStroke stroke, Edge edge, Runnable handler)
{
this.keystroke = stroke;
this.handler = handler;
this.edge = edge;
wasActive = keystroke.isActive();
if (InputSystem.isReady()) keystroke.poll();
}
@ -54,18 +58,17 @@ public class KeyBinding implements KeyListener {
@Override
public void receive(KeyEvent event)
{
/*Log.f3("evt k="+event.getKey()+", c="+(int)event.getChar());
// ignore unrelated events
if (!keystroke.getKeys().contains(event.getKey())) return;
*/
// run handler when event was met
if (keystroke.isActive() && !wasActive) {
if (keystroke.tryTrigger(edge)) {
handler.run();
}
wasActive = keystroke.isActive();
}
@Override
public void onInputReady()
{
keystroke.poll();
}
}

@ -5,8 +5,9 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.events.KeyEvent;
import mightypork.gamecore.input.events.KeyListener;
import mightypork.gamecore.input.events.KeyEventHandler;
import mightypork.gamecore.logging.Log;
@ -15,7 +16,7 @@ import mightypork.gamecore.logging.Log;
*
* @author MightyPork
*/
public class KeyBindingPool implements KeyBinder, KeyListener {
public class KeyBindingPool implements KeyBinder, KeyEventHandler {
private final Set<KeyBinding> bindings = new HashSet<>();
@ -27,7 +28,7 @@ public class KeyBindingPool implements KeyBinder, KeyListener {
* @param task handler
*/
@Override
public void bindKey(KeyStroke stroke, Runnable task)
public void bindKey(KeyStroke stroke, Edge edge, Runnable task)
{
for (final KeyBinding kb : bindings) {
if (kb.matches(stroke)) {
@ -37,7 +38,7 @@ public class KeyBindingPool implements KeyBinder, KeyListener {
}
}
bindings.add(new KeyBinding(stroke, task));
bindings.add(new KeyBinding(stroke, edge, task));
}

@ -0,0 +1,114 @@
package mightypork.gamecore.input;
import java.util.HashMap;
import java.util.Map;
import mightypork.gamecore.ConfigSetup;
import mightypork.gamecore.util.files.config.Property;
import mightypork.gamecore.util.files.config.PropertyManager;
public class KeyConfig implements ConfigSetup {
private static KeyConfig inst = new KeyConfig();
/**
* Key property.<br>
* The stored value must be invariant ({@link KeyStroke} is mutable).
*
* @author MightyPork
*/
private static class KeyProperty extends Property<KeyStroke> {
public KeyProperty(String key, KeyStroke defaultValue, String comment)
{
super(key, defaultValue, comment);
}
@Override
public KeyStroke decode(String string, KeyStroke defval)
{
if (string != null) {
// keep it invariant
final int backup_key = getValue().getKey();
final int backup_mod = getValue().getMod();
getValue().fromDataString(string);
if (getValue().getKey() == Keys.NONE) {
getValue().setTo(backup_key, backup_mod);
}
}
return getValue();
}
@Override
public String encode(KeyStroke value)
{
return value.toDataString();
}
@Override
public void setValue(Object value)
{
// keep it invariant
getValue().setTo(((KeyStroke) value).getKey(), ((KeyStroke) value).getMod());
}
}
private static Map<String, KeyProperty> strokes = new HashMap<>();
private static PropertyManager prop;
public static void addKeyLayout(KeySetup layout)
{
layout.addKeys(inst);
}
@Override
public void addOptions(PropertyManager prop)
{
for (final KeyProperty kp : strokes.values()) {
prop.putProperty(kp);
}
this.prop = prop;
}
public void add(String cfgKey, String dataString)
{
strokes.put(cfgKey, new KeyProperty(cfgKey, KeyStroke.createFromDataString(dataString), null));
}
public static KeyStroke get(String cfgKey)
{
final KeyProperty kp = strokes.get(cfgKey);
if (kp == null) throw new IllegalArgumentException("No such stroke: " + cfgKey);
return kp.getValue();
}
public static void set(String cfgKey, int key, int mod)
{
final KeyProperty kp = strokes.get(cfgKey);
if (kp == null) throw new IllegalArgumentException("No such stroke: " + cfgKey);
kp.getValue().setTo(key, mod);
prop.save();
}
public static KeyConfig inst()
{
return inst;
}
}

@ -0,0 +1,7 @@
package mightypork.gamecore.input;
public interface KeySetup {
public void addKeys(KeyConfig keys);
}

@ -1,6 +1,9 @@
package mightypork.gamecore.input;
import mightypork.gamecore.util.math.constraints.Pollable;
import mightypork.gamecore.util.strings.StringUtils;
import org.lwjgl.input.Keyboard;
@ -9,37 +12,28 @@ import org.lwjgl.input.Keyboard;
*
* @author MightyPork
*/
public class KeyStroke {
private final int mod;
private final int key;
private final boolean fallingEdge;
public class KeyStroke implements Pollable {
/**
* KeyStroke
*
* @param fallingEdge true for falling edge, up for rising edge
* @param mod_mask mods mask
* @param key key code
*/
public KeyStroke(boolean fallingEdge, int key, int mod_mask)
public static enum Edge
{
this.fallingEdge = fallingEdge;
this.key = key;
this.mod = mod_mask;
FALLING, RISING;
}
private int mod;
private int key;
private boolean wasDown;
/**
* Rising edge keystroke
* KeyStroke
*
* @param mod_mask mods mask
* @param key key code
* @param mod_mask mods mask
*/
public KeyStroke(int key, int mod_mask)
{
this(false, key, mod_mask);
setTo(key, mod_mask);
}
@ -50,59 +44,126 @@ public class KeyStroke {
*/
public KeyStroke(int key)
{
this(false, key, Keys.MOD_NONE);
this(key, Keys.MOD_NONE);
}
/**
* @return true if the keystroke is currently satisfied (keys pressed)
* @return true if the keystroke is currently down & modifiers match.
*/
public boolean isActive()
public boolean isDown()
{
boolean st = Keyboard.isKeyDown(key);
st &= (InputSystem.getModifierKeys() == mod);
st &= (InputSystem.getActiveModKeys() == mod);
return fallingEdge ? st : !st;
return st;
}
public void setTo(int key, int mod_mask)
{
this.key = key;
this.mod = mod_mask | Keys.keyToMod(key); // for mods alone
this.wasDown = (InputSystem.isReady() ? isDown() : false);
}
/**
* Set current state as the last state (ignore it on next trigger event)
*/
@Override
public String toString()
public void poll()
{
String s = "(";
if ((mod & Keys.MOD_CONTROL) != 0) {
s += "CTRL+";
}
wasDown = isDown();
}
public boolean tryTrigger(Edge edge)
{
final boolean down = isDown() && !wasDown;
final boolean up = !isDown() && wasDown;
if ((mod & Keys.MOD_ALT) != 0) {
s += "ALT+";
}
boolean retval = false;
if ((mod & Keys.MOD_SHIFT) != 0) {
s += "SHIFT+";
switch (edge) {
case FALLING:
retval = !wasDown && down;
break;
case RISING:
retval = wasDown && up;
break;
}
if ((mod & Keys.MOD_META) != 0) {
s += "META+";
}
wasDown = isDown();
s += Keyboard.getKeyName(key);
return retval;
}
public String toDataString()
{
String s = "";
s += fallingEdge ? ",DOWN" : ",UP";
if (mod != Keys.MOD_NONE) s = Keys.modToString(mod);
s += ")";
s += Keys.keyToString(key);
return s;
}
public static KeyStroke createFromDataString(String dataString)
{
final KeyStroke ks = new KeyStroke(Keys.NONE, Keys.MOD_NONE);
ks.fromDataString(dataString);
return ks;
}
public void fromDataString(String dataString)
{
final String dataString1 = dataString.toUpperCase().replace('-', '+').replaceAll("[^A-Z0-9_+]", "");
if (dataString1.contains("+")) {
final String keyStr = StringUtils.fromLastChar(dataString1, '+');
final String modStr = StringUtils.toLastChar(dataString1, '+');
this.key = Keys.keyFromString(keyStr);
this.mod = Keys.modFromString(modStr);
} else {
this.key = Keys.keyFromString(dataString1);
this.mod = Keys.MOD_NONE;
}
}
public int getKey()
{
return key;
}
public int getMod()
{
return mod;
}
@Override
public String toString()
{
return toDataString();
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + (fallingEdge ? 1231 : 1237);
result = prime * result + key;
result = prime * result + mod;
return result;
@ -116,7 +177,6 @@ public class KeyStroke {
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final KeyStroke other = (KeyStroke) obj;
if (fallingEdge != other.fallingEdge) return false;
if (key != other.key) return false;
if (mod != other.mod) return false;
return true;

@ -1,6 +1,10 @@
package mightypork.gamecore.input;
import java.util.HashMap;
import mightypork.gamecore.logging.Log;
import org.lwjgl.input.Keyboard;
@ -9,135 +13,252 @@ import org.lwjgl.input.Keyboard;
*
* @author MightyPork
*/
public interface Keys {
public class Keys {
//@formatter:off
public static final int NONE = 0x00;
public static final int NONE = Keyboard.KEY_NONE;
public static final int ESCAPE = 0x01;
public static final int NUM_1 = 0x02;
public static final int NUM_2 = 0x03;
public static final int NUM_3 = 0x04;
public static final int NUM_4 = 0x05;
public static final int NUM_5 = 0x06;
public static final int NUM_6 = 0x07;
public static final int NUM_7 = 0x08;
public static final int NUM_8 = 0x09;
public static final int NUM_9 = 0x0A;
public static final int NUM_0 = 0x0B;
public static final int Q = 0x10;
public static final int W = 0x11;
public static final int E = 0x12;
public static final int R = 0x13;
public static final int T = 0x14;
public static final int Y = 0x15;
public static final int U = 0x16;
public static final int I = 0x17;
public static final int O = 0x18;
public static final int P = 0x19;
public static final int A = 0x1E;
public static final int S = 0x1F;
public static final int D = 0x20;
public static final int F = 0x21;
public static final int G = 0x22;
public static final int H = 0x23;
public static final int J = 0x24;
public static final int K = 0x25;
public static final int L = 0x26;
public static final int Z = 0x2C;
public static final int X = 0x2D;
public static final int C = 0x2E;
public static final int V = 0x2F;
public static final int B = 0x30;
public static final int N = 0x31;
public static final int M = 0x32;
public static final int ESCAPE = Keyboard.KEY_ESCAPE;
public static final int NUM_1 = Keyboard.KEY_1;
public static final int NUM_2 = Keyboard.KEY_2;
public static final int NUM_3 = Keyboard.KEY_3;
public static final int NUM_4 = Keyboard.KEY_4;
public static final int NUM_5 = Keyboard.KEY_5;
public static final int NUM_6 = Keyboard.KEY_6;
public static final int NUM_7 = Keyboard.KEY_7;
public static final int NUM_8 = Keyboard.KEY_8;
public static final int NUM_9 = Keyboard.KEY_9;
public static final int NUM_0 = Keyboard.KEY_0;
public static final int Q = Keyboard.KEY_Q;
public static final int W = Keyboard.KEY_W;
public static final int E = Keyboard.KEY_E;
public static final int R = Keyboard.KEY_R;
public static final int T = Keyboard.KEY_T;
public static final int Y = Keyboard.KEY_Y;
public static final int U = Keyboard.KEY_U;
public static final int I = Keyboard.KEY_I;
public static final int O = Keyboard.KEY_O;
public static final int P = Keyboard.KEY_P;
public static final int A = Keyboard.KEY_A;
public static final int S = Keyboard.KEY_S;
public static final int D = Keyboard.KEY_D;
public static final int F = Keyboard.KEY_F;
public static final int G = Keyboard.KEY_G;
public static final int H = Keyboard.KEY_H;
public static final int J = Keyboard.KEY_J;
public static final int K = Keyboard.KEY_K;
public static final int L = Keyboard.KEY_L;
public static final int Z = Keyboard.KEY_Z;
public static final int X = Keyboard.KEY_X;
public static final int C = Keyboard.KEY_C;
public static final int V = Keyboard.KEY_V;
public static final int B = Keyboard.KEY_B;
public static final int N = Keyboard.KEY_N;
public static final int M = Keyboard.KEY_M;
public static final int MINUS = 0x0C;
public static final int EQUALS = 0x0D;
public static final int SLASH = 0x35;
public static final int BACKSLASH = 0x2B;
public static final int L_BRACKET = 0x1A;
public static final int R_BRACKET = 0x1B;
public static final int SEMICOLON = 0x27;
public static final int APOSTROPHE = 0x28;
public static final int GRAVE = 0x29;
public static final int COMMA = 0x33;
public static final int PERIOD = 0x34;
public static final int SPACE = 0x39;
public static final int BACKSPACE = 0x0E;
public static final int TAB = 0x0F;
public static final int F1 = 0x3B;
public static final int F2 = 0x3C;
public static final int F3 = 0x3D;
public static final int F4 = 0x3E;
public static final int F5 = 0x3F;
public static final int F6 = 0x40;
public static final int F7 = 0x41;
public static final int F8 = 0x42;
public static final int F9 = 0x43;
public static final int F10 = 0x44;
public static final int F11 = 0x57;
public static final int F12 = 0x58;
public static final int F13 = 0x64;
public static final int F14 = 0x65;
public static final int F15 = 0x66;
public static final int MINUS = Keyboard.KEY_MINUS;
public static final int EQUALS = Keyboard.KEY_EQUALS;
public static final int SLASH = Keyboard.KEY_SLASH;
public static final int BACKSLASH = Keyboard.KEY_BACKSLASH;
public static final int L_BRACKET = Keyboard.KEY_LBRACKET;
public static final int R_BRACKET = Keyboard.KEY_RBRACKET;
public static final int SEMICOLON = Keyboard.KEY_SEMICOLON;
public static final int APOSTROPHE = Keyboard.KEY_APOSTROPHE;
public static final int GRAVE = Keyboard.KEY_GRAVE;
public static final int COMMA = Keyboard.KEY_COMMA;
public static final int PERIOD = Keyboard.KEY_PERIOD;
public static final int SPACE = Keyboard.KEY_SPACE;
public static final int BACKSPACE = Keyboard.KEY_BACK;
public static final int TAB = Keyboard.KEY_TAB;
public static final int F1 = Keyboard.KEY_F1;
public static final int F2 = Keyboard.KEY_F2;
public static final int F3 = Keyboard.KEY_F3;
public static final int F4 = Keyboard.KEY_F4;
public static final int F5 = Keyboard.KEY_F5;
public static final int F6 = Keyboard.KEY_F6;
public static final int F7 = Keyboard.KEY_F7;
public static final int F8 = Keyboard.KEY_F8;
public static final int F9 = Keyboard.KEY_F9;
public static final int F10 = Keyboard.KEY_F10;
public static final int F11 = Keyboard.KEY_F11;
public static final int F12 = Keyboard.KEY_F12;
public static final int F13 = Keyboard.KEY_F13;
public static final int F14 = Keyboard.KEY_F14;
public static final int F15 = Keyboard.KEY_F15;
public static final int CAPS_LOCK = 0x3A;
public static final int SCROLL_LOCK = 0x46;
public static final int NUM_LOCK = 0x45;
public static final int SUBTRACT = 0x4A; /* - on numeric keypad */
public static final int ADD = 0x4E; /* + on numeric keypad */
public static final int NUMPAD_0 = 0x52;
public static final int NUMPAD_1 = 0x4F;
public static final int NUMPAD_2 = 0x50;
public static final int NUMPAD_3 = 0x51;
public static final int NUMPAD_4 = 0x4B;
public static final int NUMPAD_5 = 0x4C;
public static final int NUMPAD_6 = 0x4D;
public static final int NUMPAD_7 = 0x47;
public static final int NUMPAD_8 = 0x48;
public static final int NUMPAD_9 = 0x49;
public static final int DECIMAL = 0x53; /* . on numeric keypad */
public static final int NUMPAD_ENTER = 0x9C; /* Enter on numeric keypad */
public static final int DIVIDE = 0xB5; /* / on numeric keypad */
public static final int MULTIPLY = 0x37; /* * on numeric keypad */
public static final int L_CONTROL = 0x1D;
public static final int R_CONTROL = 0x9D;
public static final int L_ALT = 0x38;
public static final int R_ALT = 0xB8;
public static final int L_SHIFT = 0x2A;
public static final int R_SHIFT = 0x36;
public static final int L_META = 0xDB;
public static final int R_META = 0xDC;
public static final int UP = 0xC8; /* UpArrow on arrow keypad */
public static final int DOWN = 0xD0; /* DownArrow on arrow keypad */
public static final int LEFT = 0xCB; /* LeftArrow on arrow keypad */
public static final int RIGHT = 0xCD; /* RightArrow on arrow keypad */
public static final int CAPS_LOCK = Keyboard.KEY_CAPITAL;
public static final int SCROLL_LOCK = Keyboard.KEY_SCROLL;
public static final int NUM_LOCK = Keyboard.KEY_NUMLOCK;
public static final int NUMPAD_MINUS = Keyboard.KEY_SUBTRACT;
public static final int NUMPAD_PLUSS = Keyboard.KEY_ADD;
public static final int NUMPAD_0 = Keyboard.KEY_NUMPAD0;
public static final int NUMPAD_1 = Keyboard.KEY_NUMPAD1;
public static final int NUMPAD_2 = Keyboard.KEY_NUMPAD2;
public static final int NUMPAD_3 = Keyboard.KEY_NUMPAD3;
public static final int NUMPAD_4 = Keyboard.KEY_NUMPAD4;
public static final int NUMPAD_5 = Keyboard.KEY_NUMPAD5;
public static final int NUMPAD_6 = Keyboard.KEY_NUMPAD6;
public static final int NUMPAD_7 = Keyboard.KEY_NUMPAD7;
public static final int NUMPAD_8 = Keyboard.KEY_NUMPAD8;
public static final int NUMPAD_9 = Keyboard.KEY_NUMPAD9;
public static final int NUMPAD_DECIMAL = Keyboard.KEY_DECIMAL;
public static final int NUMPAD_ENTER = Keyboard.KEY_NUMPADENTER;
public static final int NUMPAD_DIVIDE = Keyboard.KEY_DIVIDE;
public static final int NUMPAD_MULTIPLY = Keyboard.KEY_MULTIPLY;
public static final int L_CONTROL = Keyboard.KEY_LCONTROL;
public static final int R_CONTROL = Keyboard.KEY_RCONTROL;
public static final int L_ALT = Keyboard.KEY_LMENU;
public static final int R_ALT = Keyboard.KEY_RMENU;
public static final int L_SHIFT = Keyboard.KEY_LSHIFT;
public static final int R_SHIFT = Keyboard.KEY_RSHIFT;
public static final int L_META = Keyboard.KEY_LMETA;
public static final int R_META = Keyboard.KEY_RMETA;
public static final int UP = Keyboard.KEY_UP;
public static final int DOWN = Keyboard.KEY_DOWN;
public static final int LEFT = Keyboard.KEY_LEFT;
public static final int RIGHT = Keyboard.KEY_RIGHT;
public static final int HOME = 0xC7; /* Home on arrow keypad */
public static final int END = 0xCF; /* End on arrow keypad */
public static final int HOME = Keyboard.KEY_HOME;
public static final int END = Keyboard.KEY_END;
public static final int PAGE_UP = 0xC9; /* PgUp on arrow keypad */
public static final int PAGE_DOWN = 0xD1; /* PgDn on arrow keypad */
public static final int PAGE_UP = Keyboard.KEY_PRIOR;
public static final int PAGE_DOWN = Keyboard.KEY_NEXT;
public static final int RETURN = 0x1C;
public static final int PAUSE = 0xC5; /* Pause */
public static final int INSERT = 0xD2; /* Insert on arrow keypad */
public static final int DELETE = 0xD3; /* Delete on arrow keypad */
public static final int RETURN = Keyboard.KEY_RETURN;
public static final int PAUSE = Keyboard.KEY_PAUSE;
public static final int INSERT = Keyboard.KEY_INSERT;
public static final int DELETE = Keyboard.KEY_DELETE;
public static final byte MOD_NONE = 0;
public static final byte MOD_ALT = 1;
public static final byte MOD_CONTROL = 2;
public static final byte MOD_SHIFT = 4;
public static final byte MOD_META = 8;
public static final byte MOD_NONE = 0;
public static final byte MOD_ALT = 1;
public static final byte MOD_CONTROL = 2;
public static final byte MOD_SHIFT = 4;
public static final byte MOD_META = 8;
//@formatter:on
private static HashMap<String, String> loadAliasMap = new HashMap<>();
private static HashMap<String, String> saveAliasMap = new HashMap<>();
static {
// init maps
loadAliasMap.put("ENTER", "RETURN");
loadAliasMap.put("PGDN", "NEXT");
loadAliasMap.put("PGUP", "PRIOR");
loadAliasMap.put("PAGE_DOWN", "NEXT");
loadAliasMap.put("PAGE_UP", "PRIOR");
loadAliasMap.put("SPACEBAR", "SPACE");
loadAliasMap.put("ESC", "ESCAPE");
loadAliasMap.put("NUMPAD_DIVIDE", "DIVIDE");
loadAliasMap.put("NUMPAD_MULTIPLY", "MULTIPLY");
loadAliasMap.put("NUMPAD_ADD", "ADD");
loadAliasMap.put("NUMPAD_SUBTRACT", "SUBTRACT");
loadAliasMap.put("CAPS_LOCK", "CAPITAL");
loadAliasMap.put("SCROLL_LOCK", "SROLL");
loadAliasMap.put("NUM_LOCK", "NUMLOCK");
loadAliasMap.put("BACKSPACE", "BACK");
saveAliasMap.put("RETURN", "ENTER");
saveAliasMap.put("NEXT", "PAGE_DOWN");
saveAliasMap.put("PRIOR", "PAGE_UP");
saveAliasMap.put("DIVIDE", "NUMPAD_DIVIDE");
saveAliasMap.put("MULTIPLY", "NUMPAD_MULTIPLY");
saveAliasMap.put("ADD", "NUMPAD_ADD");
saveAliasMap.put("SUBTRACT", "NUMPAD_SUBTRACT");
saveAliasMap.put("CAPITAL", "CAPS_LOCK");
saveAliasMap.put("SROLL", "SCROLL_LOCK");
saveAliasMap.put("NUMLOCK", "NUM_LOCK");
saveAliasMap.put("BACK", "BACKSPACE");
}
public static int keyFromString(String key)
{
String key1 = key;
if (loadAliasMap.containsKey(key1)) key1 = loadAliasMap.get(key1);
final int index = Keyboard.getKeyIndex(key1);
if (index == Keys.NONE && !key1.equals("NONE")) {
Log.w("Could not parse key: " + key + " (" + key1 + ")");
}
return index;
}
public static int modFromString(String mod)
{
int mod_mask = Keys.MOD_NONE;
if (mod.contains("CTRL")) {
mod_mask |= Keys.MOD_CONTROL;
}
if (mod.contains("ALT")) {
mod_mask |= Keys.MOD_ALT;
}
if (mod.contains("SHIFT")) {
mod_mask |= Keys.MOD_SHIFT;
}
if (mod.contains("META") || mod.contains("WIN")) {
mod_mask |= Keys.MOD_META;
}
return mod_mask;
}
public static String modToString(int mod)
{
String s = "";
if ((mod & Keys.MOD_CONTROL) != 0) {
s += "CTRL+";
}
if ((mod & Keys.MOD_ALT) != 0) {
s += "ALT+";
}
if ((mod & Keys.MOD_SHIFT) != 0) {
s += "SHIFT+";
}
if ((mod & Keys.MOD_META) != 0) {
s += "META+";
}
return s;
}
public static String keyToString(int key)
{
String s = Keyboard.getKeyName(key);
if (saveAliasMap.containsKey(s)) s = saveAliasMap.get(s);
if (s == null) {
Log.w("Could not stringify key: " + key);
s = "NONE";
}
return s.toUpperCase();
}
public static int keyToMod(int key)
{
if (key == L_SHIFT || key == R_SHIFT) return MOD_SHIFT;
if (key == L_CONTROL || key == R_CONTROL) return MOD_CONTROL;
if (key == L_ALT || key == R_ALT) return MOD_ALT;
if (key == L_META || key == R_META) return MOD_META;
return MOD_NONE;
}
}

@ -0,0 +1,15 @@
package mightypork.gamecore.input.events;
import mightypork.gamecore.eventbus.BusEvent;
public class InputReadyEvent extends BusEvent<InputReadyListener> {
@Override
protected void handleBy(InputReadyListener handler)
{
handler.onInputReady();
}
}

@ -0,0 +1,7 @@
package mightypork.gamecore.input.events;
public interface InputReadyListener {
void onInputReady();
}

@ -13,7 +13,7 @@ import org.lwjgl.input.Keyboard;
* @author MightyPork
*/
@NotLoggedEvent
public class KeyEvent extends BusEvent<KeyListener> {
public class KeyEvent extends BusEvent<KeyEventHandler> {
private final int key;
private final boolean down;
@ -70,7 +70,7 @@ public class KeyEvent extends BusEvent<KeyListener> {
@Override
public void handleBy(KeyListener keh)
public void handleBy(KeyEventHandler keh)
{
keh.receive(this);
}

@ -6,7 +6,7 @@ package mightypork.gamecore.input.events;
*
* @author MightyPork
*/
public interface KeyListener {
public interface KeyEventHandler {
/**
* Handle an event

@ -14,7 +14,7 @@ import mightypork.gamecore.util.math.constraints.vect.VectConst;
* @author MightyPork
*/
@NotLoggedEvent
public class MouseButtonEvent extends BusEvent<MouseButtonListener> {
public class MouseButtonEvent extends BusEvent<MouseButtonHandler> {
public static final int BUTTON_LEFT = 0;
public static final int BUTTON_MIDDLE = 1;
@ -119,7 +119,7 @@ public class MouseButtonEvent extends BusEvent<MouseButtonListener> {
@Override
public void handleBy(MouseButtonListener handler)
public void handleBy(MouseButtonHandler handler)
{
handler.receive(this);
}

@ -6,7 +6,7 @@ package mightypork.gamecore.input.events;
*
* @author MightyPork
*/
public interface MouseButtonListener {
public interface MouseButtonHandler {
/**
* Handle an event

@ -13,7 +13,7 @@ import mightypork.gamecore.util.math.constraints.vect.VectConst;
* @author MightyPork
*/
@NotLoggedEvent
public class MouseMotionEvent extends BusEvent<MouseMotionListener> {
public class MouseMotionEvent extends BusEvent<MouseMotionHandler> {
private final VectConst move;
private final VectConst pos;
@ -49,7 +49,7 @@ public class MouseMotionEvent extends BusEvent<MouseMotionListener> {
@Override
public void handleBy(MouseMotionListener keh)
public void handleBy(MouseMotionHandler keh)
{
keh.receive(this);
}

@ -6,7 +6,7 @@ package mightypork.gamecore.input.events;
*
* @author MightyPork
*/
public interface MouseMotionListener {
public interface MouseMotionHandler {
/**
* Handle an event

@ -0,0 +1,15 @@
package mightypork.gamecore.render;
import mightypork.gamecore.eventbus.BusEvent;
public class DisplayReadyEvent extends BusEvent<DisplayReadyListener> {
@Override
protected void handleBy(DisplayReadyListener handler)
{
handler.onDisplayReady();
}
}

@ -0,0 +1,7 @@
package mightypork.gamecore.render;
public interface DisplayReadyListener {
void onDisplayReady();
}

@ -104,6 +104,8 @@ public class DisplaySystem extends AppModule implements RectBound {
Display.update();
}
getEventBus().send(new DisplayReadyEvent());
} catch (final LWJGLException e) {
throw new RuntimeException("Could not initialize screen", e);
}

@ -1,4 +1,4 @@
package mightypork.gamecore.resources.loading;
package mightypork.gamecore.resources;
import java.util.concurrent.ExecutorService;
@ -9,8 +9,6 @@ import mightypork.gamecore.app.MainLoopRequest;
import mightypork.gamecore.eventbus.BusAccess;
import mightypork.gamecore.eventbus.events.Destroyable;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.events.ResourceLoadRequestListener;
import mightypork.gamecore.util.annot.FactoryMethod;
/**
@ -18,31 +16,26 @@ import mightypork.gamecore.util.annot.FactoryMethod;
*
* @author MightyPork
*/
public class AsyncResourceLoader extends Thread implements ResourceLoadRequestListener, Destroyable {
/**
* Start a new loader thread.
*
* @param app app access
* @return the launched thread
*/
@FactoryMethod
public static AsyncResourceLoader launch(BusAccess app)
{
final AsyncResourceLoader loader = new AsyncResourceLoader(app);
loader.setDaemon(true);
loader.start();
return loader;
}
public class AsyncResourceLoader extends Thread implements ResourceLoader, Destroyable {
private final ExecutorService exs = Executors.newCachedThreadPool();
private final LinkedBlockingQueue<Deferred> toLoad = new LinkedBlockingQueue<>();
private final LinkedBlockingQueue<DeferredResource> toLoad = new LinkedBlockingQueue<>();
private volatile boolean stopped;
private final BusAccess app;
private BusAccess app;
private volatile boolean mainLoopQueuing = false;
@Override
public synchronized void init(BusAccess app)
{
this.app = app;
app.getEventBus().subscribe(this);
setDaemon(true);
super.start();
}
public void enableMainLoopQueuing(boolean yes)
{
mainLoopQueuing = yes;
@ -52,16 +45,14 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequestLi
/**
* @param app app acceess
*/
public AsyncResourceLoader(BusAccess app)
public AsyncResourceLoader()
{
super("Deferred loader");
this.app = app;
app.getEventBus().subscribe(this);
}
@Override
public void loadResource(final Deferred resource)
public void loadResource(final DeferredResource resource)
{
if (resource.isLoaded()) return;
@ -98,7 +89,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequestLi
while (!stopped) {
try {
final Deferred def = toLoad.take();
final DeferredResource def = toLoad.take();
if (def == null) continue;
if (!def.isLoaded()) {

@ -1,4 +1,4 @@
package mightypork.gamecore.resources.loading;
package mightypork.gamecore.resources;
import mightypork.gamecore.eventbus.events.Destroyable;
@ -12,7 +12,7 @@ import mightypork.gamecore.logging.LogAlias;
* @author MightyPork
*/
@LogAlias(name = "Resource")
public abstract class DeferredResource implements Deferred, Destroyable {
public abstract class BaseDeferredResource implements DeferredResource, Destroyable {
private final String resource;
private volatile boolean loadFailed = false;
@ -23,7 +23,7 @@ public abstract class DeferredResource implements Deferred, Destroyable {
* @param resource resource path / name; this string is later used in
* loadResource()
*/
public DeferredResource(String resource)
public BaseDeferredResource(String resource)
{
this.resource = resource;
}
@ -33,11 +33,9 @@ public abstract class DeferredResource implements Deferred, Destroyable {
public synchronized final void load()
{
if (loadFailed) return;
if (loadAttempted) return;
loadAttempted = true;
loadFailed = false;
try {
@ -118,8 +116,8 @@ public abstract class DeferredResource implements Deferred, Destroyable {
{
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof DeferredResource)) return false;
final DeferredResource other = (DeferredResource) obj;
if (!(obj instanceof BaseDeferredResource)) return false;
final BaseDeferredResource other = (BaseDeferredResource) obj;
if (resource == null) {
if (other.resource != null) return false;
} else if (!resource.equals(other.resource)) return false;

@ -1,4 +1,4 @@
package mightypork.gamecore.resources.loading;
package mightypork.gamecore.resources;
/**
@ -6,7 +6,7 @@ package mightypork.gamecore.resources.loading;
*
* @author MightyPork
*/
public interface Deferred {
public interface DeferredResource {
/**
* Load the actual resource, if not loaded yet.

@ -1,4 +1,4 @@
package mightypork.gamecore.resources.loading;
package mightypork.gamecore.resources;
import java.lang.annotation.*;

@ -0,0 +1,101 @@
package mightypork.gamecore.resources;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.resources.audio.SoundBank;
import mightypork.gamecore.resources.audio.players.EffectPlayer;
import mightypork.gamecore.resources.audio.players.LoopPlayer;
import mightypork.gamecore.resources.fonts.FontBank;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.resources.textures.GLTexture;
import mightypork.gamecore.resources.textures.TextureBank;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.resources.textures.TxSheet;
/**
* Static resource repository
*
* @author MightyPork
*/
public final class Res {
private static TextureBank textures;
private static SoundBank sounds;
private static FontBank fonts;
private static boolean initialized = false;
/**
* Load on behalf of given base app
*
* @param app app access
*/
public static void init(AppAccess app)
{
if (initialized) return;
initialized = true;
textures = new TextureBank(app);
sounds = new SoundBank(app);
fonts = new FontBank(app);
}
public static GLTexture getTexture(String key)
{
return textures.getTexture(key);
}
/**
* Get a texture sheet by key
*
* @param key
* @return sheet
*/
public static TxSheet getTxSheet(String key)
{
return textures.getSheet(key);
}
/**
* Get a texture quad by key
*
* @param key
* @return quad
*/
public static TxQuad getTxQuad(String key)
{
return textures.getQuad(key);
}
public static LoopPlayer getSoundLoop(String key)
{
return sounds.getLoop(key);
}
public static EffectPlayer getSoundEffect(String key)
{
return sounds.getEffect(key);
}
public static GLFont getFont(String key)
{
return fonts.getFont(key);
}
public static void load(ResourceSetup binder)
{
binder.addFonts(fonts);
binder.addSounds(sounds);
binder.addTextures(textures);
}
}

@ -1,9 +1,8 @@
package mightypork.gamecore.resources.events;
package mightypork.gamecore.resources;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
import mightypork.gamecore.resources.loading.Deferred;
/**
@ -12,22 +11,22 @@ import mightypork.gamecore.resources.loading.Deferred;
* @author MightyPork
*/
@SingleReceiverEvent
public class ResourceLoadRequest extends BusEvent<ResourceLoadRequestListener> {
public class ResourceLoadRequest extends BusEvent<ResourceLoader> {
private final Deferred resource;
private final DeferredResource resource;
/**
* @param resource resource to load
*/
public ResourceLoadRequest(Deferred resource)
public ResourceLoadRequest(DeferredResource resource)
{
this.resource = resource;
}
@Override
public void handleBy(ResourceLoadRequestListener handler)
public void handleBy(ResourceLoader handler)
{
handler.loadResource(resource);
}

@ -0,0 +1,29 @@
package mightypork.gamecore.resources;
import mightypork.gamecore.eventbus.BusAccess;
/**
* {@link ResourceLoadRequest} listener
*
* @author MightyPork
*/
public interface ResourceLoader {
/**
* Load a resource
*
* @param resource
*/
void loadResource(DeferredResource resource);
/**
* Initialize the loader (async loader may start a stread)
*
* @param app app the loader works for. The event bus must already be
* initialized.
*/
void init(BusAccess app);
}

@ -0,0 +1,38 @@
package mightypork.gamecore.resources;
import mightypork.gamecore.resources.audio.SoundBank;
import mightypork.gamecore.resources.fonts.FontBank;
import mightypork.gamecore.resources.textures.TextureBank;
/**
* Resource binder; used by apps to specify what resources are to be loaded.
*
* @author MightyPork
*/
public interface ResourceSetup {
/**
* Add fonts to load.
*
* @param fonts font registry
*/
void addFonts(FontBank fonts);
/**
* Add sounds to load.
*
* @param sounds sound registry
*/
void addSounds(SoundBank sounds);
/**
* Add textures to load
*
* @param textures texture registry
*/
void addTextures(TextureBank textures);
}

@ -0,0 +1,15 @@
package mightypork.gamecore.resources.audio;
import mightypork.gamecore.eventbus.BusEvent;
public class AudioReadyEvent extends BusEvent<AudioReadyListener> {
@Override
protected void handleBy(AudioReadyListener handler)
{
handler.onInputReady();
}
}

@ -0,0 +1,7 @@
package mightypork.gamecore.resources.audio;
public interface AudioReadyListener {
void onInputReady();
}

@ -5,7 +5,7 @@ import java.io.IOException;
import java.io.InputStream;
import mightypork.gamecore.logging.LogAlias;
import mightypork.gamecore.resources.loading.DeferredResource;
import mightypork.gamecore.resources.BaseDeferredResource;
import mightypork.gamecore.util.files.FileUtils;
import mightypork.gamecore.util.math.constraints.vect.Vect;
@ -19,7 +19,7 @@ import org.newdawn.slick.openal.SoundStore;
* @author MightyPork
*/
@LogAlias(name = "Audio")
public class DeferredAudio extends DeferredResource {
public class DeferredAudio extends BaseDeferredResource {
private enum PlayMode
{

@ -8,9 +8,9 @@ import java.util.Set;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.eventbus.clients.RootBusNode;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.resources.ResourceLoadRequest;
import mightypork.gamecore.resources.audio.players.EffectPlayer;
import mightypork.gamecore.resources.audio.players.LoopPlayer;
import mightypork.gamecore.resources.events.ResourceLoadRequest;
import mightypork.gamecore.util.math.Calc.Buffers;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar;
@ -87,6 +87,8 @@ public class SoundSystem extends RootBusNode implements Updateable {
setListener(INITIAL_LISTENER_POS);
soundSystemInited = true;
getEventBus().send(new AudioReadyEvent());
}
}

@ -1,20 +0,0 @@
package mightypork.gamecore.resources.events;
import mightypork.gamecore.resources.loading.Deferred;
/**
* {@link ResourceLoadRequest} listener
*
* @author MightyPork
*/
public interface ResourceLoadRequestListener {
/**
* Load a resource
*
* @param resource
*/
void loadResource(Deferred resource);
}

@ -5,7 +5,7 @@ import java.util.HashMap;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.app.LightAppModule;
import mightypork.gamecore.resources.events.ResourceLoadRequest;
import mightypork.gamecore.resources.ResourceLoadRequest;
import mightypork.gamecore.resources.fonts.impl.DeferredFont;
import org.newdawn.slick.opengl.Texture;
@ -36,7 +36,7 @@ public class FontBank extends LightAppModule {
* @param key font key
* @param font font instance
*/
public void loadFont(String key, DeferredFont font)
public void addFont(String key, DeferredFont font)
{
getEventBus().send(new ResourceLoadRequest(font));

@ -7,9 +7,9 @@ import java.io.IOException;
import java.io.InputStream;
import mightypork.gamecore.logging.LogAlias;
import mightypork.gamecore.resources.BaseDeferredResource;
import mightypork.gamecore.resources.MustLoadInMainThread;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.resources.loading.DeferredResource;
import mightypork.gamecore.resources.loading.MustLoadInMainThread;
import mightypork.gamecore.resources.textures.FilterMode;
import mightypork.gamecore.util.files.FileUtils;
import mightypork.gamecore.util.math.color.Color;
@ -23,7 +23,7 @@ import mightypork.gamecore.util.math.constraints.vect.Vect;
*/
@MustLoadInMainThread
@LogAlias(name = "Font")
public class DeferredFont extends DeferredResource implements GLFont {
public class DeferredFont extends BaseDeferredResource implements GLFont {
public static enum FontStyle
{

@ -3,8 +3,8 @@ package mightypork.gamecore.resources.textures;
import mightypork.gamecore.logging.LogAlias;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.loading.DeferredResource;
import mightypork.gamecore.resources.loading.MustLoadInMainThread;
import mightypork.gamecore.resources.BaseDeferredResource;
import mightypork.gamecore.resources.MustLoadInMainThread;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import org.lwjgl.opengl.GL11;
@ -17,7 +17,7 @@ import org.lwjgl.opengl.GL11;
*/
@LogAlias(name = "Texture")
@MustLoadInMainThread
public class DeferredTexture extends DeferredResource implements GLTexture {
public class DeferredTexture extends BaseDeferredResource implements GLTexture {
public static DeferredTexture lastBind = null;

@ -6,8 +6,9 @@ import java.util.Map;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.app.LightAppModule;
import mightypork.gamecore.resources.events.ResourceLoadRequest;
import mightypork.gamecore.resources.ResourceLoadRequest;
import mightypork.gamecore.util.error.KeyAlreadyExistsException;
import mightypork.gamecore.util.math.constraints.rect.Rect;
/**
@ -32,31 +33,33 @@ public class TextureBank extends LightAppModule {
/**
* Load a texture from resource, with the resource-path as a name.
* Load a texture from resource, without a key. This texture will not be
* added to the bank.
*
* @param resourcePath resource path of the texture
* @param filter
* @param wrap
* @return texture reference
*/
public GLTexture loadTexture(String resourcePath, FilterMode filter, WrapMode wrap)
public GLTexture addTexture(String resourcePath, FilterMode filter, WrapMode wrap)
{
return loadTexture(resourcePath, resourcePath, filter, wrap);
return addTexture(resourcePath, resourcePath, filter, wrap);
}
/**
* Load a texture from resource
* Load a texture from resource; if key is not null, the texture will be
* added to the bank.
*
* @param key texture key
* @param key texture key, can be null.
* @param resourcePath resource path of the texture
* @param filter
* @param wrap
* @return texture reference
*/
public GLTexture loadTexture(String key, String resourcePath, FilterMode filter, WrapMode wrap)
public GLTexture addTexture(String key, String resourcePath, FilterMode filter, WrapMode wrap)
{
if (textures.containsKey(key)) throw new KeyAlreadyExistsException();
if (key != null) if (textures.containsKey(key)) throw new KeyAlreadyExistsException();
final DeferredTexture texture = new DeferredTexture(resourcePath);
texture.setFilter(filter);
@ -64,7 +67,10 @@ public class TextureBank extends LightAppModule {
getEventBus().send(new ResourceLoadRequest(texture));
textures.put(key, texture);
if (key != null) {
textures.put(key, texture);
add(key, texture.makeQuad(Rect.ONE));
}
return texture;
}

@ -31,80 +31,7 @@ public class OsUtils {
private static EnumOS cachedOs;
/**
* Get App dir, ensure it exists
*
* @param dirname
* @return app dir
*/
public static File getWorkDir(String dirname)
{
return getWorkDir(dirname, true);
}
/**
* Get App sub-folder
*
* @param dirname
* @param subfolderName
* @param create
* @return the folder
*/
public static File getWorkDir(String dirname, String subfolderName, boolean create)
{
final File f = new File(getWorkDir(dirname), subfolderName);
if (!f.exists() && create) {
if (!f.mkdirs()) {
throw new RuntimeException("Could not create.");
}
}
return f;
}
/**
* Get App sub-folder, create
*
* @param dirname
* @param subfolderName
* @return the folder
*/
public static File getWorkDir(String dirname, String subfolderName)
{
return getWorkDir(dirname, subfolderName, true);
}
public static EnumOS getOs()
{
if (cachedOs != null) return cachedOs;
final String s = System.getProperty("os.name").toLowerCase();
if (s.contains("win")) {
cachedOs = EnumOS.windows;
} else if (s.contains("mac")) {
cachedOs = EnumOS.macos;
} else if (s.contains("linux") || s.contains("unix")) {
cachedOs = EnumOS.linux;
} else if (s.contains("solaris") || s.contains("sunos")) {
cachedOs = EnumOS.solaris;
} else {
cachedOs = EnumOS.unknown;
}
return cachedOs;
}
private static File getWorkDir(String dirname, boolean create)
public static File getHomeWorkDir(String dirname)
{
final String userhome = System.getProperty("user.home", ".");
File file;
@ -135,15 +62,33 @@ public class OsUtils {
break;
}
if (!file.exists() || !file.isDirectory()) {
if (create) {
if (!file.mkdirs()) {
throw new RuntimeException("Could not create working directory.");
}
}
return file;
}
public static EnumOS getOs()
{
if (cachedOs != null) return cachedOs;
final String s = System.getProperty("os.name").toLowerCase();
if (s.contains("win")) {
cachedOs = EnumOS.windows;
} else if (s.contains("mac")) {
cachedOs = EnumOS.macos;
} else if (s.contains("linux") || s.contains("unix")) {
cachedOs = EnumOS.linux;
} else if (s.contains("solaris") || s.contains("sunos")) {
cachedOs = EnumOS.solaris;
} else {
cachedOs = EnumOS.unknown;
}
return file;
return cachedOs;
}
}

@ -0,0 +1,71 @@
package mightypork.gamecore.util.files.config;
import mightypork.gamecore.util.objects.Convert;
public abstract class Property<T extends Object> {
private final String comment;
private final String key;
private T value;
private final T defaultValue;
public Property(String key, T defaultValue, String comment)
{
super();
this.comment = comment;
this.key = key;
this.value = defaultValue;
this.defaultValue = defaultValue;
}
public final void parse(String string)
{
setValue(decode(string, defaultValue));
}
public abstract T decode(String string, T defval);
public String encode(T value)
{
return Convert.toString(value, Convert.toString(defaultValue));
}
@Override
public final String toString()
{
return encode(value);
}
public T getValue()
{
return value;
}
@SuppressWarnings("unchecked")
public void setValue(Object value)
{
this.value = (T) value;
}
public String getComment()
{
return comment;
}
public String getKey()
{
return key;
}
}

@ -9,9 +9,6 @@ import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.TreeMap;
import mightypork.gamecore.util.math.Range;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.VectConst;
import mightypork.gamecore.util.objects.Convert;
@ -24,35 +21,6 @@ import mightypork.gamecore.util.objects.Convert;
*/
public class PropertyManager {
private abstract class Property<T> {
public String comment;
public String key;
public T value;
public T defaultValue;
public Property(String key, T defaultValue, String comment)
{
super();
this.comment = comment;
this.key = key;
this.defaultValue = defaultValue;
this.value = defaultValue;
}
public abstract void parse(String string);
@Override
public String toString()
{
return Convert.toString(value);
}
}
private class BooleanProperty extends Property<Boolean> {
public BooleanProperty(String key, Boolean defaultValue, String comment)
@ -62,9 +30,9 @@ public class PropertyManager {
@Override
public void parse(String string)
public Boolean decode(String string, Boolean defval)
{
value = Convert.toBoolean(string, defaultValue);
return Convert.toBoolean(string, defval);
}
}
@ -77,9 +45,9 @@ public class PropertyManager {
@Override
public void parse(String string)
public Integer decode(String string, Integer defval)
{
value = Convert.toInteger(string, defaultValue);
return Convert.toInteger(string, defval);
}
}
@ -92,9 +60,9 @@ public class PropertyManager {
@Override
public void parse(String string)
public Double decode(String string, Double defval)
{
value = Convert.toDouble(string, defaultValue);
return Convert.toDouble(string, defval);
}
}
@ -107,39 +75,9 @@ public class PropertyManager {
@Override
public void parse(String string)
public String decode(String string, String defval)
{
value = Convert.toString(string, defaultValue);
}
}
private class RangeProperty extends Property<Range> {
public RangeProperty(String key, Range defaultValue, String comment)
{
super(key, defaultValue, comment);
}
@Override
public void parse(String string)
{
value = Convert.toRange(string, defaultValue);
}
}
private class CoordProperty extends Property<Vect> {
public CoordProperty(String key, Vect defaultValue, String comment)
{
super(key, defaultValue, comment);
}
@Override
public void parse(String string)
{
value = Convert.toVect(string, defaultValue);
return Convert.toString(string, defval);
}
}
@ -155,7 +93,6 @@ public class PropertyManager {
private final TreeMap<String, Property<?>> entries;
private final TreeMap<String, String> renameTable;
private final TreeMap<String, String> overrideValues;
private SortedProperties props = new SortedProperties();
@ -169,7 +106,6 @@ public class PropertyManager {
{
this.file = file;
this.entries = new TreeMap<>();
this.overrideValues = new TreeMap<>();
this.renameTable = new TreeMap<>();
this.fileComment = comment;
}
@ -178,7 +114,7 @@ public class PropertyManager {
/**
* Load, fix and write to file.
*/
public void apply()
public void load()
{
boolean needsSave = false;
if (!file.getParentFile().mkdirs()) {
@ -201,38 +137,30 @@ public class PropertyManager {
// rename keys
for (final Entry<String, String> entry : renameTable.entrySet()) {
if (props.getProperty(entry.getKey()) == null) {
continue;
}
props.setProperty(entry.getValue(), props.getProperty(entry.getKey()));
final String pr = props.getProperty(entry.getKey());
if (pr == null) continue;
props.remove(entry.getKey());
needsSave = true;
}
// set the override values into the freshly loaded properties file
for (final Entry<String, String> entry : overrideValues.entrySet()) {
props.setProperty(entry.getKey(), entry.getValue());
props.setProperty(entry.getValue(), pr);
needsSave = true;
}
// validate entries one by one, replace with default when needed
for (final Property<?> entry : entries.values()) {
keyList.add(entry.key);
keyList.add(entry.getKey());
final String propOrig = props.getProperty(entry.key);
final String propOrig = props.getProperty(entry.getKey());
entry.parse(propOrig);
if (!entry.toString().equals(propOrig)) {
needsSave = true;
}
if (entry.comment != null) {
props.setKeyComment(entry.key, entry.comment);
if (entry.getComment() != null) {
props.setKeyComment(entry.getKey(), entry.getComment());
}
if (propOrig == null || !entry.toString().equals(propOrig)) {
props.setProperty(entry.key, entry.toString());
props.setProperty(entry.getKey(), entry.toString());
needsSave = true;
}
@ -244,23 +172,27 @@ public class PropertyManager {
props.remove(propname);
needsSave = true;
}
}
// save if needed
if (needsSave || cfgForceSave) {
try {
props.store(new FileOutputStream(file), fileComment);
} catch (final IOException ioe) {
ioe.printStackTrace();
}
save();
}
overrideValues.clear();
renameTable.clear();
}
public void save()
{
try {
props.store(new FileOutputStream(file), fileComment);
} catch (final IOException ioe) {
ioe.printStackTrace();
}
}
/**
* @param newlineBeforeComments put newline before comments
*/
@ -291,13 +223,13 @@ public class PropertyManager {
/**
* Get a property entry (rarely used)
*
* @param n key
* @param k key
* @return the entry
*/
private Property<?> get(String n)
private Property<?> getProperty(String k)
{
try {
return entries.get(n);
return entries.get(k);
} catch (final Throwable t) {
return null;
}
@ -307,137 +239,117 @@ public class PropertyManager {
/**
* Get boolean property
*
* @param n key
* @param k key
* @return the boolean found, or false
*/
public Boolean getBoolean(String n)
public Boolean getBoolean(String k)
{
return Convert.toBoolean(get(n).value);
return Convert.toBoolean(getProperty(k).getValue());
}
/**
* Get numeric property
*
* @param n key
* @param k key
* @return the int found, or null
*/
public Integer getInteger(String n)
public Integer getInteger(String k)
{
return Convert.toInteger(get(n).value);
return Convert.toInteger(getProperty(k).getValue());
}
/**
* Get numeric property as double
*
* @param n key
* @param k key
* @return the double found, or null
*/
public Double getDouble(String n)
public Double getDouble(String k)
{
return Convert.toDouble(get(n).value);
return Convert.toDouble(getProperty(k).getValue());
}
/**
* Get string property
*
* @param n key
* @param k key
* @return the string found, or null
*/
public String getString(String n)
public String getString(String k)
{
return Convert.toString(get(n).value);
return Convert.toString(getProperty(k).getValue());
}
/**
* Get range property
* Get arbitrary property. Make sure it's of the right type!
*
* @param n key
* @return the range found, or null
* @param k key
* @return the prioperty found
*/
public Range getRange(String n)
@SuppressWarnings("unchecked")
public <T> T getValue(String k)
{
return Convert.toRange(get(n).value);
}
/**
* Get coord property
*
* @param n key
* @return the coord found, or null
*/
public VectConst getCoord(String n)
{
return Convert.toVect(get(n).value);
try {
return ((Property<T>) getProperty(k)).getValue();
} catch (final ClassCastException e) {
return null;
}
}
/**
* Add a boolean property
*
* @param n key
* @param k key
* @param d default value
* @param comment the in-file comment
*/
public void putBoolean(String n, boolean d, String comment)
public void putBoolean(String k, boolean d, String comment)
{
entries.put(n, new BooleanProperty(n, d, comment));
putProperty(new BooleanProperty(k, d, comment));
}
/**
* Add a numeric property (double)
*
* @param n key
* @param k key
* @param d default value
* @param comment the in-file comment
*/
public void putDouble(String n, double d, String comment)
public void putDouble(String k, double d, String comment)
{
entries.put(n, new DoubleProperty(n, d, comment));
putProperty(new DoubleProperty(k, d, comment));
}
/**
* Add a numeric property
*
* @param n key
* @param k key
* @param d default value
* @param comment the in-file comment
*/
public void putInteger(String n, int d, String comment)
public void putInteger(String k, int d, String comment)
{
entries.put(n, new IntegerProperty(n, d, comment));
putProperty(new IntegerProperty(k, d, comment));
}
/**
* Add a string property
*
* @param n key
* @param k key
* @param d default value
* @param comment the in-file comment
*/
public void putString(String n, String d, String comment)
public void putString(String k, String d, String comment)
{
entries.put(n, new StringProperty(n, d, comment));
}
/**
* Add a coord property
*
* @param n key
* @param d default value
* @param comment the in-file comment
*/
public void putCoord(String n, Vect d, String comment)
{
entries.put(n, new CoordProperty(n, d, comment));
putProperty(new StringProperty(k, d, comment));
}
@ -445,17 +357,16 @@ public class PropertyManager {
* Add a range property
*
* @param n key
* @param d default value
* @param comment the in-file comment
* @param prop property to put
*/
public void putRange(String n, Range d, String comment)
public <T> void putProperty(Property<T> prop)
{
entries.put(n, new RangeProperty(n, d, comment));
entries.put(prop.getKey(), prop);
}
/**
* Rename key before doing "apply"; value is preserved
* Rename key before loading; value is preserved
*
* @param oldKey old key
* @param newKey new key
@ -468,16 +379,20 @@ public class PropertyManager {
/**
* Set value saved to certain key; use to save runtime-changed configuration
* values.
* Set value saved to certain key.
*
* @param key key
* @param value the saved value
*/
public void setValue(String key, Object value)
{
overrideValues.put(key, value.toString());
return;
getProperty(key).setValue(value);
}
public void setFileComment(String fileComment)
{
this.fileComment = fileComment;
}
}

@ -0,0 +1,52 @@
package mightypork.gamecore.util.objects;
import java.util.Enumeration;
import java.util.Iterator;
/**
* Helper class for iterationg over an {@link Enumeration}
*
* @author MightyPork
* @param <T> target element type (will be cast)
*/
public class EnumerationIterator<T> implements Iterable<T> {
private final Enumeration<? extends T> enumeration;
public EnumerationIterator(Enumeration<? extends T> enumeration)
{
this.enumeration = enumeration;
}
@Override
public Iterator<T> iterator()
{
return new Iterator<T>() {
@Override
public boolean hasNext()
{
return enumeration.hasMoreElements();
}
@Override
public T next()
{
return enumeration.nextElement();
}
@Override
public void remove()
{
throw new UnsupportedOperationException("Operation not supported.");
}
};
}
}

@ -1,84 +0,0 @@
package mightypork.rogue;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.files.config.PropertyManager;
/**
* Main Config class
*
* @author MightyPork
*/
public final class Config {
private static PropertyManager mgr;
// opts
public static final int def_LAST_RUN_VERSION = 0;
public static int LAST_RUN_VERSION;
public static final boolean def_START_IN_FS = false;
public static boolean START_IN_FS;
// property keys
private static final String PK_LAST_RUN_VERSION = "status.last_run_version";
private static final String PK_START_IN_FS = "cfg.start_in_fullscreen";
/**
* Prepare config manager and load user settings
*/
public static void init()
{
Log.f2("Initializing configuration manager.");
final String comment = Const.APP_NAME + " config file";
mgr = new PropertyManager(Paths.CONFIG, comment);
mgr.cfgNewlineBeforeComments(true);
mgr.cfgSeparateSections(true);
mgr.putInteger(PK_LAST_RUN_VERSION, def_LAST_RUN_VERSION, null);
mgr.putBoolean(PK_START_IN_FS, def_START_IN_FS, "Go to fullscreen on startup.");
load(); // load what has been "put"
}
/**
* Save changed fields to config file
*/
public static void save()
{
mgr.setValue(PK_LAST_RUN_VERSION, Const.VERSION);
mgr.setValue(PK_START_IN_FS, START_IN_FS);
mgr.apply();
}
/**
* Load config file and assign values to fields
*/
public static void load()
{
mgr.apply();
LAST_RUN_VERSION = mgr.getInteger(PK_LAST_RUN_VERSION);
START_IN_FS = mgr.getBoolean(PK_START_IN_FS);
}
// options that can't be configured via config file
public static boolean LOGGING_ENABLED = true;
public static boolean LOG_TO_STDOUT = true;
public static boolean SINGLE_INSTANCE = true;
/** Render dark in unknown area & skip invisible stuff */
public static boolean RENDER_UFOG = true;
/** Render a font bounding box in text painters. */
public static boolean DEBUG_FONT_RENDER = false;
}

@ -9,7 +9,7 @@ package mightypork.rogue;
public final class Const {
// STRINGS
public static final int VERSION = 3;
public static final int VERSION = 4;
public static final String APP_NAME = "Rogue";
public static final String TITLEBAR = APP_NAME + " v." + VERSION;
@ -20,4 +20,7 @@ public final class Const {
// INITIAL WINDOW SIZE
public static final int WINDOW_W = 1024;
public static final int WINDOW_H = 768;
/** Render dark in unknown area & skip invisible stuff */
public static boolean RENDER_UFOG = true;
}

@ -0,0 +1,59 @@
package mightypork.rogue;
import java.io.File;
import java.util.Arrays;
import mightypork.gamecore.app.BaseApp;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.files.OsUtils;
public class Launcher {
/**
* Launcher
*
* @param args
*/
public static void main(String[] args)
{
Log.f3(Arrays.toString(args));
File workdir = null;
try {
boolean localWorkdir = false;
String lwdDir = null;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("--workdir") || args[i].equals("-w")) {
localWorkdir = true;
lwdDir = args[i + 1];
i++;
}
}
if (!localWorkdir) {
workdir = OsUtils.getHomeWorkDir(lwdDir);
} else {
workdir = new File(".rogue-save");
}
} catch (final ArrayIndexOutOfBoundsException e) {
Log.e("Malformed arguments.");
}
final BaseApp app = new RogueApp(workdir, true);
app.addResources(new RogueResources());
app.addKeys(new RogueKeys());
app.addConfig(new RogueConfig());
app.setBusLogging(false);
app.setConfigFile("config.ini", "Rogue config file");
app.setLogOptions("/", "runtime", 5, java.util.logging.Level.ALL);
app.start();
}
}

@ -1,65 +0,0 @@
package mightypork.rogue;
import java.io.File;
import mightypork.gamecore.util.files.OsUtils;
public final class Paths {
private static final String WORKDIR_NAME = ".rogue-save";
public static File WORKDIR;
public static File LOG_FILE;
public static File SCREENSHOTS;
public static File CONFIG;
public static File LOCK;
public static File SAVE_SLOT_1;
public static File SAVE_SLOT_2;
public static File SAVE_SLOT_3;
/**
* Initialize for local workdir
*
* @param local_wd_name workdir name
*/
public static void init(String local_wd_name)
{
init(true, local_wd_name);
}
/**
* Initialize for gloal workdir
*/
public static void init()
{
init(false, WORKDIR_NAME);
}
private static void init(boolean local_workdir, String workdir_name)
{
if (local_workdir) {
WORKDIR = new File(workdir_name);
} else {
WORKDIR = OsUtils.getWorkDir(workdir_name);
}
LOG_FILE = new File(WORKDIR, "runtime.log");
SCREENSHOTS = new File(WORKDIR, "screenshots");
CONFIG = new File(WORKDIR, "config.ini");
LOCK = new File(WORKDIR, ".lock");
SAVE_SLOT_1 = new File(WORKDIR, "saves/slot_1.ion");
SAVE_SLOT_2 = new File(WORKDIR, "saves/slot_2.ion");
SAVE_SLOT_3 = new File(WORKDIR, "saves/slot_3.ion");
}
}

@ -2,25 +2,19 @@ package mightypork.rogue;
import java.io.File;
import java.util.Arrays;
import java.util.Locale;
import mightypork.gamecore.Config;
import mightypork.gamecore.app.BaseApp;
import mightypork.gamecore.app.MainLoop;
import mightypork.gamecore.app.MainLoopRequest;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.EventBus;
import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.logging.writers.LogWriter;
import mightypork.gamecore.input.KeyConfig;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.resources.loading.AsyncResourceLoader;
import mightypork.gamecore.util.ion.Ion;
import mightypork.gamecore.util.strings.StringUtils;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType;
import mightypork.rogue.events.GameStateRequest;
@ -40,66 +34,11 @@ import mightypork.rogue.world.level.Level;
*
* @author MightyPork
*/
public final class App extends BaseApp {
public final class RogueApp extends BaseApp {
/**
* Launcher
*
* @param args
*/
public static void main(String[] args)
public RogueApp(File workdir, boolean singleInstance)
{
Log.f3(Arrays.toString(args));
try {
boolean lwd = false;
String lwdDir = null;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("--workdir") || args[i].equals("-w")) {
lwd = true;
lwdDir = args[i + 1];
i++;
}
}
if (!lwd) {
Paths.init();
} else {
Paths.init(lwdDir);
}
} catch (ArrayIndexOutOfBoundsException e) {
Log.e("Malformed arguments.");
}
Log.i("Using workdir: " + Paths.WORKDIR.getAbsolutePath());
(new App()).start();
}
@Override
protected File getLockFile()
{
return Paths.LOCK;
}
@Override
protected void preInit()
{
Config.init();
Config.save();
}
@Override
protected LogWriter createLog()
{
Locale.setDefault(Locale.ENGLISH); // for decimal point in numbers
return Log.create("runtime", Paths.LOG_FILE, 5);
super(workdir, singleInstance);
}
@ -113,31 +52,14 @@ public final class App extends BaseApp {
}
@Override
protected void initBus(EventBus bus)
{
bus.detailedLogging = true;
}
@Override
protected void initDisplay(DisplaySystem display)
{
display.createMainWindow(Const.WINDOW_W, Const.WINDOW_H, true, Config.START_IN_FS, Const.TITLEBAR);
display.createMainWindow(Const.WINDOW_W, Const.WINDOW_H, true, Config.<Boolean> get("opt.fullscreen"), Const.TITLEBAR);
display.setTargetFps(Const.FPS_RENDER);
}
@Override
protected void initResources()
{
final AsyncResourceLoader thread = AsyncResourceLoader.launch(this);
thread.enableMainLoopQueuing(true);
Res.load(this);
}
@Override
protected void initScreens(ScreenRegistry screens)
{
@ -145,8 +67,8 @@ public final class App extends BaseApp {
/* game screen references world provider instance */
WorldProvider.init(this);
getEventBus().subscribe(new RogueStateManager(this));
getEventBus().subscribe(new GameStateManager(this));
screens.addScreen("main_menu", new ScreenMainMenu(this));
screens.addScreen("select_world", new ScreenSelectWorld(this));
@ -162,23 +84,17 @@ public final class App extends BaseApp {
protected void initInputSystem(InputSystem input)
{
// this will work only with reusable events (such as requests)
bindEventToKey(new ActionRequest(RequestType.FULLSCREEN), Keys.F11);
bindEventToKey(new ActionRequest(RequestType.SCREENSHOT), Keys.F2);
bindEventToKey(new ActionRequest(RequestType.FULLSCREEN), "key.global.fullscreen");
bindEventToKey(new ActionRequest(RequestType.SCREENSHOT), "key.global.screenshot");
bindEventToKey(new GameStateRequest(GameState.EXIT), Keys.Q, Keys.MOD_SHIFT | Keys.MOD_CONTROL);
bindEventToKey(new GameStateRequest(GameState.MAIN_MENU), Keys.M, Keys.MOD_SHIFT | Keys.MOD_CONTROL);
}
private void bindEventToKey(final BusEvent<?> event, int key)
{
bindEventToKey(event, key, Keys.MOD_NONE);
bindEventToKey(new GameStateRequest(RogueState.EXIT), "key.global.quit");
bindEventToKey(new GameStateRequest(RogueState.MAIN_MENU), "key.global.menu");
}
private void bindEventToKey(final BusEvent<?> event, int key, int mod)
private void bindEventToKey(final BusEvent<?> event, String strokeName)
{
getInput().bindKey(new KeyStroke(key, mod), new Runnable() {
getInput().bindKey(KeyConfig.get(strokeName), Edge.RISING, new Runnable() {
@Override
public void run()
@ -192,7 +108,7 @@ public final class App extends BaseApp {
@Override
protected MainLoop createMainLoop()
{
return new GameLoop(this);
return new RogueMainLoop(this);
}
@ -204,7 +120,7 @@ public final class App extends BaseApp {
@Override
public void run()
{
getEventBus().send(new GameStateRequest(GameState.MAIN_MENU));
getEventBus().send(new GameStateRequest(RogueState.MAIN_MENU));
//getEventBus().send(new CrossfadeRequest("test.layout", true));
}
}));

@ -0,0 +1,16 @@
package mightypork.rogue;
import mightypork.gamecore.ConfigSetup;
import mightypork.gamecore.util.files.config.PropertyManager;
public class RogueConfig implements ConfigSetup {
@Override
public void addOptions(PropertyManager prop)
{
prop.putBoolean("opt.fullscreen", false, "Start in fullscreen");
}
}

@ -0,0 +1,23 @@
package mightypork.rogue;
import mightypork.gamecore.input.KeyConfig;
import mightypork.gamecore.input.KeySetup;
public class RogueKeys implements KeySetup {
@Override
public void addKeys(KeyConfig keys)
{
keys.add("key.global.quit", "CTRL+SHIFT+Q");
keys.add("key.global.menu", "CTRL+SHIFT+M");
keys.add("key.global.screenshot", "F2");
keys.add("key.global.fullscreen", "F11");
keys.add("key.general.cancel", "ESC");
keys.add("key.general.confirm", "ENTER");
keys.add("key.general.yes", "Y");
keys.add("key.general.no", "N");
}
}

@ -7,19 +7,21 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import mightypork.gamecore.WorkDir;
import mightypork.gamecore.app.BaseApp;
import mightypork.gamecore.app.MainLoop;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.render.Screenshot;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.Utils;
import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType;
public final class GameLoop extends MainLoop implements ActionRequest.Listener {
public final class RogueMainLoop extends MainLoop implements ActionRequest.Listener {
public GameLoop(BaseApp app)
public RogueMainLoop(BaseApp app)
{
super(app);
}
@ -100,7 +102,7 @@ public final class GameLoop extends MainLoop implements ActionRequest.Listener {
File file;
int index = 0;
while (true) {
file = new File(Paths.SCREENSHOTS, fname + (index > 0 ? "-" + index : "") + ".png");
file = new File(WorkDir.getDir("screenshots"), fname + (index > 0 ? "-" + index : "") + ".png");
if (!file.exists()) break;
index++;
}

@ -1,63 +1,34 @@
package mightypork.rogue;
import mightypork.gamecore.app.BaseApp;
import mightypork.gamecore.resources.ResourceSetup;
import mightypork.gamecore.resources.audio.SoundBank;
import mightypork.gamecore.resources.audio.players.EffectPlayer;
import mightypork.gamecore.resources.audio.players.LoopPlayer;
import mightypork.gamecore.resources.fonts.FontBank;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.resources.fonts.Glyphs;
import mightypork.gamecore.resources.fonts.impl.DeferredFont;
import mightypork.gamecore.resources.textures.*;
import mightypork.gamecore.resources.textures.FilterMode;
import mightypork.gamecore.resources.textures.GLTexture;
import mightypork.gamecore.resources.textures.QuadGrid;
import mightypork.gamecore.resources.textures.TextureBank;
import mightypork.gamecore.resources.textures.WrapMode;
import mightypork.gamecore.util.math.constraints.rect.Rect;
/**
* Static resource repository
*
* @author MightyPork
*/
public final class Res {
public class RogueResources implements ResourceSetup {
private static TextureBank textures;
private static SoundBank sounds;
private static FontBank fonts;
private static boolean initialized = false;
/**
* Load on behalf of given base app
*
* @param app app access
*/
public static void load(BaseApp app)
{
if (initialized) return;
initialized = true;
textures = new TextureBank(app);
sounds = new SoundBank(app);
fonts = new FontBank(app);
loadSounds();
loadFonts();
loadTextures();
}
private static void loadFonts()
@Override
public void addFonts(FontBank fonts)
{
DeferredFont font;
//fonts.loadFont("polygon_pixel", new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16));
fonts.loadFont("press_start", font = new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16));
fonts.addFont("press_start", font = new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16));
fonts.loadFont("battlenet", font = new DeferredFont("/res/font/battlenet.ttf", Glyphs.basic, 16));
fonts.addFont("battlenet", font = new DeferredFont("/res/font/battlenet.ttf", Glyphs.basic, 16));
font.setDiscardRatio(3 / 16D, 2 / 16D);
fonts.loadFont("tinyutf", font = new DeferredFont("/res/font/TinyUnicode2.ttf", Glyphs.basic, 16));
fonts.addFont("tinyutf", font = new DeferredFont("/res/font/TinyUnicode2.ttf", Glyphs.basic, 16));
font.setDiscardRatio(5 / 16D, 3 / 16D);
// aliases
@ -67,13 +38,21 @@ public final class Res {
}
private static void loadTextures()
@Override
public void addSounds(SoundBank sounds)
{
sounds.addEffect("gui.shutter", "/res/audio/shutter.ogg", 1, 1);
}
@Override
public void addTextures(TextureBank textures)
{
GLTexture texture;
QuadGrid grid;
// gui
texture = textures.loadTexture("/res/img/gui.png", FilterMode.NEAREST, WrapMode.CLAMP);
texture = textures.addTexture("/res/img/gui.png", FilterMode.NEAREST, WrapMode.CLAMP);
// small gui elements
grid = texture.grid(32, 32);
@ -106,7 +85,7 @@ public final class Res {
// sprites
texture = textures.loadTexture("/res/img/sprites.png", FilterMode.NEAREST, WrapMode.CLAMP);
texture = textures.addTexture("/res/img/sprites.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
textures.add("sprite.player", grid.makeSheet(0, 0, 4, 1));
textures.add("sprite.rat.gray", grid.makeSheet(0, 1, 4, 1));
@ -116,14 +95,14 @@ public final class Res {
// logo
texture = textures.loadTexture("/res/img/logo.png", FilterMode.NEAREST, WrapMode.CLAMP);
texture = textures.addTexture("/res/img/logo.png", FilterMode.NEAREST, WrapMode.CLAMP);
textures.add("logo", texture.makeQuad(Rect.make(0, 0, 0.543, 0.203)));
grid = texture.grid(8, 8);
textures.add("death", grid.makeQuad(0, 2));
// tiles
texture = textures.loadTexture("tiles", "/res/img/tiles.png", FilterMode.NEAREST, WrapMode.CLAMP);
texture = textures.addTexture("tiles", "/res/img/tiles.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
textures.add("tile.brick.floor", grid.makeSheet(0, 1, 5, 1));
@ -163,7 +142,7 @@ public final class Res {
textures.add("tile.ufog.full", grid.makeQuad(6, 7));
texture = textures.loadTexture("items", "/res/img/items.png", FilterMode.NEAREST, WrapMode.CLAMP);
texture = textures.addTexture("items", "/res/img/items.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
textures.add("item.meat", grid.makeQuad(0, 0));
textures.add("item.club", grid.makeQuad(1, 0));
@ -178,58 +157,4 @@ public final class Res {
textures.add("item.twig", grid.makeQuad(2, 1));
}
private static void loadSounds()
{
sounds.addEffect("gui.shutter", "/res/audio/shutter.ogg", 1, 1);
}
public static GLTexture getTexture(String key)
{
return textures.getTexture(key);
}
/**
* Get a texture sheet by key
*
* @param key
* @return sheet
*/
public static TxSheet getTxSheet(String key)
{
return textures.getSheet(key);
}
/**
* Get a texture quad by key
*
* @param key
* @return quad
*/
public static TxQuad getTxQuad(String key)
{
return textures.getQuad(key);
}
public static LoopPlayer getSoundLoop(String key)
{
return sounds.getLoop(key);
}
public static EffectPlayer getSoundEffect(String key)
{
return sounds.getEffect(key);
}
public static GLFont getFont(String key)
{
return fonts.getFont(key);
}
}

@ -7,20 +7,20 @@ import mightypork.gamecore.gui.events.CrossfadeRequest;
import mightypork.gamecore.logging.Log;
public class GameStateManager extends AppModule {
public class RogueStateManager extends AppModule {
public GameStateManager(AppAccess app)
public RogueStateManager(AppAccess app)
{
super(app);
}
public static enum GameState
public static enum RogueState
{
MAIN_MENU, SELECT_WORLD, PLAY_WORLD, EXIT
}
public void triggerAction(GameState state)
public void triggerAction(RogueState state)
{
switch (state) {
case MAIN_MENU:

@ -2,8 +2,8 @@ package mightypork.rogue.events;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.rogue.GameStateManager;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.RogueStateManager;
import mightypork.rogue.RogueStateManager.RogueState;
/**
@ -11,19 +11,19 @@ import mightypork.rogue.GameStateManager.GameState;
*
* @author MightyPork
*/
public class GameStateRequest extends BusEvent<GameStateManager> {
public class GameStateRequest extends BusEvent<RogueStateManager> {
final private GameState requested;
final private RogueState requested;
public GameStateRequest(GameState requested)
public GameStateRequest(RogueState requested)
{
this.requested = requested;
}
@Override
protected void handleBy(GameStateManager handler)
protected void handleBy(RogueStateManager handler)
{
handler.triggerAction(requested);
}

@ -7,14 +7,15 @@ import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res;
/**
@ -34,7 +35,7 @@ public class FpsOverlay extends Overlay {
/*
* Toggle key: F3
*/
bindKey(new KeyStroke(Keys.F3), new Action() {
bindKey(new KeyStroke(Keys.F3), Edge.RISING, new Action() {
@Override
public void execute()

@ -6,6 +6,7 @@ import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.Utils;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.color.pal.PAL16;
@ -15,7 +16,6 @@ import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res;
/**

@ -12,15 +12,16 @@ import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.rogue.Res;
import mightypork.rogue.screens.game.ScreenGame.GScrState;
import mightypork.rogue.world.WorldProvider;
@ -127,7 +128,7 @@ public class AskSaveLayer extends ScreenLayer {
btn3.setAction(cancel);
bindKey(new KeyStroke(Keys.ESCAPE), cancel);
bindKey(new KeyStroke(Keys.ESCAPE), Edge.RISING, cancel);
updated.add(numa);
updated.add(hideTT);

@ -14,11 +14,11 @@ import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.Res;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.screens.game.ScreenGame.GScrState;
import mightypork.rogue.world.WorldProvider;
@ -84,7 +84,7 @@ public class DeathLayer extends ScreenLayer {
@Override
protected void execute()
{
getEventBus().send(new GameStateRequest(GameState.MAIN_MENU));
getEventBus().send(new GameStateRequest(RogueState.MAIN_MENU));
}
});
}

@ -4,11 +4,11 @@ package mightypork.rogue.screens.game;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res;
import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.gui.Minimap;

@ -6,10 +6,10 @@ import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.LayoutComponent;
import mightypork.gamecore.gui.components.layout.FlowColumnLayout;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
import mightypork.rogue.Res;
public class IngameNav extends LayoutComponent {

@ -6,6 +6,7 @@ import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.input.ClickableComponent;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.color.Color;
@ -13,7 +14,6 @@ import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.caching.RectCache;
import mightypork.rogue.Res;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.item.Item;

@ -9,12 +9,13 @@ import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider;
@ -139,7 +140,7 @@ public class InventoryLayer extends ScreenLayer {
gl.put(txp2, pos, 0, 1, 1);
txp2.setVPaddingPercent(25);
bindKey(new KeyStroke(Keys.ESCAPE), new Runnable() {
bindKey(new KeyStroke(Keys.ESCAPE), Edge.RISING, new Runnable() {
@Override
public void run()
@ -150,7 +151,7 @@ public class InventoryLayer extends ScreenLayer {
}
});
bindKey(new KeyStroke(Keys.E), new Runnable() {
bindKey(new KeyStroke(Keys.E), Edge.RISING, new Runnable() {
@Override
public void run()
@ -191,7 +192,7 @@ public class InventoryLayer extends ScreenLayer {
}
});
bindKey(new KeyStroke(Keys.D), new Runnable() {
bindKey(new KeyStroke(Keys.D), Edge.RISING, new Runnable() {
@Override
public void run()
@ -212,7 +213,7 @@ public class InventoryLayer extends ScreenLayer {
private void setupGridWalkKeys()
{
bindKey(new KeyStroke(Keys.LEFT), new Runnable() {
bindKey(new KeyStroke(Keys.LEFT), Edge.RISING, new Runnable() {
@Override
public void run()
@ -229,7 +230,7 @@ public class InventoryLayer extends ScreenLayer {
};
});
bindKey(new KeyStroke(Keys.RIGHT), new Runnable() {
bindKey(new KeyStroke(Keys.RIGHT), Edge.RISING, new Runnable() {
@Override
public void run()
@ -246,7 +247,7 @@ public class InventoryLayer extends ScreenLayer {
};
});
bindKey(new KeyStroke(Keys.UP), new Runnable() {
bindKey(new KeyStroke(Keys.UP), Edge.RISING, new Runnable() {
@Override
public void run()
@ -263,7 +264,7 @@ public class InventoryLayer extends ScreenLayer {
};
});
bindKey(new KeyStroke(Keys.DOWN), new Runnable() {
bindKey(new KeyStroke(Keys.DOWN), Edge.RISING, new Runnable() {
@Override
public void run()

@ -3,8 +3,8 @@ package mightypork.rogue.screens.game;
import mightypork.gamecore.gui.components.input.ClickableComponent;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.rogue.Res;
/**

@ -8,11 +8,12 @@ import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.ActionGroup;
import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.math.color.Color;
import mightypork.rogue.Config;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.Const;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
@ -197,7 +198,7 @@ public class ScreenGame extends LayeredScreen implements PlayerKilledListener {
@Override
public void run()
{
getEventBus().send(new GameStateRequest(GameState.MAIN_MENU));
getEventBus().send(new GameStateRequest(RogueState.MAIN_MENU));
}
});
@ -211,7 +212,7 @@ public class ScreenGame extends LayeredScreen implements PlayerKilledListener {
@Override
public void run()
{
getEventBus().send(new GameStateRequest(GameState.EXIT));
getEventBus().send(new GameStateRequest(RogueState.EXIT));
}
});
@ -239,20 +240,20 @@ public class ScreenGame extends LayeredScreen implements PlayerKilledListener {
addLayer(askSaveLayer = new AskSaveLayer(this));
//pause key
bindKey(new KeyStroke(Keys.P), actionTogglePause);
bindKey(new KeyStroke(Keys.PAUSE), actionTogglePause);
bindKey(new KeyStroke(Keys.SPACE), actionTogglePause);
bindKey(new KeyStroke(Keys.P), Edge.RISING, actionTogglePause);
bindKey(new KeyStroke(Keys.PAUSE), Edge.RISING, actionTogglePause);
bindKey(new KeyStroke(Keys.SPACE), Edge.RISING, actionTogglePause);
bindKey(new KeyStroke(Keys.I), actionToggleInv);
bindKey(new KeyStroke(Keys.D), actionDropLastPickedItem);
bindKey(new KeyStroke(Keys.E), actionEat);
bindKey(new KeyStroke(Keys.M), actionToggleMinimap);
bindKey(new KeyStroke(Keys.Z), actionToggleZoom);
bindKey(new KeyStroke(Keys.I), Edge.RISING, actionToggleInv);
bindKey(new KeyStroke(Keys.D), Edge.RISING, actionDropLastPickedItem);
bindKey(new KeyStroke(Keys.E), Edge.RISING, actionEat);
bindKey(new KeyStroke(Keys.M), Edge.RISING, actionToggleMinimap);
bindKey(new KeyStroke(Keys.Z), Edge.RISING, actionToggleZoom);
bindKey(new KeyStroke(Keys.L, Keys.MOD_CONTROL), actionLoad);
bindKey(new KeyStroke(Keys.S, Keys.MOD_CONTROL), actionSave);
bindKey(new KeyStroke(Keys.Q, Keys.MOD_CONTROL), actionQuit);
bindKey(new KeyStroke(Keys.ESCAPE), actionMenu);
bindKey(new KeyStroke(Keys.L, Keys.MOD_CONTROL), Edge.RISING, actionLoad);
bindKey(new KeyStroke(Keys.S, Keys.MOD_CONTROL), Edge.RISING, actionSave);
bindKey(new KeyStroke(Keys.Q, Keys.MOD_CONTROL), Edge.RISING, actionQuit);
bindKey(new KeyStroke(Keys.ESCAPE), Edge.RISING, actionMenu);
// add as actions - enableables.
worldActions.add(worldLayer);
@ -272,12 +273,12 @@ public class ScreenGame extends LayeredScreen implements PlayerKilledListener {
worldActions.setEnabled(true);
// CHEAT - X-ray
bindKey(new KeyStroke(Keys.MULTIPLY, Keys.MOD_CONTROL), new Runnable() {
bindKey(new KeyStroke(Keys.NUMPAD_MULTIPLY, Keys.MOD_CONTROL), Edge.RISING, new Runnable() {
@Override
public void run()
{
Config.RENDER_UFOG ^= true;
Const.RENDER_UFOG ^= true;
}
});
}

@ -7,6 +7,7 @@ import java.util.ConcurrentModificationException;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.BaseComponent;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.FontRenderer;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.Easing;
@ -15,7 +16,6 @@ import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.num.mutable.NumVar;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.rogue.Res;
import mightypork.rogue.world.WorldConsole;
import mightypork.rogue.world.WorldProvider;

@ -11,9 +11,9 @@ import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.rogue.Res;
public class LayoutTestScreen extends LayeredScreen {

@ -13,14 +13,15 @@ import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.PAL16;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.Res;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.GameStateRequest;
@ -83,7 +84,7 @@ public class ScreenMainMenu extends LayeredScreen {
@Override
protected void execute()
{
getEventBus().send(new GameStateRequest(GameState.SELECT_WORLD));
getEventBus().send(new GameStateRequest(RogueState.SELECT_WORLD));
}
});
rows.add(btn, 2);
@ -111,18 +112,18 @@ public class ScreenMainMenu extends LayeredScreen {
@Override
protected void execute()
{
getEventBus().send(new GameStateRequest(GameState.EXIT));
getEventBus().send(new GameStateRequest(RogueState.EXIT));
}
});
rows.add(btn, 2);
bindKey(new KeyStroke(Keys.ESCAPE), new Runnable() {
bindKey(new KeyStroke(Keys.ESCAPE), Edge.RISING, new Runnable() {
@Override
public void run()
{
getEventBus().send(new GameStateRequest(GameState.EXIT));
getEventBus().send(new GameStateRequest(RogueState.EXIT));
}
});
}

@ -1,6 +1,7 @@
package mightypork.rogue.screens.select_world;
import mightypork.gamecore.WorkDir;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.layout.RowLayout;
@ -10,14 +11,14 @@ import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.PAL16;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.Paths;
import mightypork.rogue.Res;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.GameStateRequest;
@ -71,31 +72,31 @@ public class ScreenSelectWorld extends LayeredScreen {
tp.setVPaddingPercent(20);
tp.setShadow(RGB.BLACK_50, tp.height().mul(0.6 / 8D).toVectXY());
slot1 = new WorldSlot(root, Paths.SAVE_SLOT_1);
slot1 = new WorldSlot(root, WorkDir.getFile("save/slot_1.ion"));
rows.add(slot1);
slot2 = new WorldSlot(root, Paths.SAVE_SLOT_2);
slot2 = new WorldSlot(root, WorkDir.getFile("save/slot_2.ion"));
rows.add(slot2);
slot3 = new WorldSlot(root, Paths.SAVE_SLOT_3);
slot3 = new WorldSlot(root, WorkDir.getFile("save/slot_3.ion"));
rows.add(slot3);
// escape to quitn from here
bindKey(new KeyStroke(Keys.ESCAPE), new Runnable() {
bindKey(new KeyStroke(Keys.ESCAPE), Edge.RISING, new Runnable() {
@Override
public void run()
{
getEventBus().send(new GameStateRequest(GameState.MAIN_MENU));
getEventBus().send(new GameStateRequest(RogueState.MAIN_MENU));
}
});
bindKey(new KeyStroke(Keys.Q, Keys.MOD_CONTROL), new Runnable() {
bindKey(new KeyStroke(Keys.Q, Keys.MOD_CONTROL), Edge.RISING, new Runnable() {
@Override
public void run()
{
getEventBus().send(new GameStateRequest(GameState.EXIT));
getEventBus().send(new GameStateRequest(RogueState.EXIT));
}
});
}

@ -13,6 +13,7 @@ import mightypork.gamecore.gui.components.layout.GridLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.events.ScreenRequest;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.ion.Ion;
import mightypork.gamecore.util.ion.IonBundle;
@ -20,7 +21,6 @@ import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res;
import mightypork.rogue.events.LoadingOverlayRequest;
import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider;

@ -2,6 +2,7 @@ package mightypork.rogue.world;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
@ -10,8 +11,7 @@ import mightypork.gamecore.util.math.constraints.rect.RectConst;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectProxy;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.VectConst;
import mightypork.rogue.Config;
import mightypork.rogue.Res;
import mightypork.rogue.Const;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.level.render.TileRenderContext;
@ -144,7 +144,7 @@ public class WorldRenderer extends RectProxy {
// batch rendering of the tiles
if (USE_BATCH_RENDERING) {
Render.setColor(RGB.WHITE, Config.RENDER_UFOG ? 1 : 0.6);
Render.setColor(RGB.WHITE, Const.RENDER_UFOG ? 1 : 0.6);
Render.enterBatchTexturedQuadMode(Res.getTexture("tiles"));
}
for (trc.pos.x = x1; trc.pos.x <= x2; trc.pos.x++) {

@ -2,6 +2,7 @@ package mightypork.rogue.world.entity.render;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.resources.textures.TxSheet;
import mightypork.gamecore.util.math.Calc;
@ -11,7 +12,6 @@ import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.num.mutable.NumVar;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.Res;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityRenderer;
import mightypork.rogue.world.level.render.MapRenderContext;

@ -9,7 +9,7 @@ import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.input.events.MouseButtonEvent;
import mightypork.gamecore.input.events.MouseButtonListener;
import mightypork.gamecore.input.events.MouseButtonHandler;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.color.Color;
@ -32,7 +32,7 @@ import mightypork.rogue.world.gui.interaction.MapInteractionPlugin;
*
* @author MightyPork
*/
public class MapView extends InputComponent implements DelegatingClient, MouseButtonListener, Updateable, WorldAscendRequestListener,
public class MapView extends InputComponent implements DelegatingClient, MouseButtonHandler, Updateable, WorldAscendRequestListener,
WorldDescendRequestListener {
private static final double transition_time = 0.8;

@ -3,7 +3,7 @@ package mightypork.rogue.world.gui;
import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.input.events.MouseButtonEvent;
import mightypork.gamecore.input.events.MouseButtonListener;
import mightypork.gamecore.input.events.MouseButtonHandler;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.color.Color;
@ -12,7 +12,7 @@ import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.mutable.RectMutable;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.Config;
import mightypork.rogue.Const;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.level.Level;
@ -21,7 +21,7 @@ import mightypork.rogue.world.tile.Tile;
import org.lwjgl.opengl.GL11;
public class Minimap extends InputComponent implements MouseButtonListener {
public class Minimap extends InputComponent implements MouseButtonHandler {
private final RectMutable bounds = Rect.makeVar();
private int unit = 0;
@ -56,7 +56,7 @@ public class Minimap extends InputComponent implements MouseButtonListener {
for (pos.x = 0, point.x = tl.xi(); pos.x < lw; pos.x++, point.x += unit) {
final Tile t = lvl.getTile(pos);
if (t.isNull() || (!t.isExplored() && Config.RENDER_UFOG)) continue;
if (t.isNull() || (!t.isExplored() && Const.RENDER_UFOG)) continue;
final Color clr = t.getMapColor();

@ -5,7 +5,7 @@ import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.input.events.KeyEvent;
import mightypork.gamecore.input.events.KeyListener;
import mightypork.gamecore.input.events.KeyEventHandler;
import mightypork.gamecore.util.math.algo.Move;
import mightypork.gamecore.util.math.algo.Moves;
import mightypork.gamecore.util.math.constraints.vect.Vect;
@ -14,7 +14,7 @@ import mightypork.rogue.world.events.PlayerStepEndListener;
import mightypork.rogue.world.gui.MapView;
public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndListener, KeyListener, Updateable {
public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndListener, KeyEventHandler, Updateable {
private static final int[] keys = { Keys.LEFT, Keys.RIGHT, Keys.UP, Keys.DOWN };
private static final Move[] sides = { Moves.W, Moves.E, Moves.N, Moves.S };
@ -49,7 +49,7 @@ public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndLi
if (evt.isDown() || mapView.plc.getPlayer().isMoving()) return; // not interested
if (InputSystem.getModifierKeys() != Keys.MOD_NONE) return;
if (InputSystem.getActiveModKeys() != Keys.MOD_NONE) return;
for (int i = 0; i < 4; i++) {
if (evt.getKey() == keys[i]) {
@ -66,7 +66,7 @@ public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndLi
if (mapView.plc.getPlayer().getMoveProgress() < 0.8) return false;
if (InputSystem.getModifierKeys() != Keys.MOD_NONE) return false;
if (InputSystem.getActiveModKeys() != Keys.MOD_NONE) return false;
for (int i = 0; i < 4; i++) {

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.active;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.ItemModel;

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.food;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.impl.ItemBaseFood;

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.food;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.impl.ItemBaseFood;

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.food;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.impl.ItemBaseFood;

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;

@ -1,7 +1,7 @@
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;

@ -11,7 +11,7 @@ import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonObjBlob;
import mightypork.gamecore.util.ion.IonOutput;
import mightypork.gamecore.util.math.color.Color;
import mightypork.rogue.Config;
import mightypork.rogue.Const;
import mightypork.rogue.world.World;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.level.Level;
@ -53,7 +53,7 @@ public abstract class Tile implements BusAccess, IonObjBlob {
@DefaultImpl
public void renderTile(TileRenderContext context)
{
if (!isExplored() && Config.RENDER_UFOG) return;
if (!isExplored() && Const.RENDER_UFOG) return;
initRenderer();

@ -3,11 +3,11 @@ package mightypork.rogue.world.tile;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.util.annot.DefaultImpl;
import mightypork.gamecore.util.math.algo.Moves;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.rogue.Res;
import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.render.NullTileRenderer;

@ -6,7 +6,7 @@ import java.util.Stack;
import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonOutput;
import mightypork.rogue.Config;
import mightypork.rogue.Const;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.Items;
import mightypork.rogue.world.level.render.TileRenderContext;
@ -33,7 +33,7 @@ public abstract class TileWithItems extends Tile {
{
super.renderExtra(context);
if ((isExplored() || !Config.RENDER_UFOG) && hasItem() && shouldRenderItems()) {
if ((isExplored() || !Const.RENDER_UFOG) && hasItem() && shouldRenderItems()) {
itemRenderer.render(items, context);
}
}

@ -1,7 +1,7 @@
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.impl.TileBaseChest;

@ -1,7 +1,7 @@
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.impl.TileBaseDoor;

@ -1,7 +1,7 @@
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.impl.TileBaseEntrance;

@ -1,7 +1,7 @@
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.impl.TileBaseExit;

@ -1,7 +1,7 @@
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.impl.TileBaseFloor;

@ -1,7 +1,7 @@
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.impl.TileBasePassage;

@ -1,7 +1,7 @@
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.impl.TileBaseSecretDoor;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save