junkdog / artemis-odb

A continuation of the popular Artemis ECS framework
BSD 2-Clause "Simplified" License
779 stars 112 forks source link

Prefabs/typed multi-entity templates #448

Closed junkdog closed 8 years ago

junkdog commented 8 years ago
@PrefabData("prefab/player.json")
public class PlayerPrefab extends Prefab {
    private ComponentMapper<Position> positionMapper;

    public PlayerPrefab(World world) {
        super(world, new FallbackFileResolver());
    }

    public SaveFileFormat createPlayer(float x, float y) {
        SaveFileFormat l = create();
        Entity player = l.get("player");

        positionMapper.get(player).xy.set(x, y);

        return l;
    }
}

mininmum viable world configuration:

world = new World(new WorldConfiguration()
    .setSystem(GroupManager.class) // not strictly necessary
    .setSystem(TagManager.class)   // not strictly necessary
    .setSystem(WorldSerializationManager.class));

JsonArtemisSerializer backend = new JsonArtemisSerializer(world);
backend.prettyPrint(true);
world.getSystem(WorldSerializationManager.class).setSerializer(backend);

saving entities to json

The (/some) tests use:

    public static String save(IntBag entities,
                              WorldSerializationManager manger)
            throws Exception {

        SaveFileFormat save = new SaveFileFormat(entities);
        ByteArrayOutputStream baos = new ByteArrayOutputStream(256);
        manger.save(baos, save);
        return baos.toString(StandardCharsets.UTF_8.name());
    }
DaanVanYperen commented 8 years ago

E("prefab/player.json").pos(5,5); AAAAAAAAAAAAAHHHHHHHHHHHHHH

junkdog commented 8 years ago

Whaaat1!?!!??