random names, wandering, improved selection ui
parent
9b12ee7417
commit
a205bad00f
6
pom.xml
6
pom.xml
|
|
@ -76,9 +76,9 @@
|
|||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>2.13.4</version>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
import yaml
|
||||
|
||||
dataStr = open("res/names.yml").read()
|
||||
print("loading data")
|
||||
data = yaml.safe_load(dataStr)
|
||||
# data = [
|
||||
# {
|
||||
# "name": 'fonk',
|
||||
# "sex": 'donk'
|
||||
# },
|
||||
# {
|
||||
# "name": 'fonk',
|
||||
# "sex": 'donk'
|
||||
# },
|
||||
# {
|
||||
# "name": 'tonk',
|
||||
# "sex": 'donk'
|
||||
# }
|
||||
# ]
|
||||
newData = []
|
||||
|
||||
def findPairInArray(arr, n, s):
|
||||
for pair in arr:
|
||||
name = pair["name"]
|
||||
sex = pair["sex"]
|
||||
if n == name and s == sex:
|
||||
return pair
|
||||
return None
|
||||
|
||||
|
||||
for pair in data:
|
||||
name = pair["name"]
|
||||
sex = pair["sex"]
|
||||
print("" + name + " " + sex)
|
||||
match = findPairInArray(newData, name, sex)
|
||||
print(match)
|
||||
if match == None:
|
||||
newData.append({
|
||||
"name": name,
|
||||
"sex": sex
|
||||
})
|
||||
|
||||
print(newData)
|
||||
|
||||
with open('res/output.yaml', 'w') as file:
|
||||
outputs = yaml.dump(newData, file)
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,13 @@
|
|||
firstName: "John"
|
||||
lastName: "Doe"
|
||||
age: 31
|
||||
contactDetails:
|
||||
- type: "mobile"
|
||||
number: 123456789
|
||||
- type: "landline"
|
||||
number: 456786868
|
||||
homeAddress:
|
||||
line: "Xyz, DEF Street"
|
||||
city: "City Y"
|
||||
state: "State Y"
|
||||
zip: 345657
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package xyz.valnet.engine.util;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.lang.Math;
|
||||
|
||||
import org.yaml.snakeyaml.TypeDescription;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
|
||||
public class Names {
|
||||
|
||||
public static class NamesYaml {
|
||||
public List<Name> names;
|
||||
|
||||
public static class Name {
|
||||
public String name;
|
||||
public String sex;
|
||||
}
|
||||
}
|
||||
|
||||
private static Names instance;
|
||||
|
||||
private List<NamesYaml.Name> names;
|
||||
|
||||
public static void loadNames() {
|
||||
instance = new Names();
|
||||
}
|
||||
|
||||
|
||||
private void load() {
|
||||
InputStream fileStream = null;
|
||||
try {
|
||||
// Constructor constructor = new Constructor();
|
||||
// TypeDescription typeDescription = new TypeDescription(NameYaml.class);
|
||||
// // typeDescription.putListPropertyType("things", ConfigurableThing.class);
|
||||
// constructor.addTypeDescription(typeDescription);
|
||||
|
||||
Yaml yaml = new Yaml();
|
||||
fileStream = new FileInputStream("res/names.yaml");
|
||||
var loaded = yaml.loadAs(fileStream, NamesYaml.class).names;
|
||||
this.names = loaded;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (fileStream != null) {
|
||||
try {
|
||||
fileStream.close();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Names() {
|
||||
load();
|
||||
}
|
||||
|
||||
public static String getRandomName() {
|
||||
return instance.names.get((int)Math.floor(Math.random() * instance.names.size())).name;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ import xyz.valnet.hadean.util.detail.Detail;
|
|||
public class SelectionUI extends GameObject implements ISelectionChangeListener, IButtonListener, IMouseCaptureArea, ITransient {
|
||||
|
||||
private String name = "";
|
||||
private String genericName = "";
|
||||
private int count = 0;
|
||||
private List<ISelectable> selected = new ArrayList<ISelectable>();
|
||||
private HashMap<String, Integer> selectedTypes = new HashMap<String, Integer>();
|
||||
|
|
@ -58,12 +59,12 @@ public class SelectionUI extends GameObject implements ISelectionChangeListener,
|
|||
Assets.uiFrame.draw(10, 576 - BottomBar.bottomBarHeight - height - padding, width, height);
|
||||
|
||||
if(selectedTypes.size() == 1) {
|
||||
Assets.font.drawString("" + count + "x " + name, 26, 576 - BottomBar.bottomBarHeight - height);
|
||||
|
||||
if(count == 1) {
|
||||
|
||||
Assets.font.drawString(name, 26, 576 - BottomBar.bottomBarHeight - height);
|
||||
String details = Detail.renderDetails(selected.get(0).getDetails());
|
||||
Assets.font.drawString(details, 26, 576 - BottomBar.bottomBarHeight - height + 32);
|
||||
} else {
|
||||
Assets.font.drawString("" + count + "x " + genericName, 26, 576 - BottomBar.bottomBarHeight - height);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
@ -109,6 +110,7 @@ public class SelectionUI extends GameObject implements ISelectionChangeListener,
|
|||
for(ISelectable selectable : selected) {
|
||||
String name = selectable.getClass().getName();
|
||||
String[] splitName = name.split("\\.");
|
||||
String properName = selectable.getName();
|
||||
String shortName = splitName[splitName.length - 1];
|
||||
|
||||
if(selectedTypes.containsKey(name)) {
|
||||
|
|
@ -119,7 +121,7 @@ public class SelectionUI extends GameObject implements ISelectionChangeListener,
|
|||
btn.setText("" + items.size() + "x " + shortName);
|
||||
count ++;
|
||||
} else {
|
||||
Button btn = new SimpleButton("1x " + shortName, 20, 576 - BottomBar.bottomBarHeight - height + 30 * selectedTypes.size(), width - padding * 2, 24, Layers.GENERAL_UI_INTERACTABLE);
|
||||
Button btn = new SimpleButton(properName, 20, 576 - BottomBar.bottomBarHeight - height + 30 * selectedTypes.size(), width - padding * 2, 24, Layers.GENERAL_UI_INTERACTABLE);
|
||||
btn.registerClickListener(this);
|
||||
selectedTypes.put(name, 1);
|
||||
addNarrowButton(name, btn);
|
||||
|
|
@ -127,7 +129,8 @@ public class SelectionUI extends GameObject implements ISelectionChangeListener,
|
|||
list.add(selectable);
|
||||
narrowBuckets.put(btn, list);
|
||||
count = 1;
|
||||
this.name = shortName;
|
||||
this.name = properName;
|
||||
this.genericName = shortName;
|
||||
}
|
||||
}
|
||||
if(selectedTypes.size() == 1) {
|
||||
|
|
|
|||
|
|
@ -72,4 +72,16 @@ public class Terrain extends GameObject implements IPathable, IWorldBoundsAdapte
|
|||
return new Vector4f(0, 0, WORLD_SIZE, WORLD_SIZE);
|
||||
}
|
||||
|
||||
public Tile getRandomWalkableTile() {
|
||||
Tile tile = null;
|
||||
int maxTries = 100;
|
||||
int tries = 0;
|
||||
while((tile == null || !tile.isWalkable()) && tries < maxTries) {
|
||||
tile = tiles[(int)Math.floor(Math.random() * WORLD_SIZE)][(int)Math.floor(Math.random() * WORLD_SIZE)];
|
||||
tries ++;
|
||||
}
|
||||
if(tries >= maxTries) return null;
|
||||
return tile;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ public class JobActivity extends Activity {
|
|||
job = jobboard.requestJob(worker);
|
||||
if(job == null) callback.apply(this);
|
||||
job.registerClosedListener(() -> {
|
||||
System.out.println("job cancelled");
|
||||
callback.apply(this);
|
||||
});
|
||||
|
||||
|
|
@ -127,7 +126,7 @@ public class JobActivity extends Activity {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(job == null) return "Activity (Null Job)";
|
||||
if(job == null) return "No Work";
|
||||
return job.getJobName();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package xyz.valnet.hadean.gameobjects.worldobjects.pawn;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import xyz.valnet.hadean.HadeanGame;
|
||||
import xyz.valnet.hadean.util.detail.Detail;
|
||||
import xyz.valnet.hadean.util.detail.PercentDetail;
|
||||
|
||||
|
|
@ -23,6 +24,9 @@ public class Needs implements Serializable {
|
|||
}
|
||||
|
||||
public float getSleepNeed() {
|
||||
if(HadeanGame.debugView) {
|
||||
return 0;
|
||||
}
|
||||
return 1 - energy;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.pawn;
|
||||
|
||||
import static xyz.valnet.hadean.util.detail.Detail.mergeDetails;
|
||||
import static xyz.valnet.hadean.util.detail.Detail.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -8,6 +8,8 @@ import java.util.List;
|
|||
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;
|
||||
|
|
@ -27,7 +29,7 @@ import xyz.valnet.hadean.util.detail.PercentDetail;
|
|||
public class Pawn extends Agent {
|
||||
|
||||
private static int pawnCount = 0;
|
||||
private String name = "Pawn " + (++ pawnCount);
|
||||
private String name = Names.getRandomName();
|
||||
private Needs needs = new Needs();
|
||||
|
||||
// private int meaningless = 0;
|
||||
|
|
@ -98,6 +100,7 @@ public class Pawn extends Agent {
|
|||
|
||||
activities.add(new JobActivity(this, get(JobBoard.class)));
|
||||
activities.add(new SleepActivity(needs, get(Clock.class)));
|
||||
activities.add(new WanderActivity(this, needs, get(Terrain.class)));
|
||||
}
|
||||
|
||||
protected void create() {
|
||||
|
|
@ -125,12 +128,21 @@ public class Pawn extends Agent {
|
|||
@Override
|
||||
public Detail[] getDetails() {
|
||||
// return needs.getDetails();
|
||||
return mergeDetails(needs.getDetails(), new Detail[] {
|
||||
Detail[] details = mergeDetails(needs.getDetails(), new Detail[] {
|
||||
new ObjectDetail<Activity>("Activity", currentActivity),
|
||||
new PercentDetail("Sleep Value", activities.get(1).getBenefit(), 2),
|
||||
new BooleanDetail("Pathing", isPathing()),
|
||||
new ObjectDetail<Integer>("Inventory", inventory.size())
|
||||
});
|
||||
|
||||
if(HadeanGame.debugView) {
|
||||
for(Activity activity : activities) {
|
||||
details = mergeDetails(details, new Detail[] {
|
||||
new PercentDetail(activity.toString(), activity.getBenefit())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return details;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -172,8 +184,6 @@ public class Pawn extends Agent {
|
|||
|
||||
if(currentActivity != null) return;
|
||||
|
||||
currentActivity = null;
|
||||
|
||||
List<Activity> valueSortedActivities = activities.stream()
|
||||
.filter(a -> a.isValid())
|
||||
.map(a -> new Pair<Activity, Float>(a, a.getBenefit()))
|
||||
|
|
@ -188,6 +198,7 @@ public class Pawn extends Agent {
|
|||
}
|
||||
|
||||
private void switchActivity(Activity activity) {
|
||||
if(activity == currentActivity) return;
|
||||
if(currentActivity != null) currentActivity.end();
|
||||
currentActivity = activity;
|
||||
stopPathing();
|
||||
|
|
@ -202,12 +213,9 @@ public class Pawn extends Agent {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO at some point rewrite this to use an actor component array
|
||||
// where we loop through until something _does_ sometihng.
|
||||
@Override
|
||||
protected boolean act(float dTime) {
|
||||
if(super.act(dTime)) return true;
|
||||
// if(doJob()) return true;
|
||||
if(currentActivity != null) {
|
||||
currentActivity.act(dTime);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,23 @@
|
|||
package xyz.valnet.hadean.gameobjects.worldobjects.pawn;
|
||||
|
||||
import xyz.valnet.engine.math.Vector2i;
|
||||
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||
import xyz.valnet.hadean.gameobjects.Tile;
|
||||
import xyz.valnet.hadean.gameobjects.worldobjects.agents.Agent;
|
||||
|
||||
// TODO actually implement this activity.
|
||||
public class WanderActivity extends Activity {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Agent agent;
|
||||
@SuppressWarnings("unused")
|
||||
private Needs needs;
|
||||
// TODO implement fun?
|
||||
// private Needs needs;
|
||||
|
||||
public WanderActivity(Agent agent, Needs needs) {
|
||||
this.needs = needs;
|
||||
private Terrain terrain;
|
||||
|
||||
public WanderActivity(Agent agent, Needs needs, Terrain terrain) {
|
||||
// this.needs = needs;
|
||||
this.agent = agent;
|
||||
this.terrain = terrain;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -33,7 +37,7 @@ public class WanderActivity extends Activity {
|
|||
|
||||
@Override
|
||||
public void act(float dTime) {
|
||||
// since wandering is literally just pathing.
|
||||
callback.apply(this);
|
||||
}
|
||||
|
||||
ActivityCancellationCallback callback;
|
||||
|
|
@ -41,6 +45,13 @@ public class WanderActivity extends Activity {
|
|||
@Override
|
||||
public void begin(ActivityCancellationCallback callback) {
|
||||
this.callback = callback;
|
||||
|
||||
Tile tile = terrain.getRandomWalkableTile();
|
||||
if(tile == null) {
|
||||
callback.apply(this);
|
||||
return;
|
||||
}
|
||||
target = tile.getCoords();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -48,12 +59,15 @@ public class WanderActivity extends Activity {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Sleeping";
|
||||
return "Wandering";
|
||||
}
|
||||
|
||||
private Vector2i target = null;
|
||||
|
||||
@Override
|
||||
public Vector2i[] getTargetLocations() {
|
||||
return null;
|
||||
if(target == null) return null;
|
||||
return new Vector2i[] { target };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,4 +30,5 @@ public interface ISelectable {
|
|||
public default Priority getSelectPriority() {
|
||||
return Priority.NORMAL;
|
||||
}
|
||||
public String getName();
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
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.Camera;
|
||||
import xyz.valnet.hadean.gameobjects.Clock;
|
||||
|
|
@ -31,6 +32,8 @@ public class GameScene extends SceneGraph {
|
|||
@Override
|
||||
protected void construct() {
|
||||
|
||||
Names.loadNames();
|
||||
|
||||
objects.add(new Terrain());
|
||||
objects.add(new Camera());
|
||||
objects.add(new JobBoard());
|
||||
|
|
|
|||
|
|
@ -30,4 +30,28 @@ public abstract class Detail {
|
|||
System.arraycopy(b, 0, c, a.length, b.length);
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Detail[] mergeDetails(Detail[] a, Detail[] b, Detail[] c) {
|
||||
Detail[] d = new Detail[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 Detail[] mergeDetails(Detail[] ... args) {
|
||||
if(args.length == 1) return new Detail[0];
|
||||
if(args.length == 1) return args[0];
|
||||
if(args.length == 2) return mergeDetails(args[0], args[1]);
|
||||
if(args.length == 3) return mergeDetails(args[0], args[1], args[2]);
|
||||
|
||||
Detail[][] merge = new Detail[3][];
|
||||
Detail[][] rest = new Detail[args.length - 3][];
|
||||
System.arraycopy(args, 0, merge, 0, 3);
|
||||
System.arraycopy(args, 3, rest, 0, rest.length);
|
||||
|
||||
Detail[] first = mergeDetails(merge);
|
||||
Detail[] merged = mergeDetails(rest);
|
||||
return mergeDetails(first, merged);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue