saving and loading

pull/1/head
Ivory 2023-01-02 19:40:36 -05:00
parent 8d3535da55
commit 54da15ef59
14 changed files with 69 additions and 58 deletions

View File

@ -1,5 +0,0 @@
{
"configurations": [
]
}

View File

@ -10,6 +10,7 @@ public class GameObject implements IRenderable, ITickable, Serializable {
public void link(SceneGraph scene) {
this.scene = scene;
this.ready();
}
public boolean inScene() {
@ -45,6 +46,10 @@ public class GameObject implements IRenderable, ITickable, Serializable {
@Override
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()
protected void connect() {}
// create is guaranteed to only run once for an object, even after save/load

View File

@ -206,8 +206,9 @@ public abstract class SceneGraph implements IScene {
objects.addAll(newObjects);
for(GameObject obj : objects) obj.link(this);
for(GameObject obj : objects) obj.addedToScene();
for(GameObject obj : newObjects) obj.link(this);
for(GameObject obj : newObjects) obj.addedToScene();
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -10,11 +10,6 @@ public class Clock extends GameObject {
private float time = 12;
@Override
public void start() {
}
@Override
public void update(float dTime) {
time += 0.0004f;

View File

@ -24,20 +24,23 @@ public class Terrain extends GameObject implements IPathable, IWorldBoundsAdapte
private Camera camera;
public void start() {
@Override
protected void create() {
for (int i = 0; i < WORLD_SIZE; i++) {
for (int j = 0; j < WORLD_SIZE; j++) {
tiles[i][j] = new Tile(i, j);
add(tiles[i][j]);
}
}
}
// Tile randomTile = getRandomTile();
// Vector2i coords = randomTile.getCoords();
// Stockpile stockpile = new Stockpile(coords.x, coords.y);
// randomTile.placeThing(stockpile);
@Override
protected void connect() {
camera = get(Camera.class);
}
@Override
protected void start() {
camera.focus(WORLD_SIZE / 2, WORLD_SIZE / 2);
}

View File

@ -45,11 +45,6 @@ public class Tile extends WorldObject implements IWorkable {
public void start() {
super.start();
// if(Math.random() > 0.97) {
// Tree tree = new Tree((int)x, (int)y);
// stuff.add(tree);
// add(tree);
// }
float scale = 1;
@ -58,7 +53,15 @@ public class Tile extends WorldObject implements IWorkable {
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);
// 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() {

View File

@ -21,7 +21,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi
private IBuildLayerListener listener = null;
@Override
public void start() {
protected void connect() {
camera = get(Camera.class);
}

View File

@ -19,8 +19,8 @@ public class HoverQuery extends GameObject implements ITransient {
private Camera camera;
@Override
public void start() {
super.start();
protected void connect() {
super.connect();
camera = get(Camera.class);
}

View File

@ -13,14 +13,13 @@ import xyz.valnet.hadean.interfaces.ISelectable;
import xyz.valnet.hadean.interfaces.ISelectionChangeListener;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
import xyz.valnet.hadean.util.SmartBoolean;
public class JobBoardTab extends Tab implements ISelectionChangeListener {
private SelectionLayer selection;
private JobBoard jobBoard;
private SmartBoolean opened;
private boolean opened;
private float progress = 0f;
private float width = 200;
@ -35,35 +34,36 @@ public class JobBoardTab extends Tab implements ISelectionChangeListener {
}
@Override
public void start() {
super.start();
protected void connect() {
super.connect();
selection = get(SelectionLayer.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
public void update(float dTime) {
progress = lerp(progress, opened.value() ? 1 : 0, 0.05f);
progress = lerp(progress, opened ? 1 : 0, 0.05f);
}
@Override
public void selectionChanged(List<ISelectable> selected) {
if(selected.isEmpty()) return;
opened.set(false);
opened = false;
}
@Override
public void evoke() {
opened.toggle();
opened = !opened;
if(opened.value()) {
if(opened) {
selection.updateSelection(new ArrayList<ISelectable>());
}
}

View File

@ -10,8 +10,12 @@ public abstract class Tab extends GameObject implements IBottomBarItem, ITransie
private BottomBar bottombar;
@Override
public void start() {
protected void connect() {
bottombar = get(BottomBar.class);
}
@Override
protected void start() {
bottombar.registerButton(this);
}
}

View File

@ -56,11 +56,6 @@ public class Stockpile extends WorldObject implements ISelectable, ITileThing, I
return null;
}
@Override
public void start() {
super.start();
}
@Override
public Vector4f getWorldBox() {
return new Vector4f(x, y, x + w, y + h);

View File

@ -16,7 +16,7 @@ public abstract class WorldObject extends GameObject {
protected Terrain terrain;
@Override
public void start() {
protected void connect() {
camera = get(Camera.class);
terrain = get(Terrain.class);
}

View File

@ -18,12 +18,14 @@ public abstract class Item extends WorldObject implements ISelectable, ITileThin
private Job haulJob = null;
@Override
public void start() {
super.start();
if(jobboard == null) {
jobboard = get(JobBoard.class);
markForHaul();
}
protected void connect() {
super.connect();
jobboard = get(JobBoard.class);
}
protected void create() {
super.create();
if(haulOnCreate()) markForHaul();
}
protected boolean haulOnCreate() {

View File

@ -33,7 +33,7 @@ public class Pawn extends Agent {
// private float workEthic = (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;
public void pickupItem(Item i) {
@ -52,15 +52,23 @@ public class Pawn extends Agent {
getTile().placeThing(item);
}
@Override
protected void ready() {
super.ready();
activities = new ArrayList<Activity>();
}
@Override
public void 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 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