Compare commits
13 Commits
bottom-bar
...
stable
| Author | SHA1 | Date |
|---|---|---|
|
|
4dff9566a4 | |
|
|
c4bfd44cc9 | |
|
|
51d6c3db8b | |
|
|
39710d33a7 | |
|
|
ac0a9217db | |
|
|
ce5906b768 | |
|
|
04eaf1434f | |
|
|
54229b1f2e | |
|
|
fe29860988 | |
|
|
3c2a62c7dd | |
|
|
f4608463e0 | |
|
|
93b2788c58 | |
|
|
4d2a630fce |
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const { readdirSync, readFileSync } = require('fs');
|
||||
const { resolve, parse, relative } = require('path');
|
||||
|
||||
const trimWhitespace = true;
|
||||
const base = "./src";
|
||||
|
||||
let lines = 0;
|
||||
let files = [];
|
||||
|
||||
function processDir(path) {
|
||||
const children = readdirSync(path, {
|
||||
withFileTypes: true
|
||||
});
|
||||
for(const entity of children) {
|
||||
const { name } = entity
|
||||
const full = resolve(path, name);
|
||||
if(entity.isFile()) {
|
||||
processFile(full);
|
||||
} else if(entity.isDirectory()) {
|
||||
processDir(full);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function processFile(path) {
|
||||
const parsed = parse(path);
|
||||
const rel = relative(resolve(base), path)
|
||||
const type = parsed.ext;
|
||||
const text = readFileSync(path);
|
||||
|
||||
console.log(path);
|
||||
}
|
||||
|
||||
function printStats() {
|
||||
console.log("")
|
||||
}
|
||||
|
||||
processDir(base);
|
||||
printStats();
|
||||
|
|
@ -21,7 +21,7 @@ public abstract class Game {
|
|||
if(this.scene != null) {
|
||||
this.scene.disable();
|
||||
}
|
||||
scene.enable();
|
||||
scene.enable(this);
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +51,14 @@ public abstract class Game {
|
|||
}
|
||||
}
|
||||
|
||||
public final float getAverageFPS() {
|
||||
return averageFPS;
|
||||
}
|
||||
|
||||
public final int getMeasuredFPS() {
|
||||
return measuredFPS;
|
||||
}
|
||||
|
||||
public abstract void updateViewMatrix(Matrix4f matrix);
|
||||
|
||||
public final void scrollUp() {
|
||||
|
|
|
|||
|
|
@ -173,6 +173,30 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
|
|||
}
|
||||
}
|
||||
|
||||
private final Vector2i getNextBoxDimensions() {
|
||||
if(context.fixedSize) {
|
||||
return context.box.dim.asInt();
|
||||
} else {
|
||||
return Vector2i.zero;
|
||||
}
|
||||
}
|
||||
|
||||
private LayoutStyle getDefaultLayoutStyle() {
|
||||
if(context.fixedSize) {
|
||||
if(context.horizontal) {
|
||||
return LayoutStyle.shrink; // IDK if thats a good default...
|
||||
} else {
|
||||
return LayoutStyle.expandWidth;
|
||||
}
|
||||
} else {
|
||||
if(context.horizontal) {
|
||||
return LayoutStyle.normal;
|
||||
} else {
|
||||
return LayoutStyle.normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === ELEMENTS ===
|
||||
//
|
||||
|
||||
|
|
@ -247,39 +271,26 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
|
|||
}
|
||||
|
||||
protected boolean button(String text) {
|
||||
return button(genButtonId(), text, false);
|
||||
return button(genButtonId(), text, getDefaultLayoutStyle());
|
||||
}
|
||||
|
||||
protected boolean button(String text, boolean expand) {
|
||||
return button(genButtonId(), text, expand);
|
||||
protected boolean button(String text, LayoutStyle style) {
|
||||
return button(genButtonId(), text, style);
|
||||
}
|
||||
|
||||
protected boolean button(String id, String text) {
|
||||
return button(id, text, false);
|
||||
return button(id, text, getDefaultLayoutStyle());
|
||||
}
|
||||
|
||||
protected boolean button(String id, String text, boolean expand) {
|
||||
int h = 32;
|
||||
if(expand && context.fixedSize) {
|
||||
h = (int) context.box.h;
|
||||
}
|
||||
int w = (int) context.box.w;
|
||||
if(context.horizontal && !context.fixedSize) {
|
||||
w = 100;
|
||||
}
|
||||
|
||||
int x = (int) context.box.x;
|
||||
int y = (int) context.box.y;
|
||||
protected boolean button(String id, String text, LayoutStyle style) {
|
||||
Vector2i position = getNextBoxLocation();
|
||||
Vector2i availableSpace = getNextBoxDimensions();
|
||||
|
||||
if(!context.fixedSize) {
|
||||
if(context.vertical()) {
|
||||
y += (int) context.box.h;
|
||||
} else {
|
||||
x += (int) context.box.w;
|
||||
}
|
||||
}
|
||||
|
||||
Box buttonBox = new Box(x, y, w, h);
|
||||
Box buttonBox = new Box(
|
||||
position,
|
||||
availableSpace.x == 0 ? style.width : (float) Math.min(style.width, availableSpace.x),
|
||||
availableSpace.y == 0 ? style.height : (float) Math.min(style.height, availableSpace.y)
|
||||
);
|
||||
Button btn = getButton(id);
|
||||
|
||||
if(!context.hasRegisteredGuiArea) {
|
||||
|
|
@ -287,8 +298,8 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
|
|||
}
|
||||
|
||||
btn.setText(text);
|
||||
btn.setPosition(x, y);
|
||||
btn.setSize(w, h);
|
||||
btn.setPosition((int) buttonBox.x, (int) buttonBox.y);
|
||||
btn.setSize((int) buttonBox.w, (int) buttonBox.h);
|
||||
btn.setLayer(getCurrentLayer());
|
||||
|
||||
adjustBox(buttonBox.w, buttonBox.h);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package xyz.valnet.engine.graphics;
|
||||
|
||||
public class LayoutStyle {
|
||||
public int width = 100, height = 32;
|
||||
|
||||
public static LayoutStyle normal = LayoutStyle.sized(100, 32);
|
||||
public static LayoutStyle expand = LayoutStyle.sized(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
public static LayoutStyle shrink = LayoutStyle.sized(0, 0);
|
||||
public static LayoutStyle expandWidth = LayoutStyle.sized(Integer.MAX_VALUE, 32);
|
||||
|
||||
public static LayoutStyle sized(int w, int h) {
|
||||
LayoutStyle btn = new LayoutStyle();
|
||||
btn.width = w;
|
||||
btn.height = h;
|
||||
return btn;
|
||||
}
|
||||
}
|
||||
|
|
@ -85,6 +85,14 @@ public class Box implements Serializable {
|
|||
return new Box(x, y, x2 - x, y2 - y);
|
||||
}
|
||||
|
||||
public static Box fromPoints(Vector2f a, Vector2i b) {
|
||||
return new Box(a.x, a.y, b.x - a.x, b.y - a.y);
|
||||
}
|
||||
|
||||
public static Box fromPoints(Vector2i a, Vector2f b) {
|
||||
return new Box(a.x, a.y, b.x - a.x, b.y - a.y);
|
||||
}
|
||||
|
||||
public Box copy() {
|
||||
return new Box(x, y, w, h);
|
||||
}
|
||||
|
|
@ -92,4 +100,56 @@ public class Box implements Serializable {
|
|||
public boolean contains(float x, float y) {
|
||||
return x >= this.x && x < this.x2 && y >= this.y && y < this.y2;
|
||||
}
|
||||
|
||||
public boolean contains(Vector2f pos) {
|
||||
return contains(pos.x, pos.y);
|
||||
}
|
||||
|
||||
public boolean intersects(Box other) {
|
||||
boolean aLeftOfB = x2 <= other.x;
|
||||
boolean aRightOfB = x >= other.x2;
|
||||
boolean aAboveB = y >= other.y2;
|
||||
boolean aBelowB = y2 <= other.y;
|
||||
|
||||
return !( aLeftOfB || aRightOfB || aAboveB || aBelowB );
|
||||
}
|
||||
|
||||
public Vector2i[] getBorders() {
|
||||
|
||||
// TODO this could be bad, idk man. maybe define an intbox...
|
||||
int x = (int) Math.round(this.x);
|
||||
int y = (int) Math.round(this.y);
|
||||
int w = (int) Math.round(this.w);
|
||||
int h = (int) Math.round(this.h);
|
||||
|
||||
int size = 2 * w + 2 * h;
|
||||
Vector2i[] vecs = new Vector2i[size];
|
||||
|
||||
// top / bottom row
|
||||
for(int i = 0; i < h; i ++) {
|
||||
vecs[i] = new Vector2i(x + i, y - 1);
|
||||
vecs[size - i - 1] = new Vector2i(x + i, y + h);
|
||||
}
|
||||
|
||||
// middle pillars
|
||||
for(int i = 0; i < h; i ++) {
|
||||
vecs[w + i * 2] = new Vector2i(x - 1, y + i);
|
||||
vecs[w + i * 2 + 1] = new Vector2i(x + h, y + i);
|
||||
}
|
||||
|
||||
return vecs;
|
||||
}
|
||||
|
||||
public Box outset(float f) {
|
||||
return new Box(x - f, y - f, w + 2 * f, h + 2 * f);
|
||||
}
|
||||
|
||||
public Box quantize() {
|
||||
return Box.fromPoints(
|
||||
(float) Math.floor(x),
|
||||
(float) Math.floor(y),
|
||||
(float) Math.ceil(x2),
|
||||
(float) Math.ceil(y2)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
package xyz.valnet.engine.math;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class TileBox implements Serializable {
|
||||
public final int x, y;
|
||||
public final int w, h;
|
||||
|
||||
public final Vector2i topLeft;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TileCallback {
|
||||
public void apply(int x, int y);
|
||||
}
|
||||
|
||||
public TileBox(int x, int y, int w, int h) {
|
||||
if(w < 0) {
|
||||
x += w + 1;
|
||||
w *= -1;
|
||||
}
|
||||
if(h < 0) {
|
||||
y += h + 1;
|
||||
h *= -1;
|
||||
}
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
topLeft = new Vector2i(x, y);
|
||||
}
|
||||
|
||||
public TileBox(Vector2i pos, Vector2i dim) {
|
||||
this(pos.x, pos.y, dim.x, dim.y);
|
||||
}
|
||||
|
||||
public TileBox(int x, int y, Vector2i dim) {
|
||||
this(x, y, dim.x, dim.y);
|
||||
}
|
||||
|
||||
public TileBox(Vector2i pos, int w, int h) {
|
||||
this(pos.x, pos.y, w, h);
|
||||
}
|
||||
|
||||
public void forEach(TileCallback cb) {
|
||||
for(int i = 0; i < w; i ++) {
|
||||
for(int j = 0; j < h; j ++) {
|
||||
cb.apply(x + i, y + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TileBox fromPoints(int x, int y, int x2, int y2) {
|
||||
return new TileBox(
|
||||
x <= x2 ? x : x2,
|
||||
y <= y2 ? y : y2,
|
||||
x <= x2 ? (x2 - x + 1) : (x - x2 + 1),
|
||||
y <= y2 ? (y2 - y + 1) : (y - y2 + 1)
|
||||
);
|
||||
}
|
||||
|
||||
public static TileBox fromPoints(Vector2i a, int x2, int y2) {
|
||||
return fromPoints(a.x, a.y, x2, y2);
|
||||
}
|
||||
|
||||
public static TileBox fromPoints(int x, int y, Vector2i b) {
|
||||
return fromPoints(x, y, b.x, b.y);
|
||||
}
|
||||
|
||||
public static TileBox fromPoints(Vector2i a, Vector2i b) {
|
||||
return fromPoints(a.x, a.y, b.x, b.y);
|
||||
}
|
||||
|
||||
public Box asBox() {
|
||||
return new Box(x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ public class Vector2f implements Serializable {
|
|||
}
|
||||
|
||||
public Vector2i asInt() {
|
||||
return new Vector2i((int)x, (int)y);
|
||||
return new Vector2i((int)Math.floor(x), (int)Math.floor(y));
|
||||
}
|
||||
|
||||
public boolean equals(Vector2f v) {
|
||||
|
|
@ -51,4 +51,10 @@ public class Vector2f implements Serializable {
|
|||
public String toString() {
|
||||
return "<" + x + ", " + y + ">";
|
||||
}
|
||||
|
||||
public Vector2f clamp(Box box) {
|
||||
float x = Math.min(Math.max(this.x, box.x), box.x2);
|
||||
float y = Math.min(Math.max(this.y, box.y), box.y2);
|
||||
return new Vector2f(x, y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ public class Vector2i implements Serializable {
|
|||
|
||||
public int x, y;
|
||||
|
||||
public static Vector2i one = new Vector2i(1, 1);
|
||||
public static Vector2i zero = new Vector2i(0, 0);
|
||||
|
||||
public Vector2i() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
|
@ -55,8 +58,16 @@ public class Vector2i implements Serializable {
|
|||
return new Vector2i(x - 1, y);
|
||||
}
|
||||
|
||||
public Box getTileBox() {
|
||||
return new Box(x, y, 1, 1);
|
||||
public TileBox getTileBox() {
|
||||
return new TileBox(x, y, 1, 1);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "<" + x + ", " + y + ">";
|
||||
}
|
||||
|
||||
public Vector2i sub(Vector2i b) {
|
||||
return new Vector2i(this.x - b.x, this.y - b.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package xyz.valnet.engine.scenegraph;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import xyz.valnet.engine.scenegraph.SceneGraph.GameObjectCallback;
|
||||
import xyz.valnet.hadean.util.Pair;
|
||||
|
||||
public class GameObject implements IRenderable, ITickable, Serializable {
|
||||
private transient SceneGraph scene;
|
||||
|
||||
|
|
@ -85,4 +88,16 @@ public class GameObject implements IRenderable, ITickable, Serializable {
|
|||
protected boolean isPaused() {
|
||||
return scene.isPaused();
|
||||
}
|
||||
|
||||
protected Pair<Float, Integer> getFPS() {
|
||||
return scene.getFPS();
|
||||
}
|
||||
|
||||
protected void onAddGameObject(GameObjectCallback listener) {
|
||||
scene.registerAddListener(listener);
|
||||
}
|
||||
|
||||
protected void onRemoveGameObject(GameObjectCallback listener) {
|
||||
scene.registerRemoveListener(listener);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package xyz.valnet.engine.scenegraph;
|
||||
|
||||
import xyz.valnet.engine.Game;
|
||||
|
||||
public interface IScene {
|
||||
public void render();
|
||||
public void update(float dTime);
|
||||
|
|
@ -14,6 +16,6 @@ public interface IScene {
|
|||
public void keyRelease(int key);
|
||||
public void keyRepeat(int key);
|
||||
|
||||
public void enable();
|
||||
public void enable(Game game);
|
||||
public void disable();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.io.FileInputStream;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -15,8 +16,10 @@ import java.util.Set;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import xyz.valnet.engine.App;
|
||||
import xyz.valnet.engine.Game;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
|
||||
import xyz.valnet.hadean.util.Pair;
|
||||
|
||||
public abstract class SceneGraph implements IScene {
|
||||
protected final List<GameObject> objects = new ArrayList<GameObject>();
|
||||
|
|
@ -28,6 +31,22 @@ public abstract class SceneGraph implements IScene {
|
|||
private boolean loadFlag = false;
|
||||
private boolean saveFlag = false;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface GameObjectCallback extends Serializable {
|
||||
public void apply(GameObject obj);
|
||||
}
|
||||
|
||||
private Set<GameObjectCallback> onAddListeners = new HashSet<>();
|
||||
private Set<GameObjectCallback> onRemoveListeners = new HashSet<>();
|
||||
|
||||
public void registerAddListener(GameObjectCallback cb) {
|
||||
onAddListeners.add(cb);
|
||||
}
|
||||
|
||||
public void registerRemoveListener(GameObjectCallback cb) {
|
||||
onRemoveListeners.add(cb);
|
||||
}
|
||||
|
||||
public <T> T get(Class<T> clazz) {
|
||||
for(GameObject obj : objects) {
|
||||
if(clazz.isInstance(obj)) {
|
||||
|
|
@ -49,6 +68,7 @@ public abstract class SceneGraph implements IScene {
|
|||
|
||||
@Override
|
||||
public void update(float dTime) {
|
||||
dTime = Math.min(dTime, 6);
|
||||
// ADD OBJECTS
|
||||
if(!newObjects.isEmpty()) {
|
||||
List<GameObject> added = new ArrayList<GameObject>();
|
||||
|
|
@ -129,13 +149,15 @@ public abstract class SceneGraph implements IScene {
|
|||
}
|
||||
|
||||
private boolean paused = false;
|
||||
private Game game;
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
public void enable(Game game) {
|
||||
this.game = game;
|
||||
this.construct();
|
||||
|
||||
for(GameObject obj : objects) {
|
||||
|
|
@ -149,6 +171,12 @@ public abstract class SceneGraph implements IScene {
|
|||
for(GameObject obj : objects) {
|
||||
obj.addedToScene();
|
||||
}
|
||||
|
||||
for(GameObject obj : objects) {
|
||||
for(GameObjectCallback listener : onAddListeners) {
|
||||
listener.apply(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -174,6 +202,9 @@ public abstract class SceneGraph implements IScene {
|
|||
newObjects.add(obj);
|
||||
obj.link(this);
|
||||
obj.addedToScene();
|
||||
for(GameObjectCallback listener : onAddListeners) {
|
||||
listener.apply(obj);
|
||||
}
|
||||
addObjectToCache(obj);
|
||||
}
|
||||
|
||||
|
|
@ -185,6 +216,9 @@ public abstract class SceneGraph implements IScene {
|
|||
|
||||
public void remove(GameObject obj) {
|
||||
removeObjects.add(obj);
|
||||
for(GameObjectCallback listener : onRemoveListeners) {
|
||||
listener.apply(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean inScene(GameObject gameObject) {
|
||||
|
|
@ -215,6 +249,12 @@ public abstract class SceneGraph implements IScene {
|
|||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
private ArrayList<GameObject> getTransientObjects() {
|
||||
return new ArrayList<GameObject>(objects.stream()
|
||||
.filter(go -> (go instanceof ITransient))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
private void save() {
|
||||
try {
|
||||
FileOutputStream file = new FileOutputStream("SAVE_DATA.TXT");
|
||||
|
|
@ -242,6 +282,7 @@ public abstract class SceneGraph implements IScene {
|
|||
input.close();
|
||||
file.close();
|
||||
DebugTab.log("imported " + newObjects.size() + " objects");
|
||||
dump(newObjects);
|
||||
ArrayList<GameObject> toRemove = getNonTransientObjects();
|
||||
|
||||
for(GameObject obj : toRemove) {
|
||||
|
|
@ -253,6 +294,12 @@ public abstract class SceneGraph implements IScene {
|
|||
for(GameObject obj : newObjects) obj.link(this);
|
||||
for(GameObject obj : newObjects) obj.addedToScene();
|
||||
|
||||
// transients that survive a scene load, should be
|
||||
// re-connected to the new scene
|
||||
for(GameObject obj : getTransientObjects()) {
|
||||
obj.connect();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -322,4 +369,8 @@ public abstract class SceneGraph implements IScene {
|
|||
iml.scrollUp();
|
||||
}
|
||||
}
|
||||
|
||||
public Pair<Float, Integer> getFPS() {
|
||||
return new Pair<Float, Integer>(game.getAverageFPS(), game.getMeasuredFPS());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package xyz.valnet.engine.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ClassToInstanceSet<B> {
|
||||
private Map<Class<? extends B>, Set<B>> map = new HashMap<>();
|
||||
|
||||
private final <T extends B> void ensure(Class<T> clazz) {
|
||||
if(!map.containsKey(clazz)) {
|
||||
map.put(clazz, new HashSet<>());
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends B> void add(Class<T> clazz, T obj) {
|
||||
ensure(clazz);
|
||||
var set = map.get(clazz);
|
||||
set.add(obj);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // it IS checked, by way of the add method.
|
||||
public final <T extends B> Set<T> get(Class<T> clazz) {
|
||||
return (Set<T>) map.get(clazz);
|
||||
}
|
||||
}
|
||||
|
|
@ -31,14 +31,6 @@ public class HadeanGame extends Game {
|
|||
if(!debugView) return;
|
||||
}
|
||||
|
||||
public float getAverageFPS() {
|
||||
return averageFPS;
|
||||
}
|
||||
|
||||
public int getMeasuredFPS() {
|
||||
return measuredFPS;
|
||||
}
|
||||
|
||||
// receive the updated matrix every frame for the actual window.
|
||||
@Override
|
||||
public void updateViewMatrix(Matrix4f matrix) {
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
package xyz.valnet.hadean;
|
||||
|
||||
public class ItemDescriptor {
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
package xyz.valnet.hadean.designation;
|
||||
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Tree;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
|
||||
@BuildableMetadata(category = "Jobs", name = "Chop Trees")
|
||||
public class CutTreesDesignation extends Designation<Tree> {
|
||||
|
||||
@Override
|
||||
|
|
@ -15,4 +13,9 @@ public class CutTreesDesignation extends Designation<Tree> {
|
|||
protected void designate(Tree thing) {
|
||||
thing.runAction(Tree.ACTION_CHOP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabName() {
|
||||
return "ChopTrees";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ package xyz.valnet.hadean.designation;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.TileBox;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
|
||||
|
|
@ -11,39 +13,26 @@ public abstract class Designation<T extends ISelectable> extends GameObject impl
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void buildAt(int x, int y, int w, int h) {
|
||||
public void buildAt(TileBox tileBox) {
|
||||
Box box = tileBox.asBox();
|
||||
Class<T> type = getType();
|
||||
List<T> things = getAll(type);
|
||||
for(ISelectable thing : things) {
|
||||
Vector4f box = thing.getWorldBox();
|
||||
if(rectanglesIntersect(x, y, x + w, y + h, box.x, box.y, box.z, box.w))
|
||||
designate((T) thing);
|
||||
Box thingBox = thing.getWorldBox();
|
||||
if(box.intersects(thingBox))
|
||||
designate((T) thing);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void buildAt(int x, int y) {
|
||||
Class<T> type = getType();
|
||||
List<T> things = getAll(type);
|
||||
for(ISelectable thing : things) {
|
||||
Vector4f box = thing.getWorldBox();
|
||||
if(rectanglesIntersect(x, y, x + 1, y + 1, box.x, box.y, box.z, box.w))
|
||||
designate((T) thing);
|
||||
}
|
||||
public String getBuildTabCategory() {
|
||||
return "Jobs";
|
||||
}
|
||||
|
||||
public boolean rectanglesIntersect(
|
||||
float minAx, float minAy, float maxAx, float maxAy,
|
||||
float minBx, float minBy, float maxBx, float maxBy ) {
|
||||
boolean aLeftOfB = maxAx <= minBx;
|
||||
boolean aRightOfB = minAx >= maxBx;
|
||||
boolean aAboveB = minAy >= maxBy;
|
||||
boolean aBelowB = maxAy <= minBy;
|
||||
|
||||
return !( aLeftOfB || aRightOfB || aAboveB || aBelowB );
|
||||
@Override
|
||||
public BuildType getBuildType() {
|
||||
return BuildType.AREA;
|
||||
}
|
||||
|
||||
|
||||
protected abstract Class<T> getType();
|
||||
protected abstract void designate(T thing);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
package xyz.valnet.hadean.designation;
|
||||
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
|
||||
@BuildableMetadata(category = "Jobs", name = "Haul Items")
|
||||
public class HaulItemDesignation extends Designation<Item> {
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<Item> getType() {
|
||||
return Item.class;
|
||||
|
|
@ -16,4 +13,9 @@ public class HaulItemDesignation extends Designation<Item> {
|
|||
protected void designate(Item thing) {
|
||||
thing.runAction(Item.HAUL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabName() {
|
||||
return "Haul Items";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import xyz.valnet.engine.graphics.Drawing;
|
|||
import xyz.valnet.engine.graphics.Sprite;
|
||||
import xyz.valnet.engine.graphics.Tile9;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.TileBox;
|
||||
import xyz.valnet.engine.math.Vector2f;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
|
|
@ -31,6 +32,8 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
|
||||
private float minY, maxY;
|
||||
|
||||
private Box focusBounds = null;
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
IWorldBoundsAdapter worldBoundsAdapter = get(IWorldBoundsAdapter.class);
|
||||
|
|
@ -39,7 +42,11 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
maxY = bounds.w;
|
||||
}
|
||||
|
||||
public Vector2f getWorldMouse() {
|
||||
public final void setFocusBounds(Box box) {
|
||||
this.focusBounds = box;
|
||||
}
|
||||
|
||||
public final Vector2f getWorldMouse() {
|
||||
return screen2world(App.mouseX, App.mouseY);
|
||||
}
|
||||
|
||||
|
|
@ -67,6 +74,10 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
Vector2f dragDifference = screen2world(App.mouseX, App.mouseY).subtract(focus);
|
||||
focus = dragOrigin.subtract(dragDifference);
|
||||
}
|
||||
|
||||
if(focusBounds != null) {
|
||||
focus = focus.clamp(focusBounds);
|
||||
}
|
||||
}
|
||||
|
||||
public void focus(float x, float y) {
|
||||
|
|
@ -74,24 +85,32 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
this.focus.y = y;
|
||||
}
|
||||
|
||||
public Vector2i world2screen(float x, float y) {
|
||||
public final Box world2screen(Box box) {
|
||||
return Box.fromPoints(world2screen(box.a), world2screen(box.b));
|
||||
}
|
||||
|
||||
public final Vector2i world2screen(float x, float y) {
|
||||
return new Vector2i((int)(x * tileWidth + screenWidth / 2 - focus.x * tileWidth), (int)(y * tileWidth + screenHeight / 2 - focus.y * tileWidth));
|
||||
}
|
||||
|
||||
public Vector2i world2screen(Vector2f pos) {
|
||||
public final Vector2i world2screen(Vector2f pos) {
|
||||
return world2screen(pos.x, pos.y);
|
||||
}
|
||||
|
||||
public Vector2f screen2world(float x, float y) {
|
||||
public final Vector2i world2screen(Vector2i pos) {
|
||||
return world2screen(pos.x, pos.y);
|
||||
}
|
||||
|
||||
public final Vector2f screen2world(float x, float y) {
|
||||
return new Vector2f((x - screenWidth / 2 + focus.x * tileWidth) / tileWidth, (y - screenHeight / 2 + focus.y * tileWidth) / tileWidth);
|
||||
}
|
||||
|
||||
public Vector2f screen2world(Vector2f pos) {
|
||||
public final Vector2f screen2world(Vector2f pos) {
|
||||
return screen2world(pos.x, pos.y);
|
||||
}
|
||||
|
||||
// !! this takes an AABB and returns and AABB
|
||||
public Vector4f world2screen(Vector4f input) {
|
||||
public final Vector4f world2screen(Vector4f input) {
|
||||
return new Vector4f(
|
||||
input.x * tileWidth + screenWidth / 2 - focus.x * tileWidth,
|
||||
input.y * tileWidth + screenHeight / 2 - focus.y * tileWidth,
|
||||
|
|
@ -101,53 +120,58 @@ public class Camera extends GameObject implements ITransient, IMouseCaptureArea
|
|||
}
|
||||
|
||||
@Deprecated
|
||||
public void draw(Sprite sprite, float x, float y) {
|
||||
public final void draw(Sprite sprite, float x, float y) {
|
||||
Vector2i screenPos = world2screen(x, y);
|
||||
Drawing.drawSprite(sprite, (screenPos.x), (screenPos.y), tileWidth, tileWidth);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void draw(Sprite sprite, float x, float y, float w, float h) {
|
||||
public final void draw(Sprite sprite, float x, float y, float w, float h) {
|
||||
Vector2i screenPos = world2screen(x, y);
|
||||
Drawing.drawSprite(sprite, (screenPos.x), (screenPos.y), (int)(tileWidth * w), (int)(tileWidth * h));
|
||||
}
|
||||
|
||||
public void draw(float layer, Sprite sprite, float x, float y) {
|
||||
public final void draw(float layer, Sprite sprite, float x, float y) {
|
||||
draw(layer, sprite, x, y, 1, 1);
|
||||
}
|
||||
|
||||
public void draw(float layer, Sprite sprite, Vector2f pos) {
|
||||
public final void draw(float layer, Sprite sprite, Vector2f pos) {
|
||||
draw(layer, sprite, pos.x, pos.y, 1, 1);
|
||||
}
|
||||
|
||||
public void draw(float layer, Sprite sprite, Vector4i pos) {
|
||||
public final void draw(float layer, Sprite sprite, Vector4i pos) {
|
||||
draw(layer, sprite, pos.x, pos.y, pos.z, pos.w);
|
||||
}
|
||||
|
||||
public void draw(float layer, Sprite sprite, float x, float y, float w, float h) {
|
||||
public final void draw(float layer, Sprite sprite, float x, float y, float w, float h) {
|
||||
Vector2i screenPos = world2screen(x, y);
|
||||
Drawing.setLayer(layer + (((y + h) - minY) / (maxY - minY)));
|
||||
Drawing.drawSprite(sprite, (int)(screenPos.x), (int)(screenPos.y), (int)(tileWidth * w), (int)(tileWidth * h));
|
||||
}
|
||||
|
||||
public void draw(float layer, Tile9 sprite, Box box) {
|
||||
@Deprecated
|
||||
public final void draw(float layer, Tile9 sprite, Box box) {
|
||||
draw(layer, sprite, box.x, box.y, box.w, box.h);
|
||||
}
|
||||
|
||||
public void draw(float layer, Tile9 sprite, float x, float y, float w, float h) {
|
||||
public final void draw(float layer, Tile9 sprite, TileBox box) {
|
||||
draw(layer, sprite, box.x, box.y, box.w, box.h);
|
||||
}
|
||||
|
||||
public final void draw(float layer, Tile9 sprite, float x, float y, float w, float h) {
|
||||
Vector2i screenPos = world2screen(x, y);
|
||||
Drawing.setLayer(layer + (((y + h) - minY) / (maxY - minY)));
|
||||
sprite.draw((int)(screenPos.x), (int)(screenPos.y), (int)(tileWidth * w), (int)(tileWidth * h));
|
||||
}
|
||||
|
||||
public void drawProgressBar(float progress, Vector4f worldBox) {
|
||||
public final void drawProgressBar(float progress, Box worldBox) {
|
||||
int h = 6;
|
||||
Vector4i box = world2screen(worldBox).toXYWH().asInt();
|
||||
Box box = world2screen(worldBox);
|
||||
Drawing.setLayer(Layers.GENERAL_UI);
|
||||
Assets.flat.pushColor(Color.black);
|
||||
Assets.uiFrame.draw(box.x - h, box.y + box.w / 2 - h / 2, box.z + h * 2, h);
|
||||
Assets.uiFrame.draw((int)(box.x - h), (int)(box.y + box.h / 2 - h / 2), (int)(box.w + h * 2), h);
|
||||
Assets.flat.swapColor(Color.yellow);
|
||||
Assets.fillColor.draw(box.x + 1 - h, box.y + 1 + box.w / 2 - h / 2, (int)Math.round(lerp(0, box.z - 3 + h * 2, progress)) + 1, h - 2);
|
||||
Assets.fillColor.draw((int)(box.x + 1 - h), (int)(box.y + 1 + box.h / 2 - h / 2), (int)Math.round(lerp(0, box.w - 3 + h * 2, progress)) + 1, h - 2);
|
||||
Assets.flat.popColor();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ import java.util.List;
|
|||
|
||||
import xyz.valnet.engine.App;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.TileBox;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
|
||||
import xyz.valnet.engine.scenegraph.ITransient;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IBuildLayerListener;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
|
|
@ -24,9 +25,9 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
|
||||
private IBuildLayerListener listener = null;
|
||||
|
||||
private BuildableMetadata.Type type = BuildableMetadata.Type.AREA;
|
||||
private BuildType type = BuildType.AREA;
|
||||
|
||||
public void setBuildType(BuildableMetadata.Type type) {
|
||||
public void setBuildType(BuildType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +39,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
@Override
|
||||
public void update(float dTime) {
|
||||
if(listener == null) return;
|
||||
if(type == BuildableMetadata.Type.SINGLE && mouseDown) return;
|
||||
if(type == BuildType.SINGLE && mouseDown) return;
|
||||
|
||||
broadcastWorldCoords();
|
||||
}
|
||||
|
|
@ -58,13 +59,16 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
}
|
||||
|
||||
private void broadcastWorldCoords() {
|
||||
Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt();
|
||||
Vector2i worldcoords = camera.getWorldMouse().asInt();
|
||||
if(mouseDown) {
|
||||
Vector2i[] ords = orderCoords(new Vector2i(x, y), worldcoords);
|
||||
listener.update(ords[0].x, ords[0].y, ords[2].x + 1, ords[2].y + 1);
|
||||
listener.update(TileBox.fromPoints(startingPoint, camera.getWorldMouse().asInt()));
|
||||
return;
|
||||
}
|
||||
listener.update(worldcoords.x, worldcoords.y, 1, 1);
|
||||
if(type == BuildType.SINGLE && dimensions != null) {
|
||||
listener.update(new TileBox(worldcoords, dimensions));
|
||||
} else {
|
||||
listener.update(new TileBox(worldcoords, Vector2i.one));
|
||||
}
|
||||
}
|
||||
|
||||
public void deactiveate() {
|
||||
|
|
@ -82,9 +86,15 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
hovered = false;
|
||||
}
|
||||
|
||||
private int x, y;
|
||||
private Vector2i startingPoint = null;
|
||||
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) {
|
||||
|
|
@ -92,12 +102,10 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
listener.cancel();
|
||||
} else if(button == 0 && active && hovered) {
|
||||
// TODO this conversion in negative numbers definitely works wrong.
|
||||
Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt();
|
||||
startingPoint = camera.getWorldMouse().asInt();
|
||||
mouseDown = true;
|
||||
x = worldcoords.x;
|
||||
y = worldcoords.y;
|
||||
if(type == BuildableMetadata.Type.SINGLE) {
|
||||
listener.build(x, y);
|
||||
if(type == BuildType.SINGLE) {
|
||||
listener.build(new TileBox(startingPoint, dimensions));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -106,29 +114,12 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
|||
public void mouseUp(int button) {
|
||||
if(button == 0 && active && mouseDown) {
|
||||
mouseDown = false;
|
||||
if(type == BuildableMetadata.Type.AREA) {
|
||||
Vector2i worldcoords = camera.screen2world(App.mouseX, App.mouseY).asInt();
|
||||
int x1 = x;
|
||||
int y1 = y;
|
||||
int x2 = worldcoords.x;
|
||||
int y2 = worldcoords.y;
|
||||
int minX = Math.min(x1, x2);
|
||||
int minY = Math.min(y1, y2);
|
||||
int maxX = Math.max(x1, x2);
|
||||
int maxY = Math.max(y1, y2);
|
||||
listener.build(minX, minY, maxX, maxY);
|
||||
if(type == BuildType.AREA) {
|
||||
listener.build(TileBox.fromPoints(camera.getWorldMouse().asInt(), startingPoint));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2i[] orderCoords(Vector2i a, Vector2i b) {
|
||||
return new Vector2i[] {
|
||||
new Vector2i(Math.min(a.x, b.x), Math.min(a.y, b.y)),
|
||||
new Vector2i(Math.max(a.x, b.x), Math.max(a.y, b.y)),
|
||||
new Vector2i(Math.max(a.x, b.x) - Math.min(a.x, b.x), Math.max(a.y, b.y) - Math.min(a.y, b.y))
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Box> getGuiBoxes() {
|
||||
return List.of(active ? new Box(0, 0, 1024, 576) : Box.none);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ import xyz.valnet.engine.App;
|
|||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2f;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.engine.scenegraph.IMouseCaptureArea;
|
||||
import xyz.valnet.engine.scenegraph.ITransient;
|
||||
|
|
@ -80,11 +78,8 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
|
|||
float p = lerp(animationAmplitude, 0, t);
|
||||
|
||||
for(ISelectable thing : selected) {
|
||||
Vector4f box = thing.getWorldBox();
|
||||
Vector2i min = camera.world2screen(box.x - p, box.y - p);
|
||||
Vector2i max = camera.world2screen(box.z + p, box.w + p);
|
||||
Drawing.setLayer(Layers.SELECTION_IDENTIFIERS);
|
||||
Assets.selectedFrame.draw((int)min.x, (int)min.y, (int)(max.x - min.x), (int)(max.y - min.y));
|
||||
Box box = thing.getWorldBox().outset(p);
|
||||
camera.draw(Layers.SELECTION_IDENTIFIERS, Assets.selectedFrame, box);
|
||||
thing.selectedRender();
|
||||
}
|
||||
|
||||
|
|
@ -96,37 +91,17 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
|
|||
}
|
||||
}
|
||||
|
||||
// this will take any x1, y1, x2, y2 vector and make x1 < x2 and y1 < y2;
|
||||
private Vector4f sortVector(Vector4f vector) {
|
||||
return new Vector4f(
|
||||
Math.min(vector.x, vector.z),
|
||||
Math.min(vector.y, vector.w),
|
||||
Math.max(vector.x, vector.z),
|
||||
Math.max(vector.y, vector.w)
|
||||
);
|
||||
}
|
||||
|
||||
private List<ISelectable> selected = new ArrayList<ISelectable>();
|
||||
|
||||
private void makeSelection(Vector4f a) {
|
||||
private void makeSelection(Box selectionBox) {
|
||||
List<ISelectable> newSelection = new ArrayList<ISelectable>();
|
||||
|
||||
Vector4f normalizedSelectionBoxScreen = sortVector(a);
|
||||
Vector2f selectionBoxWorldMin = new Vector2f(normalizedSelectionBoxScreen.x, normalizedSelectionBoxScreen.y);
|
||||
Vector2f selectionBoxWorldMax = new Vector2f(normalizedSelectionBoxScreen.z, normalizedSelectionBoxScreen.w);
|
||||
|
||||
List<ISelectable> selectables = getAll(ISelectable.class);
|
||||
|
||||
int prio = Integer.MIN_VALUE;
|
||||
|
||||
for(ISelectable thing : selectables) {
|
||||
Vector4f thingBox = thing.getWorldBox();
|
||||
if(rectanglesIntersect(
|
||||
selectionBoxWorldMin.x, selectionBoxWorldMin.y,
|
||||
selectionBoxWorldMax.x, selectionBoxWorldMax.y,
|
||||
thingBox.x, thingBox.y,
|
||||
thingBox.z, thingBox.w
|
||||
)) {
|
||||
Box thingBox = thing.getWorldBox();
|
||||
if(selectionBox.intersects(thingBox)) {
|
||||
int thingPrio = thing.getSelectPriority().toValue();
|
||||
if(thingPrio > prio) {
|
||||
newSelection.clear();
|
||||
|
|
@ -216,18 +191,7 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
|
|||
@Override
|
||||
public void mouseUp(int button) {
|
||||
if(initialCoords != null && button == 0) {
|
||||
|
||||
Vector2f worldMouse = camera.screen2world(App.mouseX, App.mouseY);
|
||||
|
||||
Vector4f worldBox = new Vector4f(
|
||||
initialCoords.x,
|
||||
initialCoords.y,
|
||||
worldMouse.x,
|
||||
worldMouse.y
|
||||
);
|
||||
|
||||
makeSelection(worldBox);
|
||||
|
||||
makeSelection(Box.fromPoints(initialCoords, camera.getWorldMouse()));
|
||||
initialCoords = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
package xyz.valnet.hadean.gameobjects.jobs;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -8,8 +8,8 @@ import java.util.Set;
|
|||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Stockpile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.zones.Stockpile;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
|
|
@ -120,11 +120,15 @@ public class Job extends GameObject {
|
|||
}
|
||||
|
||||
public Vector2i[] getLocations() {
|
||||
Stockpile pile = that.get(Stockpile.class);
|
||||
// Vector4f box = pile.getWorldBox().toXYWH();
|
||||
return new Vector2i[] {
|
||||
pile.getFreeTile()
|
||||
};
|
||||
List<Stockpile> stockpiles = that.getAll(Stockpile.class);
|
||||
for(Stockpile pile : stockpiles) {
|
||||
Vector2i tile = pile.getFreeTile();
|
||||
if(tile == null) continue;
|
||||
return new Vector2i[] {
|
||||
tile
|
||||
};
|
||||
}
|
||||
return new Vector2i[] {};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
package xyz.valnet.hadean.gameobjects.jobs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -13,7 +13,8 @@ import xyz.valnet.engine.graphics.Color;
|
|||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.pawn.Pawn;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.agents.pawn.Pawn;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
|
|
@ -27,8 +28,8 @@ public class JobBoard extends GameObject {
|
|||
private List<Job> toRemove = new ArrayList<Job>();
|
||||
private Map<Pawn, Job> allocations = new HashMap<Pawn, Job>();
|
||||
|
||||
public Job postSimpleWorkJob(String name, IWorkable subject) {
|
||||
Job job = add(new Job(name));
|
||||
public Job postSimpleWorkJob(IWorkable subject) {
|
||||
Job job = add(new Job(subject.getJobName()));
|
||||
job.addStep(job.new Work(subject));
|
||||
postJob(job);
|
||||
return job;
|
||||
|
|
@ -207,6 +208,7 @@ public class JobBoard extends GameObject {
|
|||
return str;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String details() {
|
||||
|
||||
String takenJobsString = "";
|
||||
|
|
@ -234,5 +236,4 @@ public class JobBoard extends GameObject {
|
|||
"Taken Jobs: " + allocations.size() + "\n" + takenJobsString +
|
||||
"Impossible Jobs: " + impossibleJobs + "\n" + impossibleJobsString;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package xyz.valnet.hadean.gameobjects.jobs;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
|
||||
public class SimpleWorkable implements IWorkable {
|
||||
|
||||
private final String name;
|
||||
private float work = 0;
|
||||
private float MAX_WORK = 0;
|
||||
private IProgressUpdateCallback callback;
|
||||
private IGetPositionsFunction positions;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IGetPositionsFunction extends Serializable {
|
||||
public Vector2i[] get();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IProgressUpdateCallback extends Serializable {
|
||||
public void progress(float progress);
|
||||
}
|
||||
|
||||
public SimpleWorkable(String name, float maxWork, IGetPositionsFunction positionsFunction, IProgressUpdateCallback callback) {
|
||||
this.name = name;
|
||||
this.MAX_WORK = maxWork;
|
||||
this.positions = positionsFunction;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork(float dTime) {
|
||||
work += dTime;
|
||||
callback.progress(work / MAX_WORK);
|
||||
return work >= MAX_WORK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getWorkablePositions() {
|
||||
return positions.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getJobName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package xyz.valnet.hadean.gameobjects.jobs;
|
||||
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.interfaces.IWorkshop;
|
||||
|
||||
public class WorkOrder extends GameObject {
|
||||
|
||||
private boolean recurring = false;
|
||||
private int count = 10;
|
||||
private String name = "Cut Stone Blocks";
|
||||
private IWorkshop shop = null;
|
||||
|
||||
public boolean getRecurring() {
|
||||
return recurring;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void increaseCount() {
|
||||
count ++;
|
||||
}
|
||||
|
||||
public void decreaseCount() {
|
||||
count --;
|
||||
}
|
||||
|
||||
public WorkOrder setShop(IWorkshop shop) {
|
||||
this.shop = shop;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean validForShop(IWorkshop shop) {
|
||||
return this.shop == null || this.shop == shop;
|
||||
}
|
||||
|
||||
public boolean isSpecificToShop(IWorkshop shop) {
|
||||
return this.shop != null && shop == this.shop;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package xyz.valnet.hadean.gameobjects.jobs;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.interfaces.IWorkshop;
|
||||
|
||||
public class WorkOrderManager extends GameObject {
|
||||
|
||||
private Set<WorkOrder> orders;
|
||||
|
||||
@Override
|
||||
protected void start() {
|
||||
super.start();
|
||||
this.onAddGameObject((obj) -> {
|
||||
if(obj instanceof WorkOrder) {
|
||||
orders.add((WorkOrder) obj);
|
||||
}
|
||||
});
|
||||
this.onRemoveGameObject((obj) -> {
|
||||
if(obj instanceof WorkOrder) {
|
||||
orders.remove((WorkOrder) obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void create() {
|
||||
super.create();
|
||||
orders = new HashSet<>();
|
||||
}
|
||||
|
||||
public Set<WorkOrder> getOrders(IWorkshop shop) {
|
||||
return orders.stream()
|
||||
.filter((order) -> order.validForShop(shop))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
package xyz.valnet.hadean.gameobjects.terrain;
|
||||
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.FastNoiseLite;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.interfaces.IWorldBoundsAdapter;
|
||||
import xyz.valnet.hadean.pathfinding.IPathable;
|
||||
|
||||
|
|
@ -42,6 +44,7 @@ public class Terrain extends GameObject implements IPathable, IWorldBoundsAdapte
|
|||
@Override
|
||||
protected void start() {
|
||||
camera.focus(WORLD_SIZE / 2, WORLD_SIZE / 2);
|
||||
camera.setFocusBounds(new Box(0, 0, WORLD_SIZE, WORLD_SIZE));
|
||||
}
|
||||
|
||||
public Tile getTile(int x, int y) {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
package xyz.valnet.hadean.gameobjects.terrain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -9,11 +9,12 @@ import xyz.valnet.engine.graphics.Color;
|
|||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4i;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.FarmPlot;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Tree;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.WorldObject;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Boulder;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.zones.FarmPlot;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.interfaces.IPingable;
|
||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
||||
|
|
@ -123,7 +124,7 @@ public class Tile extends WorldObject implements IWorkable {
|
|||
pingNeighbors();
|
||||
|
||||
if(thing instanceof FarmPlot) {
|
||||
get(JobBoard.class).postSimpleWorkJob("Till Soil", this);
|
||||
get(JobBoard.class).postSimpleWorkJob(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
package xyz.valnet.hadean.gameobjects.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -5,14 +5,13 @@ import java.util.List;
|
|||
|
||||
import xyz.valnet.engine.App;
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2f;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.engine.scenegraph.ITransient;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.WorldObject;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
|
@ -43,13 +42,8 @@ public class HoverQuery extends GameObject implements ITransient {
|
|||
Vector2f position = camera.screen2world(App.mouseX, App.mouseY);
|
||||
thingStrings.clear();
|
||||
for(WorldObject obj : getAll(WorldObject.class)) {
|
||||
Vector4f box = obj.getWorldBox();
|
||||
if(
|
||||
position.x >= box.x &&
|
||||
position.x < box.z &&
|
||||
position.y >= box.y &&
|
||||
position.y < box.w
|
||||
) {
|
||||
Box box = obj.getWorldBox();
|
||||
if(box.contains(position)) {
|
||||
thingStrings.add(obj.getName());
|
||||
if (!HadeanGame.debugView) continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
package xyz.valnet.hadean.gameobjects.ui;
|
||||
|
||||
import static xyz.valnet.engine.util.Math.*;
|
||||
|
||||
|
|
@ -13,7 +13,6 @@ import xyz.valnet.engine.graphics.ImmediateUI;
|
|||
import xyz.valnet.engine.scenegraph.ITransient;
|
||||
import xyz.valnet.hadean.Constants;
|
||||
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
|
||||
import xyz.valnet.hadean.gameobjects.ui.ExclusivityManager;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.interfaces.ISelectionChangeListener;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
|
|
@ -133,7 +132,7 @@ public class SelectionUI extends ImmediateUI implements ISelectionChangeListener
|
|||
if(details.length == 0) {
|
||||
text("No details available.");
|
||||
} else for(Detail detail : details) {
|
||||
text(detail.toString(15));
|
||||
text(detail.toString(30));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package xyz.valnet.hadean.gameobjects.ui;
|
||||
|
||||
import xyz.valnet.engine.graphics.LayoutStyle;
|
||||
import xyz.valnet.engine.graphics.ImmediateUI;
|
||||
import xyz.valnet.engine.scenegraph.ITransient;
|
||||
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.WorkOrder;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.WorkOrderManager;
|
||||
import xyz.valnet.hadean.interfaces.IWorkshop;
|
||||
|
||||
public class WorkshopOrdersUI extends ImmediateUI implements ITransient {
|
||||
|
||||
private IWorkshop shop;
|
||||
private SelectionLayer selectionLayer;
|
||||
private WorkOrderManager manager;
|
||||
|
||||
public void open(IWorkshop shop) {
|
||||
this.shop = shop;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.shop = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void gui() {
|
||||
if(shop == null) return;
|
||||
|
||||
window(0, 0, 200, 300, () -> {
|
||||
var all = manager.getOrders(shop);
|
||||
var specifics = all.stream()
|
||||
.filter(workorder -> workorder.isSpecificToShop(shop))
|
||||
.toList();
|
||||
|
||||
for(WorkOrder order : specifics) {
|
||||
group(() -> {
|
||||
text(order.getName());
|
||||
space(4);
|
||||
horizontal(() -> {
|
||||
if(button("--", LayoutStyle.sized(32, 16))) {
|
||||
order.decreaseCount();
|
||||
}
|
||||
space(4);
|
||||
if(button("-", LayoutStyle.sized(16, 16))) {
|
||||
order.decreaseCount();
|
||||
}
|
||||
space(4);
|
||||
vertical(() -> {
|
||||
// space(8);
|
||||
text("" + order.getCount());
|
||||
});
|
||||
space(4);
|
||||
if(button("+", LayoutStyle.sized(16, 16))) {
|
||||
order.increaseCount();
|
||||
}
|
||||
space(4);
|
||||
if(button("++", LayoutStyle.sized(32, 16))) {
|
||||
order.increaseCount();
|
||||
}
|
||||
});
|
||||
});
|
||||
space(8);
|
||||
}
|
||||
|
||||
text("" + (all.size() - specifics.size()) + " implicit general orders");
|
||||
space(8);
|
||||
|
||||
if(button("New Order")) {
|
||||
add(new WorkOrder().setShop(shop));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void connect() {
|
||||
super.connect();
|
||||
selectionLayer = get(SelectionLayer.class);
|
||||
manager = get(WorkOrderManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void start() {
|
||||
super.start();
|
||||
this.selectionLayer.subscribe((selection) -> {
|
||||
if(shop == null) {
|
||||
return;
|
||||
} else if(selection.size() != 1) {
|
||||
close();
|
||||
} else if(selection.get(0) instanceof IWorkshop) {
|
||||
shop = (IWorkshop) selection.get(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,20 +8,22 @@ import java.util.Map;
|
|||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.TileBox;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.designation.CutTreesDesignation;
|
||||
import xyz.valnet.hadean.designation.HaulItemDesignation;
|
||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.ui.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
|
||||
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.FarmPlot;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Stockpile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.zones.FarmPlot;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.zones.Stockpile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.constructions.Bed;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.constructions.MasonWorkshop;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.constructions.Quarry;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.constructions.Wall;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IBuildLayerListener;
|
||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
|
|
@ -35,8 +37,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
private BuildLayer buildLayer;
|
||||
private Camera camera;
|
||||
|
||||
private int x, y;
|
||||
private int w, h;
|
||||
private TileBox renderBox = null;
|
||||
|
||||
private String selectedCategory = null;
|
||||
|
||||
|
|
@ -55,21 +56,23 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
|
||||
BuildTab.registerBuildable(FarmPlot.class);
|
||||
BuildTab.registerBuildable(Stockpile.class);
|
||||
BuildTab.registerBuildable(MasonWorkshop.class);
|
||||
}
|
||||
|
||||
public record BuildableRecord(
|
||||
String name,
|
||||
Constructor<? extends IBuildable> constructor,
|
||||
BuildableMetadata.Type type
|
||||
BuildType type,
|
||||
Vector2i dimensions
|
||||
) {}
|
||||
|
||||
public static void registerBuildable(Class<? extends IBuildable> clazz) {
|
||||
try {
|
||||
BuildableMetadata annotation = clazz.getAnnotation(BuildableMetadata.class);
|
||||
if(annotation == null) {
|
||||
DebugTab.log(clazz + " has no buildable data annotation");
|
||||
return;
|
||||
}
|
||||
// BuildableMetadata annotation = clazz.getAnnotation(BuildableMetadata.class);
|
||||
// if(annotation == null) {
|
||||
// DebugTab.log(clazz + " has no buildable data annotation");
|
||||
// return;
|
||||
// }
|
||||
|
||||
Constructor<? extends IBuildable> constructor = (Constructor<? extends IBuildable>) clazz.getConstructor();
|
||||
if(constructor.getParameterCount() != 0) {
|
||||
|
|
@ -77,15 +80,18 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
return;
|
||||
}
|
||||
|
||||
String category = annotation.category();
|
||||
String name = annotation.name();
|
||||
BuildableMetadata.Type type = annotation.type();
|
||||
IBuildable buildable = constructor.newInstance();
|
||||
|
||||
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();
|
||||
|
|
@ -98,15 +104,19 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
|
||||
if(!opened || selectedBuildable == null) return;
|
||||
// draw the currently selected build item
|
||||
|
||||
Assets.flat.pushColor(Color.white);
|
||||
Vector2i topLeft = camera.world2screen(x, y);
|
||||
Vector2i topLeft = camera.world2screen(renderBox.topLeft);
|
||||
Assets.font.drawString(selectedBuildable.name, topLeft.x, topLeft.y - 20);
|
||||
|
||||
Assets.flat.swapColor(Color.white.withAlpha(0.6f));
|
||||
camera.draw(Layers.BUILD_INTERACTABLE, Assets.selectionFrame, x, y, w, h);
|
||||
camera.draw(Layers.BUILD_INTERACTABLE, Assets.selectionFrame, renderBox);
|
||||
|
||||
Assets.flat.swapColor(Color.white.withAlpha(0.35f));
|
||||
for(int i = 0; i < w; i ++) for(int j = 0; j < h; j ++) {{
|
||||
camera.draw(Layers.BUILD_INTERACTABLE, Assets.checkerBoard, x + i, y + j);
|
||||
for(int i = 0; i < renderBox.w; i ++) for(int j = 0; j < renderBox.h; j ++) {{
|
||||
camera.draw(Layers.BUILD_INTERACTABLE, Assets.checkerBoard, renderBox.x + i, renderBox.y + j);
|
||||
}}
|
||||
|
||||
Assets.flat.popColor();
|
||||
}
|
||||
|
||||
|
|
@ -144,42 +154,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
selectedBuildable = buildableRecord;
|
||||
buildLayer.activate(this);
|
||||
buildLayer.setBuildType(selectedBuildable.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int nx, int ny, int nw, int nh) {
|
||||
x = nx;
|
||||
y = ny;
|
||||
w = nw;
|
||||
h = nh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(int x1, int y1, int x2, int y2) {
|
||||
if(selectedBuildable == null) return;
|
||||
try {
|
||||
IBuildable building = selectedBuildable.constructor.newInstance();
|
||||
if(building instanceof GameObject) {
|
||||
add((GameObject) building);
|
||||
}
|
||||
building.buildAt(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
|
||||
} catch (Exception e) {
|
||||
DebugTab.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
} catch (Exception e) {
|
||||
DebugTab.log(e);
|
||||
}
|
||||
buildLayer.setDimensions(selectedBuildable.dimensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -259,4 +234,23 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IBuildLay
|
|||
protected void onOpen() {
|
||||
reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(TileBox box) {
|
||||
renderBox = box;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(TileBox box) {
|
||||
if(selectedBuildable == null) return;
|
||||
try {
|
||||
IBuildable building = selectedBuildable.constructor.newInstance();
|
||||
if(building instanceof GameObject) {
|
||||
add((GameObject) building);
|
||||
}
|
||||
building.buildAt(box);
|
||||
} catch (Exception e) {
|
||||
DebugTab.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import java.util.List;
|
|||
|
||||
import xyz.valnet.engine.scenegraph.IKeyboardListener;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.ui.BottomBar;
|
||||
|
||||
public class DebugTab extends Tab implements IKeyboardListener {
|
||||
|
||||
|
|
@ -44,6 +44,10 @@ public class DebugTab extends Tab implements IKeyboardListener {
|
|||
space(8);
|
||||
text(System.getProperty("java.version"));
|
||||
space(8);
|
||||
var fps = getFPS();
|
||||
text("FPS: " + fps.first());
|
||||
text("MEASURED FPS: " + fps.second());
|
||||
space(8);
|
||||
|
||||
long allocated = runtime.totalMemory();
|
||||
long max = runtime.maxMemory();
|
||||
|
|
@ -65,6 +69,7 @@ public class DebugTab extends Tab implements IKeyboardListener {
|
|||
while(logs.size() > 10) {
|
||||
logs.remove(0);
|
||||
}
|
||||
System.out.println(str);
|
||||
}
|
||||
|
||||
public static void log(Object obj) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package xyz.valnet.hadean.gameobjects.ui.tabs;
|
||||
|
||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.ui.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
|
||||
public class JobBoardTab extends Tab {
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ public class MenuTab extends Tab implements IPauser {
|
|||
|
||||
@Override
|
||||
protected void gui() {
|
||||
if(!shouldRender()) return;
|
||||
|
||||
window(1024 / 2 - width / 2, animate(-height - 50, 576 / 2 - height / 2), width, height, () -> {
|
||||
text(" === Paused ===");
|
||||
space(8);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import xyz.valnet.engine.graphics.IModalUI;
|
|||
import xyz.valnet.engine.graphics.ImmediateUI;
|
||||
import xyz.valnet.engine.scenegraph.ITransient;
|
||||
import xyz.valnet.hadean.Constants;
|
||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.ui.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.ui.ExclusivityManager;
|
||||
import xyz.valnet.hadean.interfaces.IBottomBarItem;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.engine.math.TileBox;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.interfaces.IBuildable;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
||||
|
|
@ -10,19 +10,9 @@ 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildAt(int x, int y) {
|
||||
Vector2i dim = getDimensions();
|
||||
setPosition(x, y, dim.x, dim.y);
|
||||
public void buildAt(TileBox box) {
|
||||
setPosition(box.asBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -30,7 +20,6 @@ public abstract class Buildable extends WorldObject implements IBuildable, ITile
|
|||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
// TODO Auto-generated method stub
|
||||
return new Action[] {};
|
||||
}
|
||||
|
||||
|
|
@ -43,4 +32,9 @@ public abstract class Buildable extends WorldObject implements IBuildable, ITile
|
|||
public Detail[] getDetails() {
|
||||
return new Detail[] {};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabName() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,61 +0,0 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
|
||||
public class Rice extends Item {
|
||||
|
||||
|
||||
public Rice(int x, int y) {
|
||||
setPosition(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Vector2i pos = getWorldPosition().xy();
|
||||
camera.draw(Layers.AIR, Assets.riceBag, pos.x, pos.y);
|
||||
|
||||
Assets.flat.pushColor(Color.black);
|
||||
Vector2i screeCoords = camera.world2screen(pos.x, pos.y);
|
||||
Assets.miniFont.drawString("123", (int)screeCoords.x, (int)screeCoords.y);
|
||||
Assets.flat.popColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalkable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRemove() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove() {}
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
return new Action[] {};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAction(Action action) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Detail[] getDetails() {
|
||||
return new Detail[] {};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Rice";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.hadean.gameobjects.Job;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Log;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
||||
|
|
@ -18,9 +18,6 @@ import xyz.valnet.hadean.util.detail.PercentDetail;
|
|||
|
||||
public class Tree extends WorldObject implements ITileThing, ISelectable, IWorkable {
|
||||
|
||||
private static int counter = 0;
|
||||
private String name = "Tree " + (++ counter);
|
||||
|
||||
private Job chopJob = null;
|
||||
|
||||
public Tree(int x, int y) {
|
||||
|
|
@ -35,7 +32,7 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
|
|||
// Assets.flat.popColor();
|
||||
if(chopJob != null) {
|
||||
if(getProgress() > 0) {
|
||||
camera.drawProgressBar(getProgress(), new Vector4f(pos.x - 1, pos.y - 2, pos.x + 2, pos.y + 1));
|
||||
camera.drawProgressBar(getProgress(), new Box(pos.x - 1, pos.y - 2, 3, 3));
|
||||
}
|
||||
camera.draw(Layers.MARKERS, Assets.lilAxe, pos.x, pos.y);
|
||||
}
|
||||
|
|
@ -59,7 +56,7 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
|
|||
public void runAction(Action action) {
|
||||
if(action == ACTION_CHOP) {
|
||||
if(chopJob == null) {
|
||||
chopJob = get(JobBoard.class).postSimpleWorkJob("Chop Tree", this);
|
||||
chopJob = get(JobBoard.class).postSimpleWorkJob(this);
|
||||
} else {
|
||||
chopJob.close();
|
||||
chopJob = null;
|
||||
|
|
@ -125,7 +122,7 @@ public class Tree extends WorldObject implements ITileThing, ISelectable, IWorka
|
|||
|
||||
@Override
|
||||
public String getJobName() {
|
||||
return "Chop " + name;
|
||||
return "Chop Tree";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -3,17 +3,18 @@ package xyz.valnet.hadean.gameobjects.worldobjects;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.math.Vector4i;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.interfaces.ITileThing;
|
||||
|
||||
public abstract class WorldObject extends GameObject {
|
||||
|
||||
// TODO make it just a box lawl
|
||||
private int x;
|
||||
private int y;
|
||||
private int w;
|
||||
|
|
@ -93,6 +94,10 @@ public abstract class WorldObject extends GameObject {
|
|||
setPosition(x, y, 1, 1);
|
||||
}
|
||||
|
||||
protected void setPosition(Box box) {
|
||||
setPosition((int) box.x, (int) box.y, (int) box.w, (int) box.h);
|
||||
}
|
||||
|
||||
protected void setPosition(int x, int y, int w, int h) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
|
@ -124,8 +129,8 @@ public abstract class WorldObject extends GameObject {
|
|||
|
||||
public abstract String getName();
|
||||
|
||||
public Vector4f getWorldBox() {
|
||||
return new Vector4f(x, y, x + w, y + h);
|
||||
public Box getWorldBox() {
|
||||
return new Box(x, y, w, h);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import xyz.valnet.engine.math.Vector2f;
|
|||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.shaders.SimpleShader;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.WorldObject;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.pathfinding.AStarPathfinder;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.pawn;
|
||||
package xyz.valnet.hadean.gameobjects.worldobjects.agents.pawn;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.pawn;
|
||||
package xyz.valnet.hadean.gameobjects.worldobjects.agents.pawn;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.Job;
|
||||
import xyz.valnet.hadean.gameobjects.Job.JobStep;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.Job.JobStep;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
|
||||
public class JobActivity extends Activity {
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.pawn;
|
||||
package xyz.valnet.hadean.gameobjects.worldobjects.agents.pawn;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.pawn;
|
||||
package xyz.valnet.hadean.gameobjects.worldobjects.agents.pawn;
|
||||
|
||||
import static xyz.valnet.hadean.util.detail.Detail.*;
|
||||
|
||||
|
|
@ -6,14 +6,14 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.engine.math.Vector2f;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.util.Names;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.Clock;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.agents.Agent;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
|
|
@ -154,9 +154,9 @@ public class Pawn extends Agent {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Vector4f getWorldBox() {
|
||||
public Box getWorldBox() {
|
||||
Vector2f pos = getCalculatedPosition();
|
||||
return new Vector4f(pos.x, pos.y, pos.x+1, pos.y+1);
|
||||
return new Box(pos, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.pawn;
|
||||
package xyz.valnet.hadean.gameobjects.worldobjects.agents.pawn;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.util.Math.WeightedAverage;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.pawn;
|
||||
package xyz.valnet.hadean.gameobjects.worldobjects.agents.pawn;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
|
||||
// TODO actually implement this activity.
|
||||
public class WanderActivity extends Activity {
|
||||
|
|
@ -1,143 +1,23 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.graphics.Sprite;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.Job;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Log;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.detail.BooleanDetail;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
import xyz.valnet.hadean.util.detail.ObjectDetail;
|
||||
import xyz.valnet.hadean.util.detail.PercentDetail;
|
||||
|
||||
@BuildableMetadata(category = "Furniture", name = "Bed", type = BuildableMetadata.Type.SINGLE)
|
||||
public class Bed extends Buildable implements IItemReceiver, IWorkable {
|
||||
|
||||
private int logs = 0;
|
||||
private float work = 0;
|
||||
private final float maxWork = 500;
|
||||
|
||||
private Job job = null;
|
||||
public class Bed extends Construction {
|
||||
|
||||
@Override
|
||||
protected Vector2i getDimensions() {
|
||||
public Vector2i getDimensions() {
|
||||
return new Vector2i(1, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void create() {
|
||||
super.create();
|
||||
job = add(new Job("Build Bed"));
|
||||
job.addStep(job.new PickupItemByPredicate(Log.LOG_PREDICATE));
|
||||
job.addStep(job.new DropoffPredicateAtItemReceiver(this, Log.LOG_PREDICATE));
|
||||
job.addStep(job.new Work(this));
|
||||
get(JobBoard.class).postJob(job);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
super.render();
|
||||
Vector2i pos = getWorldPosition().xy();
|
||||
|
||||
if(isBuilt()) {
|
||||
camera.draw(Layers.GROUND, Assets.bed, pos.x, pos.y, 1, 2);
|
||||
} else {
|
||||
float p = work / maxWork;
|
||||
float b = 4;
|
||||
|
||||
Assets.flat.pushColor(Color.grey(b).withAlpha(0.5f));
|
||||
camera.draw(Layers.GROUND, Assets.bed, pos.x, pos.y, 1, 2);
|
||||
Assets.flat.popColor();
|
||||
|
||||
if(logs > 0) {
|
||||
camera.drawProgressBar(p, getWorldBox());
|
||||
}
|
||||
// Assets.uiFrame.draw(box.x -3, box.y - 6, (int)Math.round(lerp(0, box.z + 6, p)), 4);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Bed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean receive(Item item) {
|
||||
if(item == null) return false;
|
||||
if(!item.matches(Log.LOG_PREDICATE)) return false;
|
||||
remove(item);
|
||||
logs ++;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isBuilt() {
|
||||
return work >= maxWork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork(float dTime) {
|
||||
work += dTime;
|
||||
return isBuilt();
|
||||
}
|
||||
|
||||
private Vector2i[] getBorders() {
|
||||
Vector2i pos = getWorldPosition().xy();
|
||||
return new Vector2i[] {
|
||||
new Vector2i(pos.x, pos.y - 1),
|
||||
|
||||
new Vector2i(pos.x - 1, pos.y),
|
||||
new Vector2i(pos.x + 1, pos.y),
|
||||
|
||||
new Vector2i(pos.x - 1, pos.y + 1),
|
||||
new Vector2i(pos.x + 1, pos.y + 1),
|
||||
|
||||
new Vector2i(pos.x, pos.y + 2),
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getWorkablePositions() {
|
||||
return getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJobName() {
|
||||
return "Build Bed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getItemDropoffLocations() {
|
||||
return getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
return new Action[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAction(Action action) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Detail[] getDetails() {
|
||||
return new Detail[] {
|
||||
new BooleanDetail("Built", isBuilt()),
|
||||
new PercentDetail("Work", work / maxWork, 1),
|
||||
new ObjectDetail<Integer>("Logs", logs),
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalkable() {
|
||||
return false;
|
||||
|
|
@ -152,4 +32,19 @@ public class Bed extends Buildable implements IItemReceiver, IWorkable {
|
|||
public void onRemove() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IItemPredicate getBuildingMaterial() {
|
||||
return Log.LOG_PREDICATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBuildingMaterialCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sprite getDefaultSprite() {
|
||||
return Assets.bed;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,20 @@ package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.graphics.Sprite;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.Job;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Boulder;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
|
||||
public abstract class Construction extends Buildable implements IItemReceiver {
|
||||
|
||||
|
|
@ -21,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();
|
||||
|
|
@ -43,17 +45,16 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
}
|
||||
if(!isBuilt()) {
|
||||
Job job = get(JobBoard.class).postSimpleWorkJob(
|
||||
"Build " + getName(),
|
||||
new IWorkable() {
|
||||
@Override
|
||||
public boolean doWork(float dTime) {
|
||||
work += dTime;
|
||||
return isBuilt();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vector2i[] getWorkablePositions() {
|
||||
return getWorldBox().toXYWH().asInt().getBorders();
|
||||
return getWorldBox().getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -73,7 +74,7 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
return 1000;
|
||||
}
|
||||
|
||||
public boolean isBuilt() {
|
||||
public final boolean isBuilt() {
|
||||
return work >= getMaxWork();
|
||||
}
|
||||
|
||||
|
|
@ -108,16 +109,57 @@ public abstract class Construction extends Buildable implements IItemReceiver {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean receive(Item item) {
|
||||
public final boolean receive(Item item) {
|
||||
if(item == null) return false;
|
||||
if(!item.matches(Boulder.BOULDER_PREDICATE)) return false;
|
||||
if(!item.matches(getBuildingMaterial())) return false;
|
||||
remove(item);
|
||||
// boulders ++;
|
||||
containedItems.add(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getItemDropoffLocations() {
|
||||
return getWorldBox().toXYWH().asInt().getBorders();
|
||||
return getWorldBox().getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Sprite sprite = getDefaultSprite();
|
||||
if(isBuilt()) {
|
||||
camera.draw(Layers.TILES, sprite, getWorldPosition());
|
||||
} else {
|
||||
float b = 4;
|
||||
|
||||
Assets.flat.pushColor(Color.grey(b).withAlpha(0.5f));
|
||||
camera.draw(Layers.GROUND, getDefaultSprite(), getWorldPosition());
|
||||
Assets.flat.popColor();
|
||||
|
||||
if(getBuildProgress() > 0) {
|
||||
camera.drawProgressBar(getBuildProgress(), getWorldBox());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Sprite getDefaultSprite();
|
||||
|
||||
@Override
|
||||
public BuildType getBuildType() {
|
||||
return BuildType.SINGLE;
|
||||
}
|
||||
@Override
|
||||
public String getBuildTabCategory() {
|
||||
return "Buildings";
|
||||
}
|
||||
@Override
|
||||
public String getBuildTabName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
return new Action[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAction(Action action) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
|
||||
|
||||
import xyz.valnet.engine.graphics.Sprite;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.ui.WorkshopOrdersUI;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Log;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.interfaces.IWorkshop;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
||||
public class MasonWorkshop extends Construction implements IWorkshop {
|
||||
|
||||
private static Action OPEN_ORDERS = new Action("Orders");
|
||||
private transient WorkshopOrdersUI ordersWindow;
|
||||
|
||||
@Override
|
||||
protected IItemPredicate getBuildingMaterial() {
|
||||
return Log.LOG_PREDICATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBuildingMaterialCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalkable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Mason's Workshop";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sprite getDefaultSprite() {
|
||||
return Assets.testTile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i getDimensions() {
|
||||
return new Vector2i(3, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
if(isBuilt()) {
|
||||
return new Action[] { OPEN_ORDERS };
|
||||
} else return new Action[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAction(Action action) {
|
||||
if(action == OPEN_ORDERS) {
|
||||
ordersWindow.open(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void connect() {
|
||||
super.connect();
|
||||
ordersWindow = get(WorkshopOrdersUI.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabName() {
|
||||
return "Mason";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabCategory() {
|
||||
return "Workshops";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +1,18 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.graphics.Sprite;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.Job;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.SimpleWorkable;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Boulder;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
|
||||
@BuildableMetadata(category = "Buildings", name = "Quarry", type = BuildableMetadata.Type.SINGLE)
|
||||
public class Quarry extends Construction {
|
||||
|
||||
private Job digJob = null;
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
if(isBuilt()) {
|
||||
camera.draw(Layers.TILES, Assets.quarry, getWorldPosition());
|
||||
|
||||
if(digJob != null && !digJob.isCompleted()) {
|
||||
camera.drawProgressBar(digProgress, getWorldBox());
|
||||
}
|
||||
|
||||
} else {
|
||||
float b = 4;
|
||||
|
||||
Assets.flat.pushColor(Color.grey(b).withAlpha(0.5f));
|
||||
camera.draw(Layers.GROUND, Assets.quarry, getWorldPosition());
|
||||
Assets.flat.popColor();
|
||||
|
||||
camera.drawProgressBar(getBuildProgress(), getWorldBox());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i getDimensions() {
|
||||
return new Vector2i(3, 3);
|
||||
|
|
@ -48,32 +25,14 @@ public class Quarry extends Construction {
|
|||
if (digJob != null) return;
|
||||
if (terrain.getTile(getWorldPosition().xy().south().east()).has(Boulder.class)) return;
|
||||
|
||||
digJob = get(JobBoard.class)
|
||||
.postSimpleWorkJob("Mine at Quarry", new IWorkable() {
|
||||
digJob = get(JobBoard.class).postSimpleWorkJob(new SimpleWorkable("Mine at Quarry", 5000, () -> {
|
||||
return new Vector2i[] {
|
||||
getWorldPosition().xy().south().east()
|
||||
};
|
||||
}, (progress) -> {
|
||||
digProgress = progress;
|
||||
}));
|
||||
|
||||
private static float MAX_WORK = 5000;
|
||||
private float work = 0;
|
||||
|
||||
@Override
|
||||
public boolean doWork(float dTime) {
|
||||
work += dTime;
|
||||
digProgress = work / MAX_WORK;
|
||||
return work >= MAX_WORK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getWorkablePositions() {
|
||||
return new Vector2i[] {
|
||||
getWorldPosition().xy().south().east()
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJobName() {
|
||||
return "Mine at Quarry";
|
||||
}
|
||||
|
||||
});
|
||||
digJob.registerClosedListener(() -> {
|
||||
digProgress = 0;
|
||||
Vector2i dropPos = getWorldPosition().xy().south().east();
|
||||
|
|
@ -118,4 +77,19 @@ public class Quarry extends Construction {
|
|||
protected int getBuildingMaterialCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Sprite getDefaultSprite() {
|
||||
return Assets.quarry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
super.render();
|
||||
if(!isBuilt()) return;
|
||||
|
||||
if(digJob != null && !digJob.isCompleted() && digProgress > 0) {
|
||||
camera.drawProgressBar(digProgress, getWorldBox());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,48 +2,18 @@ package xyz.valnet.hadean.gameobjects.worldobjects.constructions;
|
|||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.graphics.Sprite;
|
||||
import xyz.valnet.engine.graphics.Tile16.Direction;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.gameobjects.Job;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Boulder;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.items.Item;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.interfaces.IItemReceiver;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.interfaces.IPingable;
|
||||
import xyz.valnet.hadean.interfaces.IWorkable;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.detail.BooleanDetail;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
import xyz.valnet.hadean.util.detail.ObjectDetail;
|
||||
import xyz.valnet.hadean.util.detail.PercentDetail;
|
||||
|
||||
@BuildableMetadata(category = "Structure", name = "Wall", type = BuildableMetadata.Type.SINGLE)
|
||||
public class Wall extends Buildable implements IItemReceiver, IWorkable, IPingable {
|
||||
|
||||
private int boulders = 0;
|
||||
private float work = 0;
|
||||
private final float maxWork = 500;
|
||||
|
||||
private Job job = null;
|
||||
|
||||
@Override
|
||||
protected void create() {
|
||||
super.create();
|
||||
job = add(new Job("Build Wall"));
|
||||
if(!HadeanGame.debugView) {
|
||||
job.addStep(job.new PickupItemByPredicate(Boulder.BOULDER_PREDICATE));
|
||||
job.addStep(job.new DropoffPredicateAtItemReceiver(this, Boulder.BOULDER_PREDICATE));
|
||||
}
|
||||
job.addStep(job.new Work(this));
|
||||
get(JobBoard.class).postJob(job);
|
||||
}
|
||||
public class Wall extends Construction implements IPingable {
|
||||
|
||||
@Override
|
||||
protected void start() {
|
||||
|
|
@ -51,79 +21,11 @@ public class Wall extends Buildable implements IItemReceiver, IWorkable, IPingab
|
|||
ping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
super.render();
|
||||
Vector2i pos = getWorldPosition().xy();
|
||||
|
||||
if(isBuilt()) {
|
||||
float b = 0.7f;
|
||||
Assets.flat.pushColor(Color.grey(b));
|
||||
camera.draw(Layers.GROUND, Assets.wall.getTextureFor(wallSides), pos.x, pos.y);
|
||||
Assets.flat.popColor();
|
||||
} else {
|
||||
float p = work / maxWork;
|
||||
float b = 4;
|
||||
|
||||
Assets.flat.pushColor(Color.grey(b).withAlpha(0.5f));
|
||||
camera.draw(Layers.GROUND, Assets.wall.getTextureFor(wallSides), pos.x, pos.y);
|
||||
Assets.flat.popColor();
|
||||
|
||||
if(boulders > 0) {
|
||||
camera.drawProgressBar(p, getWorldBox());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Wall";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean receive(Item item) {
|
||||
if(item == null) return false;
|
||||
if(!item.matches(Boulder.BOULDER_PREDICATE)) return false;
|
||||
remove(item);
|
||||
boulders ++;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isBuilt() {
|
||||
return work >= maxWork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork(float dTime) {
|
||||
work += dTime;
|
||||
return isBuilt();
|
||||
}
|
||||
|
||||
private Vector2i[] getBorders() {
|
||||
Vector2i pos = getWorldPosition().xy();
|
||||
return new Vector2i[] {
|
||||
pos.north(),
|
||||
pos.east(),
|
||||
pos.south(),
|
||||
pos.west()
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getWorkablePositions() {
|
||||
return getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJobName() {
|
||||
return "Build Wall";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i[] getItemDropoffLocations() {
|
||||
return getBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
return new Action[0];
|
||||
|
|
@ -134,19 +36,6 @@ public class Wall extends Buildable implements IItemReceiver, IWorkable, IPingab
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Detail[] getDetails() {
|
||||
return new Detail[] {
|
||||
new BooleanDetail("Built", isBuilt()),
|
||||
new PercentDetail("Work", work / maxWork, 1),
|
||||
new ObjectDetail<Integer>("Logs", boulders),
|
||||
new BooleanDetail("North", wallSides.contains(Direction.NORTH)),
|
||||
new BooleanDetail("East", wallSides.contains(Direction.EAST)),
|
||||
new BooleanDetail("South", wallSides.contains(Direction.SOUTH)),
|
||||
new BooleanDetail("West", wallSides.contains(Direction.WEST)),
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalkable() {
|
||||
return !isBuilt();
|
||||
|
|
@ -166,7 +55,7 @@ public class Wall extends Buildable implements IItemReceiver, IWorkable, IPingab
|
|||
|
||||
@Override
|
||||
public void ping() {
|
||||
Vector2i pos = getWorldBox().asInt().xy();
|
||||
Vector2i pos = getWorldBox().a.asInt();
|
||||
wallSides = EnumSet.noneOf(Direction.class);
|
||||
|
||||
Tile north = terrain.getTile(pos.x, pos.y - 1);
|
||||
|
|
@ -181,4 +70,34 @@ public class Wall extends Buildable implements IItemReceiver, IWorkable, IPingab
|
|||
Tile west = terrain.getTile(pos.x + 1, pos.y);
|
||||
if(west != null && west.has(Wall.class)) wallSides.add(Direction.WEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBuildTabCategory() {
|
||||
return "Structure";
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildType getBuildType() {
|
||||
return BuildType.LINE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IItemPredicate getBuildingMaterial() {
|
||||
return Boulder.BOULDER_PREDICATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBuildingMaterialCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sprite getDefaultSprite() {
|
||||
return Assets.wall.getTextureFor(EnumSet.noneOf(Direction.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMaxWork() {
|
||||
return super.getMaxWork();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ package xyz.valnet.hadean.gameobjects.worldobjects.items;
|
|||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4i;
|
||||
import xyz.valnet.hadean.gameobjects.Job;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.Job;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.WorldObject;
|
||||
import xyz.valnet.hadean.interfaces.IItemPredicate;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
package xyz.valnet.hadean.gameobjects.worldobjects.zones;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.math.Vector4i;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
|
||||
@BuildableMetadata(category = "Zones", name = "Farm Plot")
|
||||
public class FarmPlot extends Buildable {
|
||||
public class FarmPlot extends Zone {
|
||||
|
||||
@Override
|
||||
public void renderAlpha() {
|
||||
if(!visible) return;
|
||||
Vector4i pos = getWorldPosition();
|
||||
Assets.flat.pushColor(new Color(0.4f, 1f, 0.3f, 0.2f));
|
||||
camera.draw(Layers.GROUND, Assets.whiteBox, pos.x, pos.y, pos.z, pos.w);
|
||||
camera.draw(Layers.TILES, Assets.whiteBox, pos.x, pos.y, pos.z, pos.w);
|
||||
Assets.flat.popColor();
|
||||
}
|
||||
|
||||
|
|
@ -65,4 +64,8 @@ public class FarmPlot extends Buildable {
|
|||
@Override
|
||||
public void onPlaced(Tile tile) {}
|
||||
|
||||
@Override
|
||||
public ISelectable.Priority getSelectPriority() {
|
||||
return ISelectable.Priority.LOW;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,18 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects;
|
||||
package xyz.valnet.hadean.gameobjects.worldobjects.zones;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import xyz.valnet.engine.graphics.Color;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.engine.math.Vector4i;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.interfaces.BuildableMetadata;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
import xyz.valnet.hadean.interfaces.ISelectable;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
import xyz.valnet.hadean.util.Layers;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
|
||||
@BuildableMetadata(category = "Zones", name = "Stockpile")
|
||||
public class Stockpile extends Buildable {
|
||||
public class Stockpile extends Zone {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.zones;
|
||||
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.Buildable;
|
||||
import xyz.valnet.hadean.interfaces.BuildType;
|
||||
|
||||
public abstract class Zone extends Buildable {
|
||||
|
||||
@Override
|
||||
public String getBuildTabCategory() {
|
||||
return "Zones";
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildType getBuildType() {
|
||||
return BuildType.AREA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalkable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
public enum BuildType {
|
||||
AREA,
|
||||
LINE,
|
||||
SINGLE
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface BuildableMetadata {
|
||||
|
||||
public enum Type {
|
||||
AREA,
|
||||
LINE,
|
||||
SINGLE
|
||||
}
|
||||
|
||||
public String name();
|
||||
public String category();
|
||||
public Type type() default Type.AREA;
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import xyz.valnet.engine.math.TileBox;
|
||||
|
||||
public interface IBuildLayerListener {
|
||||
public void update(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 update(TileBox box);
|
||||
public void build(TileBox box);
|
||||
|
||||
public void cancel();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,18 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import xyz.valnet.engine.math.TileBox;
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
|
||||
public interface IBuildable {
|
||||
|
||||
public void buildAt(int x, int y, int w, int h);
|
||||
public void buildAt(int x, int y);
|
||||
public void buildAt(TileBox box);
|
||||
|
||||
public String getBuildTabCategory();
|
||||
public BuildType getBuildType();
|
||||
public String getBuildTabName();
|
||||
|
||||
public default Vector2i getDimensions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.math.Box;
|
||||
import xyz.valnet.hadean.util.Action;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ public interface ISelectable {
|
|||
}
|
||||
}
|
||||
|
||||
public Vector4f getWorldBox();
|
||||
public Box getWorldBox();
|
||||
public Action[] getActions();
|
||||
public void runAction(Action action);
|
||||
public Detail[] getDetails();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Tile;
|
||||
|
||||
public interface ITileThing {
|
||||
public boolean isWalkable();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
package xyz.valnet.hadean.interfaces;
|
||||
|
||||
public interface IWorkshop extends ISelectable {
|
||||
|
||||
}
|
||||
|
|
@ -2,12 +2,14 @@ package xyz.valnet.hadean.scenes;
|
|||
|
||||
import xyz.valnet.engine.scenegraph.SceneGraph;
|
||||
import xyz.valnet.engine.util.Names;
|
||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.ui.BottomBar;
|
||||
import xyz.valnet.hadean.gameobjects.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.Clock;
|
||||
import xyz.valnet.hadean.gameobjects.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.SelectionUI;
|
||||
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.JobBoard;
|
||||
import xyz.valnet.hadean.gameobjects.jobs.WorkOrderManager;
|
||||
import xyz.valnet.hadean.gameobjects.ui.SelectionUI;
|
||||
import xyz.valnet.hadean.gameobjects.ui.WorkshopOrdersUI;
|
||||
import xyz.valnet.hadean.gameobjects.terrain.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
|
||||
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
|
||||
import xyz.valnet.hadean.gameobjects.ui.ExclusivityManager;
|
||||
|
|
@ -16,7 +18,7 @@ import xyz.valnet.hadean.gameobjects.ui.tabs.BuildTab;
|
|||
import xyz.valnet.hadean.gameobjects.ui.tabs.DebugTab;
|
||||
import xyz.valnet.hadean.gameobjects.ui.tabs.JobBoardTab;
|
||||
import xyz.valnet.hadean.gameobjects.ui.tabs.MenuTab;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.pawn.Pawn;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.agents.pawn.Pawn;
|
||||
|
||||
// TODO BIG IDEAS
|
||||
// have caches of types that ill need (Like IMouseListener)
|
||||
|
|
@ -43,16 +45,18 @@ public class GameScene extends SceneGraph {
|
|||
objects.add(new Pawn());
|
||||
}
|
||||
|
||||
objects.add(new SelectionLayer());
|
||||
objects.add(new SelectionUI());
|
||||
objects.add(new WorkOrderManager());
|
||||
objects.add(new ExclusivityManager());
|
||||
|
||||
objects.add(new SelectionLayer());
|
||||
objects.add(new BuildLayer());
|
||||
|
||||
objects.add(new WorkshopOrdersUI());
|
||||
objects.add(new SelectionUI());
|
||||
|
||||
objects.add(new HoverQuery());
|
||||
|
||||
objects.add(new BottomBar());
|
||||
objects.add(new ExclusivityManager());
|
||||
objects.add(new BuildTab());
|
||||
objects.add(new JobBoardTab());
|
||||
objects.add(new DebugTab());
|
||||
|
|
|
|||
|
|
@ -6,4 +6,35 @@ public class Action {
|
|||
public Action(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static Action[] mergeActions(Action[] a, Action[] b) {
|
||||
Action[] c = new Action[a.length + b.length];
|
||||
System.arraycopy(a, 0, c, 0, a.length);
|
||||
System.arraycopy(b, 0, c, a.length, b.length);
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Action[] mergeActions(Action[] a, Action[] b, Action[] c) {
|
||||
Action[] d = new Action[a.length + b.length + c.length];
|
||||
System.arraycopy(a, 0, d, 0, a.length);
|
||||
System.arraycopy(b, 0, d, a.length, b.length);
|
||||
System.arraycopy(c, 0, d, a.length + b.length, c.length);
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Action[] mergeActions(Action[] ... args) {
|
||||
if(args.length == 1) return new Action[0];
|
||||
if(args.length == 1) return args[0];
|
||||
if(args.length == 2) return mergeActions(args[0], args[1]);
|
||||
if(args.length == 3) return mergeActions(args[0], args[1], args[2]);
|
||||
|
||||
Action[][] merge = new Action[3][];
|
||||
Action[][] rest = new Action[args.length - 3][];
|
||||
System.arraycopy(args, 0, merge, 0, 3);
|
||||
System.arraycopy(args, 3, rest, 0, rest.length);
|
||||
|
||||
Action[] first = mergeActions(merge);
|
||||
Action[] merged = mergeActions(rest);
|
||||
return mergeActions(first, merged);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public class Assets {
|
|||
egg = new Sprite(atlas, 8, 104, 8, 8);
|
||||
bigRock = new Sprite(atlas, 16, 104, 8, 8);
|
||||
lilPickaxe = new Sprite(atlas, 8, 120, 16, 16);
|
||||
testTile = new Sprite(atlas, 16, 16, 64, 112);
|
||||
testTile = new Sprite(atlas, 64, 112, 16, 16);
|
||||
quarry = new Sprite(atlas, 88, 64, 24, 24);
|
||||
|
||||
Map<Character, Sprite> charset = new HashMap<Character, Sprite>();
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
package xyz.valnet.hadean.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SmartBoolean implements Serializable {
|
||||
private boolean value;
|
||||
|
||||
public interface IListener extends Serializable {
|
||||
public default void rise() {}
|
||||
public default void fall() {}
|
||||
public default void changed() {}
|
||||
}
|
||||
|
||||
private IListener isbl;
|
||||
|
||||
public SmartBoolean(boolean v, IListener isbl) {
|
||||
value = v;
|
||||
this.isbl = isbl;
|
||||
}
|
||||
|
||||
public void set(boolean b) {
|
||||
if(value != b) {
|
||||
value = b;
|
||||
isbl.changed();
|
||||
if(b) {
|
||||
isbl.rise();
|
||||
} else {
|
||||
isbl.fall();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
set(!value);
|
||||
}
|
||||
|
||||
public boolean value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue