mason shop in and working
parent
ce5906b768
commit
ac0a9217db
|
|
@ -64,8 +64,12 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
listener.update(ords[0].x, ords[0].y, ords[2].x + 1, ords[2].y + 1);
|
||||
return;
|
||||
}
|
||||
if(type == BuildType.SINGLE && dimensions != null) {
|
||||
listener.update(worldcoords.x, worldcoords.y, dimensions.x, dimensions.y);
|
||||
} else {
|
||||
listener.update(worldcoords.x, worldcoords.y, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void deactiveate() {
|
||||
active = false;
|
||||
|
|
@ -85,6 +89,12 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
private int x, y;
|
||||
private boolean mouseDown = false;
|
||||
|
||||
private Vector2i dimensions = new Vector2i(1, 1);
|
||||
|
||||
public void setDimensions(Vector2i dimensions) {
|
||||
this.dimensions = dimensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDown(int button) {
|
||||
if(button == 1 && active && hovered) {
|
||||
|
|
@ -97,7 +107,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
x = worldcoords.x;
|
||||
y = worldcoords.y;
|
||||
if(type == BuildType.SINGLE) {
|
||||
listener.build(x, y);
|
||||
listener.build(x, y, x + dimensions.x - 1, y + dimensions.y - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -121,6 +131,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated(since = "What is this abomination", forRemoval = true)
|
||||
private Vector2i[] orderCoords(Vector2i a, Vector2i b) {
|
||||
return new Vector2i[] {
|
||||
new Vector2i(Math.min(a.x, b.x), Math.min(a.y, b.y)),
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
public record BuildableRecord(
|
||||
String name,
|
||||
Constructor<? extends IBuildable> constructor,
|
||||
BuildType type
|
||||
BuildType type,
|
||||
Vector2i dimensions
|
||||
) {}
|
||||
|
||||
public static void registerBuildable(Class<? extends IBuildable> clazz) {
|
||||
|
|
@ -84,12 +85,13 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
String category = buildable.getBuildTabCategory();
|
||||
String name = buildable.getBuildTabName();
|
||||
BuildType type = buildable.getBuildType();
|
||||
Vector2i dim = buildable.getDimensions();
|
||||
|
||||
DebugTab.log("Added " + category + " / " + name);
|
||||
|
||||
if(!buildables.containsKey(category))
|
||||
buildables.put(category, new ArrayList<BuildableRecord>());
|
||||
buildables.get(category).add(new BuildableRecord(name, constructor, type));
|
||||
buildables.get(category).add(new BuildableRecord(name, constructor, type, dim));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -148,6 +150,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
selectedBuildable = buildableRecord;
|
||||
buildLayer.activate(this);
|
||||
buildLayer.setBuildType(selectedBuildable.type);
|
||||
buildLayer.setDimensions(selectedBuildable.dimensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -172,20 +175,6 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(int x1, int y1) {
|
||||
if(selectedBuildable == null) return;
|
||||
try {
|
||||
IBuildable building = selectedBuildable.constructor.newInstance();
|
||||
if(building instanceof GameObject) {
|
||||
add((GameObject) building);
|
||||
}
|
||||
building.buildAt(x1, y1, 1, 1);
|
||||
} catch (Exception e) {
|
||||
DebugTab.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if(selectedBuildable == null) {
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ import xyz.valnet.hadean.util.detail.Detail;
|
|||
|
||||
public abstract class Buildable extends WorldObject implements IBuildable, ITileThing, ISelectable {
|
||||
|
||||
protected Vector2i getDimensions() {
|
||||
return new Vector2i(1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildAt(int x, int y, int w, int h) {
|
||||
setPosition(x, y, w, h);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import xyz.valnet.hadean.util.Assets;
|
|||
public class Bed extends Construction {
|
||||
|
||||
@Override
|
||||
protected Vector2i getDimensions() {
|
||||
public Vector2i getDimensions() {
|
||||
return new Vector2i(1, 2);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,6 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
|
||||
protected abstract IItemPredicate getBuildingMaterial();
|
||||
protected abstract int getBuildingMaterialCount();
|
||||
protected Vector2i getDimensions() {
|
||||
return new Vector2i(1, 1);
|
||||
}
|
||||
|
||||
private final boolean isBuildingMaterialSatisfied() {
|
||||
return containedItems.size() >= getBuildingMaterialCount();
|
||||
|
|
@ -147,7 +144,7 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
|
||||
@Override
|
||||
public BuildType getBuildType() {
|
||||
return BuildType.AREA;
|
||||
return BuildType.SINGLE;
|
||||
}
|
||||
@Override
|
||||
public String getBuildTabCategory() {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public class MasonWorkshop extends Construction {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Vector2i getDimensions() {
|
||||
public Vector2i getDimensions() {
|
||||
return new Vector2i(3, 3);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
public interface IBuildLayerListener {
|
||||
@Deprecated
|
||||
public void update(int x, int y, int w, int h);
|
||||
@Deprecated
|
||||
public void build(int x, int y, int w, int h);
|
||||
public void build(int x, int y);
|
||||
public void cancel();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
|
||||
public interface IBuildable {
|
||||
|
||||
public void buildAt(int x, int y, int w, int h);
|
||||
|
|
@ -8,4 +10,8 @@ public interface IBuildable {
|
|||
public BuildType getBuildType();
|
||||
public String getBuildTabName();
|
||||
|
||||
public default Vector2i getDimensions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue