-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Worlds to contain a mutable list of Layers. #23
Conversation
@@ -37,7 +37,7 @@ | |||
private final int width, height; | |||
|
|||
@SuppressWarnings("unchecked") | |||
public PathGraph(List<Level> levels, int width, int height) { | |||
public PathGraph(List<TileLayer> levels, int width, int height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should rename these variables to something less confusing than levels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can do this whenever we make any manual changes to a file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
@@ -37,7 +37,7 @@ | |||
private final int width, height; | |||
|
|||
@SuppressWarnings("unchecked") | |||
public PathGraph(List<Level> levels, int width, int height) { | |||
public PathGraph(List<TileLayer> levels, int width, int height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can do this whenever we make any manual changes to a file
src/snorri/world/Editable.java
Outdated
|
||
public Level getLevel(int layer); | ||
/** Rendering has the same signature as the one in Layer. */ | ||
public void render(FocusedWindow<?> levelEditor, Graphics2D gr, double deltaTime, boolean b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this extend Renderable and have this method be @OverRide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added @Override
annotation.
src/snorri/world/EntityLayer.java
Outdated
// TODO Auto-generated method stub | ||
return null; | ||
public String getFilename() { | ||
return "entity.level"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be entity.layer, entity.level is too confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Also changed default value when generating a config.
src/snorri/world/Layer.java
Outdated
public int getWidth(); | ||
public boolean canShootOver(Vector position); | ||
|
||
// TODO(lambdaviking): Save this stuff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find out what this means
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored this class to use a LayerType enum to create worlds. This allows some fancy ::
stuff, and definitely cleans up the logic.
src/snorri/world/Layer.java
Outdated
static Layer fromYAML(World world, Map<String, Object> params) throws IOException { | ||
String type = (String) params.get("type"); | ||
switch (type) { | ||
case "background": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should have an enum or constants, just something to think about, having strings seems bad for code maintainability
public interface SavableLayer extends Layer, Savable { | ||
|
||
/** Get the filename for saving the Level in the World folder. */ | ||
public String getFilename(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have a way to change the filename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, good idea. Added enums LayerType
here and PlayableType
in Playable.
src/snorri/world/TileLayer.java
Outdated
|
||
@Override | ||
public String getFilename() { | ||
return "tile.level"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be tile.layer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if (f.exists() && !f.isDirectory()) { | ||
throw new IOException("tried to save world to non-directory"); | ||
throw new IOException("Tried to save world to non-directory."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grammar????????????????????????????????
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null subject allowed in this pragmatic context, bitch.
src/snorri/world/World.java
Outdated
Layer layer = Layer.fromYAML(this, params); | ||
addLayer(layer); | ||
} catch (Exception e) { | ||
// FIXME(lambdaviking): Does getting rid of forEach allow us not to use this clause? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elaborated in comment that is not a FIXME.
src/snorri/world/World.java
Outdated
* @param index Index of the layer in the layers array. | ||
* @return The layer whose index in layers is <code>index</code>. | ||
*/ | ||
// TODO(lambdaviking): Figure this out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you need to figure out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this code. We should probably eventually support an API for accessing different TileLayer
s, which is what was to be figured out. But, for now, I just deleted the unused method.
BackgroundLayer
s,TileLayer
s, andEntityLayer
s.Level
has been renamedTileLayer
.snorri.world
package. This affectsSavable
,Loadable
,Renderable
, etc.LevelEditor
to have a currently selected layer for editing. Currently, this layer is set to the standard tile layer, but we can introduce functionality to switch it to edit foreground layers in the future.Through manual testing, I have confirmed that old-formatted levels can be loaded in the
LevelEditor
. Additionally, new levels can be created, and levels that have been loaded can be saved correctly.Fixes #14.