Last active
April 18, 2017 18:30
-
-
Save junkdog/6ff07302cf3dc31007fbcb89ce7827a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get all entities | |
val ids = world.aspectSubscriptionManager | |
.get(Aspect.all()) | |
// save as raw json string - for demo purposes | |
val saved = StringWriter().use { sw -> | |
serializer.save(sw, SaveFileFormat(ids)) | |
sw.toString() | |
} | |
// process json; resolve type mappings, referenced components etc | |
val context = Context(saved.toJson()) // "some_prefab.json" | |
// SomePrefab.java | |
val source: String = generatePrefab("SomePrefab", context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"version": 1 | |
}, | |
"componentIdentifiers": { | |
"com.artemis.component.ComponentY": "ComponentY", | |
"com.artemis.component.PrimitiveComponent": "PrimitiveComponent", | |
"com.artemis.component.CompB": "CompB", | |
"com.artemis.component.CompA": "CompA", | |
"com.artemis.component.ComponentX": "ComponentX", | |
"com.artemis.component.PositionXy": "PositionXy", | |
"com.artemis.component.CompC": "CompC" | |
}, | |
"entities": { | |
"0": { | |
"archetype": 5, | |
"components": { | |
"ComponentX": { | |
"text": "hell, comp x" | |
}, | |
"ComponentY": { | |
"text": "comp y, also text" | |
}, | |
"PositionXy": { | |
"xy": { | |
"x": 1, | |
"y": 2 | |
} | |
}, | |
"PrimitiveComponent": { | |
"aInt": 123, | |
"aDouble": 4 | |
} | |
} | |
}, | |
"1": { | |
"archetype": 9, | |
"components": { | |
"CompA": { | |
"a": 13300 | |
}, | |
"CompB": { | |
"b": 300 | |
}, | |
"CompC": { | |
"c": 40 | |
}, | |
"ComponentX": { | |
"text": "foo" | |
}, | |
"ComponentY": { | |
"text": "bar" | |
}, | |
"PositionXy": { | |
"xy": { | |
"x": 231, | |
"y": -2 | |
} | |
}, | |
"PrimitiveComponent": { | |
"aInt": 123, | |
"aDouble": 4 | |
} | |
} | |
} | |
}, | |
"archetypes": { | |
"5": [ | |
"PositionXy", | |
"ComponentX", | |
"ComponentY", | |
"CompC", | |
"PrimitiveComponent" | |
], | |
"9": [ | |
"PositionXy", | |
"ComponentX", | |
"ComponentY", | |
"CompC", | |
"PrimitiveComponent", | |
"CompA", | |
"CompB" | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.artemis.generated; | |
import com.artemis.ComponentMapper; | |
import com.artemis.EntityTransmuter; | |
import com.artemis.World; | |
import com.artemis.annotations.AspectDescriptor; | |
import com.artemis.component.CompA; | |
import com.artemis.component.CompB; | |
import com.artemis.component.CompC; | |
import com.artemis.component.ComponentX; | |
import com.artemis.component.ComponentY; | |
import com.artemis.component.PositionXy; | |
import com.artemis.component.PrimitiveComponent; | |
import com.artemis.io.EntityPoolFactory; | |
import com.artemis.prefab.CompiledPrefab; | |
public final class SomePrefab extends CompiledPrefab { | |
@AspectDescriptor( | |
all = {PositionXy.class, ComponentX.class, ComponentY.class, CompC.class, PrimitiveComponent.class} | |
) | |
private EntityTransmuter transmuter5; | |
@AspectDescriptor( | |
all = {PositionXy.class, ComponentX.class, ComponentY.class, CompC.class, PrimitiveComponent.class, CompA.class, CompB.class} | |
) | |
private EntityTransmuter transmuter9; | |
private ComponentMapper<CompA> compAMapper; | |
private ComponentMapper<CompB> compBMapper; | |
private ComponentMapper<CompC> compCMapper; | |
private ComponentMapper<ComponentX> componentXMapper; | |
private ComponentMapper<ComponentY> componentYMapper; | |
private ComponentMapper<PositionXy> positionXyMapper; | |
private ComponentMapper<PrimitiveComponent> primitiveComponentMapper; | |
public void compiledCreate(World world) { | |
EntityPoolFactory factory = entityFactory(world, 2); | |
// creating entity 0 | |
int e0 = factory.createEntityId(); | |
transmuter5.transmute(e0); | |
{ | |
ComponentX c = componentXMapper.get(e0); | |
c.text = "hell, comp x"; | |
} | |
{ | |
ComponentY c = componentYMapper.get(e0); | |
c.text = "comp y, also text"; | |
} | |
{ | |
PositionXy c = positionXyMapper.get(e0); | |
Vector2 xy = c.xy; | |
xy.x = 1.0f; | |
xy.y = 2.0f; | |
} | |
{ | |
PrimitiveComponent c = primitiveComponentMapper.get(e0); | |
c.aInt = 123; | |
c.aDouble = 4.0; | |
} | |
// creating entity 1 | |
int e1 = factory.createEntityId(); | |
transmuter9.transmute(e1); | |
{ | |
CompA c = compAMapper.get(e1); | |
c.a = 13300; | |
} | |
{ | |
CompB c = compBMapper.get(e1); | |
c.b = 300.0f; | |
} | |
{ | |
CompC c = compCMapper.get(e1); | |
c.c = 40; | |
} | |
{ | |
ComponentX c = componentXMapper.get(e1); | |
c.text = "foo"; | |
} | |
{ | |
ComponentY c = componentYMapper.get(e1); | |
c.text = "bar"; | |
} | |
{ | |
PositionXy c = positionXyMapper.get(e1); | |
Vector2 xy = c.xy; | |
xy.x = 231.0f; | |
xy.y = -2.0f; | |
} | |
{ | |
PrimitiveComponent c = primitiveComponentMapper.get(e1); | |
c.aInt = 123; | |
c.aDouble = 4.0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment