Skip to content
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

Merged
merged 9 commits into from
Aug 27, 2018
Merged

Conversation

viking-sudo-rm
Copy link
Member

  1. Worlds now contain a list of layers which are configurable via config.yml.
  2. Layer interface standardizes implementation for BackgroundLayers, TileLayers, and EntityLayers. Level has been renamed TileLayer.
  3. Reorganized interface hierarchy in snorri.world package. This affects Savable, Loadable, Renderable, etc.
  4. Removed old spaghetti code for deprecated features (creating walls, 2D pathfinding).
  5. Introduced new static factory pattern for creating worlds and some layers (did not take the time to adapt old stuff).
  6. Changed 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.
  7. Other related cleaning up and refactoring.

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.

@@ -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) {
Copy link
Member

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

Copy link
Member

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

Copy link
Member Author

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) {
Copy link
Member

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


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);
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @Override annotation.

// TODO Auto-generated method stub
return null;
public String getFilename() {
return "entity.level";
Copy link
Member

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

Copy link
Member Author

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.

public int getWidth();
public boolean canShootOver(Vector position);

// TODO(lambdaviking): Save this stuff.
Copy link
Member

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

Copy link
Member Author

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.

static Layer fromYAML(World world, Map<String, Object> params) throws IOException {
String type = (String) params.get("type");
switch (type) {
case "background":
Copy link
Member

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();
Copy link
Member

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?

Copy link
Member Author

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.


@Override
public String getFilename() {
return "tile.level";
Copy link
Member

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

Copy link
Member Author

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.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grammar????????????????????????????????

Copy link
Member Author

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.

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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for?

Copy link
Member Author

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.

* @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.
Copy link
Member

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?

Copy link
Member Author

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 TileLayers, which is what was to be figured out. But, for now, I just deleted the unused method.

@viking-sudo-rm viking-sudo-rm merged commit a913efa into master Aug 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants