saving and loading
parent
8d3535da55
commit
54da15ef59
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"configurations": [
|
|
||||||
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -10,6 +10,7 @@ public class GameObject implements IRenderable, ITickable, Serializable {
|
||||||
|
|
||||||
public void link(SceneGraph scene) {
|
public void link(SceneGraph scene) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
|
this.ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean inScene() {
|
public boolean inScene() {
|
||||||
|
|
@ -45,6 +46,10 @@ public class GameObject implements IRenderable, ITickable, Serializable {
|
||||||
@Override
|
@Override
|
||||||
public void update(float dTime) {}
|
public void update(float dTime) {}
|
||||||
|
|
||||||
|
// call order goes from top to bottom \/\/\/
|
||||||
|
// ready is called before scene linkage, and serves to initialize
|
||||||
|
// values that may be needed before incoming requests.
|
||||||
|
protected void ready() {}
|
||||||
// connect is solely for ensuring links to other objects. get() and getAll()
|
// connect is solely for ensuring links to other objects. get() and getAll()
|
||||||
protected void connect() {}
|
protected void connect() {}
|
||||||
// create is guaranteed to only run once for an object, even after save/load
|
// create is guaranteed to only run once for an object, even after save/load
|
||||||
|
|
|
||||||
|
|
@ -206,8 +206,9 @@ public abstract class SceneGraph implements IScene {
|
||||||
|
|
||||||
objects.addAll(newObjects);
|
objects.addAll(newObjects);
|
||||||
|
|
||||||
for(GameObject obj : objects) obj.link(this);
|
for(GameObject obj : newObjects) obj.link(this);
|
||||||
for(GameObject obj : objects) obj.addedToScene();
|
for(GameObject obj : newObjects) obj.addedToScene();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,6 @@ public class Clock extends GameObject {
|
||||||
|
|
||||||
private float time = 12;
|
private float time = 12;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float dTime) {
|
public void update(float dTime) {
|
||||||
time += 0.0004f;
|
time += 0.0004f;
|
||||||
|
|
|
||||||
|
|
@ -24,20 +24,23 @@ public class Terrain extends GameObject implements IPathable, IWorldBoundsAdapte
|
||||||
|
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
|
|
||||||
public void start() {
|
@Override
|
||||||
|
protected void create() {
|
||||||
for (int i = 0; i < WORLD_SIZE; i++) {
|
for (int i = 0; i < WORLD_SIZE; i++) {
|
||||||
for (int j = 0; j < WORLD_SIZE; j++) {
|
for (int j = 0; j < WORLD_SIZE; j++) {
|
||||||
tiles[i][j] = new Tile(i, j);
|
tiles[i][j] = new Tile(i, j);
|
||||||
add(tiles[i][j]);
|
add(tiles[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tile randomTile = getRandomTile();
|
@Override
|
||||||
// Vector2i coords = randomTile.getCoords();
|
protected void connect() {
|
||||||
// Stockpile stockpile = new Stockpile(coords.x, coords.y);
|
|
||||||
// randomTile.placeThing(stockpile);
|
|
||||||
|
|
||||||
camera = get(Camera.class);
|
camera = get(Camera.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start() {
|
||||||
camera.focus(WORLD_SIZE / 2, WORLD_SIZE / 2);
|
camera.focus(WORLD_SIZE / 2, WORLD_SIZE / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,6 @@ public class Tile extends WorldObject implements IWorkable {
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
super.start();
|
super.start();
|
||||||
// if(Math.random() > 0.97) {
|
|
||||||
// Tree tree = new Tree((int)x, (int)y);
|
|
||||||
// stuff.add(tree);
|
|
||||||
// add(tree);
|
|
||||||
// }
|
|
||||||
|
|
||||||
float scale = 1;
|
float scale = 1;
|
||||||
|
|
||||||
|
|
@ -58,7 +53,15 @@ public class Tile extends WorldObject implements IWorkable {
|
||||||
float blue = (float) terrain.getNoise(blueSeed, x * scale, y * scale);
|
float blue = (float) terrain.getNoise(blueSeed, x * scale, y * scale);
|
||||||
|
|
||||||
if(color == null) color = new Vector4f(red * 0.1f, 0.4f + green * 0.15f, blue * 0.05f, 1f);
|
if(color == null) color = new Vector4f(red * 0.1f, 0.4f + green * 0.15f, blue * 0.05f, 1f);
|
||||||
// color = new Vector4f(red, green, blue, 1.0f);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void create() {
|
||||||
|
if(Math.random() > 0.97) {
|
||||||
|
Tree tree = new Tree((int)x, (int)y);
|
||||||
|
stuff.add(tree);
|
||||||
|
add(tree);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTileFree() {
|
public boolean isTileFree() {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
|
||||||
private IBuildLayerListener listener = null;
|
private IBuildLayerListener listener = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
protected void connect() {
|
||||||
camera = get(Camera.class);
|
camera = get(Camera.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ public class HoverQuery extends GameObject implements ITransient {
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
protected void connect() {
|
||||||
super.start();
|
super.connect();
|
||||||
camera = get(Camera.class);
|
camera = get(Camera.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,13 @@ import xyz.valnet.hadean.interfaces.ISelectable;
|
||||||
import xyz.valnet.hadean.interfaces.ISelectionChangeListener;
|
import xyz.valnet.hadean.interfaces.ISelectionChangeListener;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
import xyz.valnet.hadean.util.Assets;
|
||||||
import xyz.valnet.hadean.util.Layers;
|
import xyz.valnet.hadean.util.Layers;
|
||||||
import xyz.valnet.hadean.util.SmartBoolean;
|
|
||||||
|
|
||||||
public class JobBoardTab extends Tab implements ISelectionChangeListener {
|
public class JobBoardTab extends Tab implements ISelectionChangeListener {
|
||||||
|
|
||||||
private SelectionLayer selection;
|
private SelectionLayer selection;
|
||||||
private JobBoard jobBoard;
|
private JobBoard jobBoard;
|
||||||
|
|
||||||
private SmartBoolean opened;
|
private boolean opened;
|
||||||
private float progress = 0f;
|
private float progress = 0f;
|
||||||
private float width = 200;
|
private float width = 200;
|
||||||
|
|
||||||
|
|
@ -35,35 +34,36 @@ public class JobBoardTab extends Tab implements ISelectionChangeListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
protected void connect() {
|
||||||
super.start();
|
super.connect();
|
||||||
selection = get(SelectionLayer.class);
|
selection = get(SelectionLayer.class);
|
||||||
jobBoard = get(JobBoard.class);
|
jobBoard = get(JobBoard.class);
|
||||||
|
}
|
||||||
opened = new SmartBoolean(false, new SmartBoolean.IListener() {
|
|
||||||
});
|
@Override
|
||||||
|
public void start() {
|
||||||
|
super.start();
|
||||||
|
opened = false;
|
||||||
|
if(selection != null) selection.subscribe(this);
|
||||||
|
|
||||||
if(selection != null) {
|
|
||||||
selection.subscribe(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float dTime) {
|
public void update(float dTime) {
|
||||||
progress = lerp(progress, opened.value() ? 1 : 0, 0.05f);
|
progress = lerp(progress, opened ? 1 : 0, 0.05f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectionChanged(List<ISelectable> selected) {
|
public void selectionChanged(List<ISelectable> selected) {
|
||||||
if(selected.isEmpty()) return;
|
if(selected.isEmpty()) return;
|
||||||
opened.set(false);
|
opened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void evoke() {
|
public void evoke() {
|
||||||
opened.toggle();
|
opened = !opened;
|
||||||
|
|
||||||
if(opened.value()) {
|
if(opened) {
|
||||||
selection.updateSelection(new ArrayList<ISelectable>());
|
selection.updateSelection(new ArrayList<ISelectable>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,12 @@ public abstract class Tab extends GameObject implements IBottomBarItem, ITransie
|
||||||
private BottomBar bottombar;
|
private BottomBar bottombar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
protected void connect() {
|
||||||
bottombar = get(BottomBar.class);
|
bottombar = get(BottomBar.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start() {
|
||||||
bottombar.registerButton(this);
|
bottombar.registerButton(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,11 +56,6 @@ public class Stockpile extends WorldObject implements ISelectable, ITileThing, I
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start() {
|
|
||||||
super.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector4f getWorldBox() {
|
public Vector4f getWorldBox() {
|
||||||
return new Vector4f(x, y, x + w, y + h);
|
return new Vector4f(x, y, x + w, y + h);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ public abstract class WorldObject extends GameObject {
|
||||||
protected Terrain terrain;
|
protected Terrain terrain;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
protected void connect() {
|
||||||
camera = get(Camera.class);
|
camera = get(Camera.class);
|
||||||
terrain = get(Terrain.class);
|
terrain = get(Terrain.class);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,14 @@ public abstract class Item extends WorldObject implements ISelectable, ITileThin
|
||||||
private Job haulJob = null;
|
private Job haulJob = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
protected void connect() {
|
||||||
super.start();
|
super.connect();
|
||||||
if(jobboard == null) {
|
jobboard = get(JobBoard.class);
|
||||||
jobboard = get(JobBoard.class);
|
}
|
||||||
markForHaul();
|
|
||||||
}
|
protected void create() {
|
||||||
|
super.create();
|
||||||
|
if(haulOnCreate()) markForHaul();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean haulOnCreate() {
|
protected boolean haulOnCreate() {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ public class Pawn extends Agent {
|
||||||
// private float workEthic = (float) Math.random();
|
// private float workEthic = (float) Math.random();
|
||||||
// private float selfWorth = (float) Math.random();
|
// private float selfWorth = (float) Math.random();
|
||||||
|
|
||||||
private List<Activity> activities = new ArrayList<Activity>();
|
private transient List<Activity> activities = new ArrayList<Activity>();
|
||||||
private Activity currentActivity = null;
|
private Activity currentActivity = null;
|
||||||
|
|
||||||
public void pickupItem(Item i) {
|
public void pickupItem(Item i) {
|
||||||
|
|
@ -52,15 +52,23 @@ public class Pawn extends Agent {
|
||||||
getTile().placeThing(item);
|
getTile().placeThing(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void ready() {
|
||||||
|
super.ready();
|
||||||
|
activities = new ArrayList<Activity>();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
super.start();
|
super.start();
|
||||||
x = (int) (Math.random() * Terrain.WORLD_SIZE);
|
|
||||||
y = (int) (Math.random() * Terrain.WORLD_SIZE);
|
|
||||||
|
|
||||||
activities.add(new JobActivity(this, get(JobBoard.class)));
|
activities.add(new JobActivity(this, get(JobBoard.class)));
|
||||||
activities.add(new SleepActivity(this, needs, get(Clock.class)));
|
activities.add(new SleepActivity(this, needs, get(Clock.class)));
|
||||||
// activities.add(new WanderActivity());
|
}
|
||||||
|
|
||||||
|
protected void create() {
|
||||||
|
x = (int) (Math.random() * Terrain.WORLD_SIZE);
|
||||||
|
y = (int) (Math.random() * Terrain.WORLD_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue