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