Skip to content

Commit

Permalink
Move tiles now uses TileSelection
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaskelly committed Apr 26, 2020
1 parent e056d62 commit c6ef102
Showing 1 changed file with 27 additions and 52 deletions.
79 changes: 27 additions & 52 deletions DelvEdit/src/com/interrupt/dungeoneer/editor/EditorApplication.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.interrupt.dungeoneer.editor;

import com.badlogic.gdx.*;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
Expand Down Expand Up @@ -31,8 +30,8 @@
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.*;
import com.interrupt.dungeoneer.*;
import com.interrupt.dungeoneer.Audio;
import com.interrupt.dungeoneer.*;
import com.interrupt.dungeoneer.collision.Collidor;
import com.interrupt.dungeoneer.editor.gfx.SurfacePickerDecal;
import com.interrupt.dungeoneer.editor.gizmos.Gizmo;
Expand Down Expand Up @@ -72,7 +71,6 @@
import com.interrupt.managers.EntityManager;
import com.interrupt.managers.StringManager;
import com.noise.PerlinNoise;
import com.badlogic.gdx.math.MathUtils;

import javax.swing.*;
import java.awt.event.WindowAdapter;
Expand Down Expand Up @@ -4107,61 +4105,38 @@ public Decal getDecal() {
}

public void moveTiles(int moveX, int moveY, float moveZ) {
// TODO: Possibly refactor here?
int selX = Editor.selection.tiles.x;
int selY = Editor.selection.tiles.y;
int selWidth = Editor.selection.tiles.width;
int selHeight = Editor.selection.tiles.height;

// Move Tiles
if(selected) {
Tile[] moving = new Tile[selWidth * selHeight];

for (int x = 0; x < selWidth; x++) {
for (int y = 0; y < selHeight; y++) {
int tileX = selX + x;
int tileY = selY + y;

Tile t = level.getTileOrNull(tileX, tileY);
moving[x + y * Editor.selection.tiles.width] = t;

level.setTile(tileX, tileY, null);
markWorldAsDirty(tileX, tileY, 1);
}
}

for (int x = 0; x < selWidth; x++) {
for (int y = 0; y < selHeight; y++) {
int tileX = selX + x + moveX;
int tileY = selY + y + moveY;

Tile t = moving[x + y * Editor.selection.tiles.width];
Array<TileSelectionInfo> tilesToMove = new Array<TileSelectionInfo>();
for (TileSelectionInfo info : Editor.selection.tiles) {
tilesToMove.add(info);
level.setTile(info.x, info.y, null);
markWorldAsDirty(info.x, info.y, 1);
}

if(moveZ != 0 && t != null) {
t.floorHeight += moveZ;
t.ceilHeight += moveZ;
}
for (TileSelectionInfo info : tilesToMove) {
Tile t = info.tile;
int newX = info.x + moveX;
int newY = info.y + moveY;

level.setTile(tileX, tileY, t);
if(moveZ != 0 && t != null) {
t.floorHeight += moveZ;
t.ceilHeight += moveZ;
}

markWorldAsDirty(tileX, tileY, 1);
}
}
level.setTile(newX, newY, t);
markWorldAsDirty(newX, newY, 1);
}

// Move Markers
for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
if(level.editorMarkers != null && level.editorMarkers.size > 0) {
for(int i = 0; i < level.editorMarkers.size; i++) {
EditorMarker m = level.editorMarkers.get(i);
if(m.x == x && m.y == y) {
m.x += moveX;
m.y += moveY;
}
}
}
}
}
// Move markers
for (TileSelectionInfo info : Editor.selection.tiles) {
for (EditorMarker m : level.editorMarkers) {
if (m.x == info.x && m.y == info.y) {
m.x += moveX;
m.y += moveY;
}
}
}

Editor.selection.tiles.x += moveX;
Editor.selection.tiles.y += moveY;
Expand Down

0 comments on commit c6ef102

Please sign in to comment.