Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TagSet and editor support (#129) #132

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import java.lang.reflect.Modifier;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PropertiesMenu extends Table {
public ArrayMap<String, Array<Field>> arrayMap = new ArrayMap<String, Array<Field>>();
Expand Down Expand Up @@ -162,6 +165,15 @@ else if(field.getType() == String.class) {

fieldMap.put(field, tf);
}
else if (field.getType() == TagSet.class) {
TextField tf = new TextField(v, skin);
tf.setTextFieldListener(getTextFieldListener(field));

add(label).align(Align.left);
add(tf).align(Align.left).fill();

fieldMap.put(field, tf);
}
else if(field.getType() == Material.class) {
Material val = (Material)value;

Expand Down Expand Up @@ -637,6 +649,13 @@ else if(currentField.getType() == String.class) {
currentField.set(entity, val);
}
}
else if(currentField.getType() == TagSet.class) {
for(Entity entity : selectedEntities) {
TagSet tags = new TagSet();
tags.addAll(Stream.of(val.split(",")).map((v) -> v.trim()).collect(Collectors.toSet()));
currentField.set(entity, tags);
}
}
}
else if(actor instanceof TextButton) {
String val = ((TextButton)actor).getText().toString();
Expand Down Expand Up @@ -714,7 +733,7 @@ else if(currentField.getType() == Color.class) {
}
}
catch(Exception ex) {
Gdx.app.error("DelvEdit", ex.getMessage());
Gdx.app.error("DelvEdit: Property Change", ex.getMessage());
}
}

Expand Down
10 changes: 10 additions & 0 deletions Dungeoneer/src/com/badlogic/gdx/utils/TagSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.badlogic.gdx.utils;

import java.util.HashSet;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be warned, the default Java collections are not always great for performance since they sometimes create extra objects when accessed. LibGdx includes some more game-friendly collections, could this be done with something like the libGdx ArrayMap? https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/utils/ArrayMap.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted in for the ObjectSet mainly because of the API compatibility, and also because the Set (as opposed to the Map) interface stores only a set of unique keys. There is no use for the values in the tag system.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That looks nicer.


public class TagSet extends HashSet<String> {
@Override
public String toString() {
return String.join(", ", this);
}
}
4 changes: 4 additions & 0 deletions Dungeoneer/src/com/interrupt/dungeoneer/entities/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.TagSet;
import com.interrupt.dungeoneer.Audio;
import com.interrupt.dungeoneer.annotations.EditorProperty;
import com.interrupt.dungeoneer.collision.Collision;
Expand Down Expand Up @@ -30,6 +31,9 @@ public class Entity {
@EditorProperty( group = "Visual" )
public Drawable drawable;

@EditorProperty
public TagSet tags = new TagSet();

/** Position x-component. */
public float x;

Expand Down