Remembers fullscreen on exit; fixed bug PropertyManager
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import mightypork.gamecore.input.KeyStroke;
|
import mightypork.gamecore.input.KeyStroke;
|
||||||
import mightypork.gamecore.input.Keys;
|
import mightypork.gamecore.input.Keys;
|
||||||
|
import mightypork.gamecore.logging.Log;
|
||||||
import mightypork.gamecore.util.files.config.Property;
|
import mightypork.gamecore.util.files.config.Property;
|
||||||
import mightypork.gamecore.util.files.config.PropertyManager;
|
import mightypork.gamecore.util.files.config.PropertyManager;
|
||||||
|
|
||||||
@@ -160,6 +161,7 @@ public class Config {
|
|||||||
*/
|
*/
|
||||||
public static void save()
|
public static void save()
|
||||||
{
|
{
|
||||||
|
Log.f3("Saving config.");
|
||||||
cfg.save();
|
cfg.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +195,8 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg.setValue(key, value);
|
cfg.setValue(key, value);
|
||||||
|
|
||||||
|
Log.f3("Setting option: " + key + " = " + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ import mightypork.gamecore.core.AppAccess;
|
|||||||
import mightypork.gamecore.core.AppModule;
|
import mightypork.gamecore.core.AppModule;
|
||||||
import mightypork.gamecore.gui.events.LayoutChangeEvent;
|
import mightypork.gamecore.gui.events.LayoutChangeEvent;
|
||||||
import mightypork.gamecore.gui.events.ScreenRequestListener;
|
import mightypork.gamecore.gui.events.ScreenRequestListener;
|
||||||
import mightypork.gamecore.gui.events.ViewportChangeEvent;
|
|
||||||
import mightypork.gamecore.gui.events.ViewportChangeListener;
|
|
||||||
import mightypork.gamecore.logging.Log;
|
import mightypork.gamecore.logging.Log;
|
||||||
import mightypork.gamecore.render.Renderable;
|
import mightypork.gamecore.render.Renderable;
|
||||||
|
import mightypork.gamecore.render.events.ViewportChangeEvent;
|
||||||
|
import mightypork.gamecore.render.events.ViewportChangeListener;
|
||||||
import mightypork.gamecore.util.annot.DefaultImpl;
|
import mightypork.gamecore.util.annot.DefaultImpl;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import java.nio.ByteBuffer;
|
|||||||
|
|
||||||
import mightypork.gamecore.core.AppAccess;
|
import mightypork.gamecore.core.AppAccess;
|
||||||
import mightypork.gamecore.core.AppModule;
|
import mightypork.gamecore.core.AppModule;
|
||||||
import mightypork.gamecore.gui.events.ViewportChangeEvent;
|
|
||||||
import mightypork.gamecore.logging.Log;
|
import mightypork.gamecore.logging.Log;
|
||||||
import mightypork.gamecore.render.events.DisplayReadyEvent;
|
import mightypork.gamecore.render.events.DisplayReadyEvent;
|
||||||
|
import mightypork.gamecore.render.events.ViewportChangeEvent;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
||||||
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.gui.events;
|
package mightypork.gamecore.render.events;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.eventbus.BusEvent;
|
import mightypork.gamecore.eventbus.BusEvent;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package mightypork.gamecore.gui.events;
|
package mightypork.gamecore.render.events;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,8 +128,6 @@ public class PropertyManager {
|
|||||||
props.cfgBlankRowBetweenSections = cfgSeparateSections;
|
props.cfgBlankRowBetweenSections = cfgSeparateSections;
|
||||||
props.cfgBlankRowBeforeComment = cfgNewlineBeforeComments;
|
props.cfgBlankRowBeforeComment = cfgNewlineBeforeComments;
|
||||||
|
|
||||||
final ArrayList<String> keyList = new ArrayList<>();
|
|
||||||
|
|
||||||
// rename keys
|
// rename keys
|
||||||
for (final Entry<String, String> entry : renameTable.entrySet()) {
|
for (final Entry<String, String> entry : renameTable.entrySet()) {
|
||||||
|
|
||||||
@@ -141,28 +139,8 @@ public class PropertyManager {
|
|||||||
props.setProperty(entry.getValue(), pr);
|
props.setProperty(entry.getValue(), pr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate entries one by one, replace with default when needed
|
|
||||||
for (final Property<?> entry : entries.values()) {
|
for (final Property<?> entry : entries.values()) {
|
||||||
keyList.add(entry.getKey());
|
entry.parse(props.getProperty(entry.getKey()));
|
||||||
|
|
||||||
final String propOrig = props.getProperty(entry.getKey());
|
|
||||||
|
|
||||||
entry.parse(propOrig);
|
|
||||||
|
|
||||||
if (entry.getComment() != null) {
|
|
||||||
props.setKeyComment(entry.getKey(), entry.getComment());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propOrig == null || !entry.toString().equals(propOrig)) {
|
|
||||||
props.setProperty(entry.getKey(), entry.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// removed unused props
|
|
||||||
for (final String propname : props.keySet().toArray(new String[props.size()])) {
|
|
||||||
if (!keyList.contains(propname)) {
|
|
||||||
props.remove(propname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renameTable.clear();
|
renameTable.clear();
|
||||||
@@ -172,6 +150,26 @@ public class PropertyManager {
|
|||||||
public void save()
|
public void save()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
final ArrayList<String> keyList = new ArrayList<>();
|
||||||
|
|
||||||
|
// validate entries one by one, replace with default when needed
|
||||||
|
for (final Property<?> entry : entries.values()) {
|
||||||
|
keyList.add(entry.getKey());
|
||||||
|
|
||||||
|
if (entry.getComment() != null) {
|
||||||
|
props.setKeyComment(entry.getKey(), entry.getComment());
|
||||||
|
}
|
||||||
|
|
||||||
|
props.setProperty(entry.getKey(), entry.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// removed unused props
|
||||||
|
for (final String propname : props.keySet().toArray(new String[props.size()])) {
|
||||||
|
if (!keyList.contains(propname)) {
|
||||||
|
props.remove(propname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
props.store(new FileOutputStream(file), fileComment);
|
props.store(new FileOutputStream(file), fileComment);
|
||||||
} catch (final IOException ioe) {
|
} catch (final IOException ioe) {
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import mightypork.gamecore.input.KeyStroke.Edge;
|
|||||||
import mightypork.gamecore.render.DisplaySystem;
|
import mightypork.gamecore.render.DisplaySystem;
|
||||||
import mightypork.gamecore.render.events.FullscreenToggleRequest;
|
import mightypork.gamecore.render.events.FullscreenToggleRequest;
|
||||||
import mightypork.gamecore.render.events.ScreenshotRequest;
|
import mightypork.gamecore.render.events.ScreenshotRequest;
|
||||||
|
import mightypork.gamecore.render.events.ViewportChangeEvent;
|
||||||
|
import mightypork.gamecore.render.events.ViewportChangeListener;
|
||||||
import mightypork.gamecore.util.ion.Ion;
|
import mightypork.gamecore.util.ion.Ion;
|
||||||
import mightypork.rogue.RogueStateManager.RogueState;
|
import mightypork.rogue.RogueStateManager.RogueState;
|
||||||
import mightypork.rogue.events.RogueStateRequest;
|
import mightypork.rogue.events.RogueStateRequest;
|
||||||
@@ -32,7 +34,7 @@ import mightypork.rogue.world.level.Level;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public final class RogueApp extends BaseApp {
|
public final class RogueApp extends BaseApp implements ViewportChangeListener {
|
||||||
|
|
||||||
public RogueApp(File workdir, boolean singleInstance)
|
public RogueApp(File workdir, boolean singleInstance)
|
||||||
{
|
{
|
||||||
@@ -122,4 +124,11 @@ public final class RogueApp extends BaseApp {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewportChanged(ViewportChangeEvent event)
|
||||||
|
{
|
||||||
|
Config.setOption("opt.fullscreen", DisplaySystem.isFullscreen());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class RogueConfig implements ConfigSetup {
|
|||||||
@Override
|
@Override
|
||||||
public void addOptions(PropertyManager prop)
|
public void addOptions(PropertyManager prop)
|
||||||
{
|
{
|
||||||
prop.putBoolean("opt.fullscreen", false, "Start in fullscreen");
|
prop.putBoolean("opt.fullscreen", false, "Start in fullscreen (remembers state at exit)");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user