use of com.talosvfx.talos.editor.data.ModuleWrapperGroup in project talos by rockbite.
the class TalosProject method loadProject.
public void loadProject(FileHandle projectFileHandle, String data, boolean fromMemory) {
TalosMain.Instance().UIStage().PreviewWidget().getGLProfiler().reset();
cleanData();
projectSerializer.prereadhack(data);
projectData = projectSerializer.read(data);
readMetaData = projectData.metaData;
ParticleEmitterWrapper firstEmitter = null;
for (EmitterData emitterData : projectData.getEmitters()) {
IntMap<ModuleWrapper> map = new IntMap<>();
ParticleEmitterWrapper emitterWrapper = loadEmitter(emitterData.name, emitterData.sortPosition);
TalosMain.Instance().NodeStage().moduleBoardWidget.loadEmitterToBoard(emitterWrapper, emitterData);
final ParticleEmitterDescriptor graph = emitterWrapper.getGraph();
for (ModuleWrapper module : emitterData.modules) {
map.put(module.getId(), module);
graph.addModule(module.getModule());
module.getModule().setModuleGraph(graph);
}
// important
particleEffectDescriptor.setEffectReference(particleEffect);
particleEffectDescriptor.addEmitter(graph);
particleEffect.init();
// configure emitter visibility
emitterWrapper.isMuted = emitterData.isMuted;
particleEffect.getEmitter(emitterWrapper.getGraph()).setVisible(!emitterData.isMuted);
// time to load groups here
for (GroupData group : emitterData.groups) {
ObjectSet<ModuleWrapper> childWrappers = new ObjectSet<>();
for (Integer id : group.modules) {
if (map.get(id) != null) {
childWrappers.add(map.get(id));
}
}
ModuleWrapperGroup moduleWrapperGroup = TalosMain.Instance().NodeStage().moduleBoardWidget.createGroupForWrappers(childWrappers);
Color clr = new Color();
Color.abgr8888ToColor(clr, group.color);
moduleWrapperGroup.setData(group.text, clr);
}
}
sortEmitters();
if (activeWrappers.size > 0) {
firstEmitter = activeWrappers.first();
}
if (firstEmitter != null) {
TalosMain.Instance().TalosProject().setCurrentEmitterWrapper(firstEmitter);
TalosMain.Instance().NodeStage().moduleBoardWidget.setCurrentEmitter(firstEmitter);
}
TalosMain.Instance().UIStage().setEmitters(activeWrappers);
TalosMain.Instance().NodeStage().getStage().setKeyboardFocus(null);
}
use of com.talosvfx.talos.editor.data.ModuleWrapperGroup in project talos by rockbite.
the class ModuleBoardWidget method pasteFromClipboard.
public void pasteFromClipboard() {
String clipboard = Gdx.app.getClipboard().getContents();
ObjectMap<Integer, ModuleWrapper> previousWrapperIdMap = new ObjectMap<>();
boolean hasParticleModule = false;
boolean hasEmitterModule = false;
for (ModuleWrapper wrapper : getModuleWrappers()) {
if (wrapper instanceof ParticleModuleWrapper)
hasParticleModule = true;
if (wrapper instanceof EmitterModuleWrapper)
hasEmitterModule = true;
}
Json json = new Json();
try {
ClipboardPayload payload = json.fromJson(ClipboardPayload.class, clipboard);
Vector3 camPosAtPaste = TalosMain.Instance().NodeStage().getStage().getCamera().position;
Vector2 offset = new Vector2(camPosAtPaste.x, camPosAtPaste.y);
offset.sub(payload.cameraPositionAtCopy);
ObjectSet<ModuleWrapper> wrappers = payload.wrappers;
ObjectSet<ModuleWrapper> copiedWrappers = new ObjectSet<>();
for (ModuleWrapper wrapper : wrappers) {
if (wrapper instanceof ParticleModuleWrapper && hasParticleModule) {
continue;
}
if (wrapper instanceof EmitterModuleWrapper && hasEmitterModule) {
continue;
}
// get old Id
previousWrapperIdMap.put(wrapper.getId(), wrapper);
getModuleWrappers().add(wrapper);
wrapper.moveBy(offset.x, offset.y);
wrapper.setModule(wrapper.getModule());
int id = getUniqueIdForModuleWrapper();
wrapper.setId(id);
wrapper.getModule().setIndex(id);
wrapper.setBoard(this);
currentEmitterWrapper.getGraph().addModule(wrapper.getModule());
wrapper.getModule().setModuleGraph(currentEmitterWrapper.getGraph());
moduleContainer.addActor(wrapper);
copiedWrappers.add(wrapper);
}
// now let's connect the connections
for (NodeConnection connection : payload.connections) {
ModuleWrapper fromWrapper = previousWrapperIdMap.get(connection.fromModule.getId());
ModuleWrapper toWrapper = previousWrapperIdMap.get(connection.toModule.getId());
if (fromWrapper == null || toWrapper == null) {
continue;
}
makeConnection(fromWrapper, toWrapper, connection.fromSlot, connection.toSlot);
}
// now add groups
for (ModuleWrapperGroup group : payload.groups) {
ObjectSet<ModuleWrapper> newWrappers = new ObjectSet<>();
for (ModuleWrapper wrapper : group.getModuleWrappers()) {
ModuleWrapper newWrapper = previousWrapperIdMap.get(wrapper.getId());
if (newWrapper != null) {
newWrappers.add(newWrapper);
}
}
ModuleWrapperGroup newGroup = createGroupForWrappers(newWrappers);
newGroup.setText(group.getText());
newGroup.setColor(group.getColor());
}
setSelectedWrappers(copiedWrappers);
} catch (Exception e) {
System.out.println(e);
}
}
use of com.talosvfx.talos.editor.data.ModuleWrapperGroup in project talos by rockbite.
the class ModuleBoardWidget method getSelectedGroups.
private Array<ModuleWrapperGroup> getSelectedGroups() {
Array<ModuleWrapperGroup> groups = getGroups();
Array<ModuleWrapperGroup> selectedGroups = new Array<>();
ObjectSet<ModuleWrapper> wrappers = getSelectedWrappers();
for (ModuleWrapperGroup group : groups) {
boolean isFullyContained = true;
for (ModuleWrapper wrapper : group.getModuleWrappers()) {
if (!wrappers.contains(wrapper)) {
isFullyContained = false;
break;
}
}
if (isFullyContained) {
// add this group
selectedGroups.add(group);
}
}
return selectedGroups;
}
use of com.talosvfx.talos.editor.data.ModuleWrapperGroup in project talos by rockbite.
the class ModuleBoardWidget method deleteWrapper.
public void deleteWrapper(ModuleWrapper wrapper) {
getModuleWrappers().removeValue(wrapper, true);
for (int i = getCurrentConnections().size - 1; i >= 0; i--) {
if (getCurrentConnections().get(i).toModule == wrapper || getCurrentConnections().get(i).fromModule == wrapper) {
removeConnection(getCurrentConnections().get(i));
}
}
mainStage.getCurrentModuleGraph().removeModule(wrapper.getModule());
moduleContainer.removeActor(wrapper);
for (ModuleWrapperGroup group : getGroups()) {
group.removeWrapper(wrapper);
}
TalosMain.Instance().ProjectController().setDirty();
TalosMain.Instance().UIStage().PreviewWidget().unregisterDragPoints();
}
use of com.talosvfx.talos.editor.data.ModuleWrapperGroup in project talos by rockbite.
the class ProjectData method setFrom.
public void setFrom(ModuleBoardWidget moduleBoardWidget) {
final ObjectMap<ParticleEmitterWrapper, Array<ModuleWrapper>> moduleWrappers = moduleBoardWidget.moduleWrappers;
final ObjectMap<ParticleEmitterWrapper, Array<ModuleBoardWidget.NodeConnection>> nodeConnections = moduleBoardWidget.nodeConnections;
emitters.clear();
for (ParticleEmitterWrapper key : moduleWrappers.keys()) {
final EmitterData emitterData = new EmitterData();
emitterData.name = key.getName();
emitterData.sortPosition = key.getEmitter().getSortPosition();
emitterData.modules.addAll(moduleWrappers.get(key));
emitterData.isMuted = key.isMuted;
final Array<ModuleBoardWidget.NodeConnection> nodeConns = nodeConnections.get(key);
if (nodeConns != null) {
for (ModuleBoardWidget.NodeConnection nodeConn : nodeConns) {
emitterData.connections.add(new ConnectionData(nodeConn.fromModule.getId(), nodeConn.toModule.getId(), nodeConn.fromSlot, nodeConn.toSlot));
}
}
// add groups
for (ModuleWrapperGroup group : moduleBoardWidget.getGroups(key)) {
GroupData groupData = new GroupData();
groupData.text = group.getText();
groupData.modules = new Array<>();
groupData.color = group.getFrameColor().toFloatBits();
for (ModuleWrapper wrapper : group.getModuleWrappers()) {
groupData.modules.add(wrapper.getId());
}
emitterData.groups.add(groupData);
}
emitters.add(emitterData);
}
}
Aggregations