diff --git a/assets/configs/app.properties b/assets/configs/app.properties index 707c93aa..779e0e69 100644 --- a/assets/configs/app.properties +++ b/assets/configs/app.properties @@ -1 +1 @@ -version=0.0.7 \ No newline at end of file +version=0.0.8-SNAPSHOT \ No newline at end of file diff --git a/assets/plugins/plugin-9patch-0.0.7.jar b/assets/plugins/plugin-9patch-0.0.8.jar similarity index 64% rename from assets/plugins/plugin-9patch-0.0.7.jar rename to assets/plugins/plugin-9patch-0.0.8.jar index 87c86de8..c2d04d80 100644 Binary files a/assets/plugins/plugin-9patch-0.0.7.jar and b/assets/plugins/plugin-9patch-0.0.8.jar differ diff --git a/assets/plugins/plugin-performance-0.0.7.jar b/assets/plugins/plugin-performance-0.0.7.jar deleted file mode 100644 index 7cecb527..00000000 Binary files a/assets/plugins/plugin-performance-0.0.7.jar and /dev/null differ diff --git a/assets/plugins/plugin-performance-0.0.8.jar b/assets/plugins/plugin-performance-0.0.8.jar new file mode 100644 index 00000000..10408dde Binary files /dev/null and b/assets/plugins/plugin-performance-0.0.8.jar differ diff --git a/assets/plugins/plugin-skin-composer-0.0.7.jar b/assets/plugins/plugin-skin-composer-0.0.8.jar similarity index 87% rename from assets/plugins/plugin-skin-composer-0.0.7.jar rename to assets/plugins/plugin-skin-composer-0.0.8.jar index a6ace174..214b1eaf 100644 Binary files a/assets/plugins/plugin-skin-composer-0.0.7.jar and b/assets/plugins/plugin-skin-composer-0.0.8.jar differ diff --git a/assets/plugins/plugin-tiled-0.0.7.jar b/assets/plugins/plugin-tiled-0.0.8.jar similarity index 54% rename from assets/plugins/plugin-tiled-0.0.7.jar rename to assets/plugins/plugin-tiled-0.0.8.jar index cd334bd5..88119d0a 100644 Binary files a/assets/plugins/plugin-tiled-0.0.7.jar and b/assets/plugins/plugin-tiled-0.0.8.jar differ diff --git a/build.gradle b/build.gradle index 9a581206..7032239c 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ plugins { } group 'games.rednblack' -version '0.0.7' +version '0.0.8' repositories { mavenCentral() @@ -84,7 +84,7 @@ dependencies { exclude group: 'com.badlogicgames.gdx', module: 'gdx-backend-lwjgl' } implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" - implementation "com.badlogicgames.ashley:ashley:$ashleyVersion" + implementation "net.onedaybeard.artemis:artemis-odb:$artemisVersion" implementation "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion" diff --git a/gradle.properties b/gradle.properties index 9a91f0a6..ab931061 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ gdxVersion = 1.10.0 lwjgl3Version = 3.2.3 -ashleyVersion = 1.7.4 +artemisVersion = 2.3.0 spineVersion = 3.8.55.1 visuiVersion = 1.5.0 typingLabelVersion = 1.2.0 diff --git a/h2d-libgdx-spine-extension b/h2d-libgdx-spine-extension index 4442f02e..f0b66533 160000 --- a/h2d-libgdx-spine-extension +++ b/h2d-libgdx-spine-extension @@ -1 +1 @@ -Subproject commit 4442f02e7811fb1a1c7b7530448b4704d961daa4 +Subproject commit f0b66533a8e43b0018d4588a6cce9f59e1900a3f diff --git a/h2d-libgdx-talos-extension b/h2d-libgdx-talos-extension index 99011034..82421191 160000 --- a/h2d-libgdx-talos-extension +++ b/h2d-libgdx-talos-extension @@ -1 +1 @@ -Subproject commit 99011034e709c850c4a404fb0f175f09052c64be +Subproject commit 82421191ed3b52c510a4e4437a9ed22d9c571385 diff --git a/hyperlap2d-common-api b/hyperlap2d-common-api index 0f434390..4d2862b4 160000 --- a/hyperlap2d-common-api +++ b/hyperlap2d-common-api @@ -1 +1 @@ -Subproject commit 0f4343906ab88b2afbdb98385f09828568cf5f23 +Subproject commit 4d2862b4c59ca7509cc84f4915bb925cdd124608 diff --git a/hyperlap2d-runtime-libgdx b/hyperlap2d-runtime-libgdx index ffcd8e49..d8879a0f 160000 --- a/hyperlap2d-runtime-libgdx +++ b/hyperlap2d-runtime-libgdx @@ -1 +1 @@ -Subproject commit ffcd8e49c2cbbb567f2483e258828015f8bc16ca +Subproject commit d8879a0f6ee46a420b2d4f6ddf2321646b9cb96f diff --git a/plugin-9patch/build.gradle b/plugin-9patch/build.gradle index 8e55e48f..579dce9e 100644 --- a/plugin-9patch/build.gradle +++ b/plugin-9patch/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'games.rednblack' -version '0.0.7' +version '0.0.8' repositories { mavenCentral() @@ -12,8 +12,8 @@ repositories { dependencies { implementation "com.badlogicgames.gdx:gdx:$gdxVersion" - implementation "com.badlogicgames.ashley:ashley:$ashleyVersion" implementation "com.kotcrab.vis:vis-ui:$visuiVersion" + implementation "net.onedaybeard.artemis:artemis-odb:$artemisVersion" implementation 'net.mountainblade:modular:1.0' diff --git a/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/MainPanelMediator.java b/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/MainPanelMediator.java index 696912d8..97dcb759 100644 --- a/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/MainPanelMediator.java +++ b/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/MainPanelMediator.java @@ -1,6 +1,5 @@ package games.rednblack.editor.plugin.ninepatch; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.g2d.NinePatch; @@ -56,8 +55,8 @@ public class MainPanelMediator extends Mediator { convertImageToNinePatch(); break; case MainPanel.SAVE_CLICKED: - Entity entity = plugin.currEditingEntity; - NinePatchComponent ninePatchComponent = ComponentRetriever.get(entity, NinePatchComponent.class); + int entity = plugin.currEditingEntity; + NinePatchComponent ninePatchComponent = ComponentRetriever.get(entity, NinePatchComponent.class, plugin.getAPI().getEngine()); applyNewSplits(ninePatchComponent.textureRegionName, viewComponent.getSplits()); viewComponent.hide(); break; @@ -65,12 +64,12 @@ public class MainPanelMediator extends Mediator { } private void convertImageToNinePatch() { - Entity entity = plugin.currEditingEntity; - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + int entity = plugin.currEditingEntity; + MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class, plugin.getAPI().getEngine()); mainItemComponent.entityType = EntityFactory.NINE_PATCH; - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); + TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class, plugin.getAPI().getEngine()); String regionName = textureRegionComponent.regionName; - NinePatchComponent ninePatchComponent = plugin.getAPI().getEngine().createComponent(NinePatchComponent.class); + NinePatchComponent ninePatchComponent = plugin.getAPI().getEngine().edit(entity).create(NinePatchComponent.class); ninePatchComponent.textureRegionName = regionName; TextureAtlas.AtlasRegion newRegion = (TextureAtlas.AtlasRegion) textureRegionComponent.region; int[] splits = {0, 0, 0, 0}; @@ -78,7 +77,6 @@ public class MainPanelMediator extends Mediator { newRegion.names = new String[] {"split", "pad"}; newRegion.values = new int[][] {splits, pad}; ninePatchComponent.ninePatch = new NinePatch(textureRegionComponent.region, 0, 0, 0, 0); - entity.add(ninePatchComponent); //remove original image File originalImg = new File(plugin.getAPI().getProjectPath() + "/assets/orig/images/"+regionName+".png"); @@ -93,8 +91,8 @@ public class MainPanelMediator extends Mediator { } private void loadNinePatch() { - Entity entity = plugin.currEditingEntity; - NinePatchComponent ninePatchComponent = ComponentRetriever.get(entity, NinePatchComponent.class); + int entity = plugin.currEditingEntity; + NinePatchComponent ninePatchComponent = ComponentRetriever.get(entity, NinePatchComponent.class, plugin.getAPI().getEngine()); loadRegion(ninePatchComponent.textureRegionName); viewComponent.show(plugin.getAPI().getUIStage()); } diff --git a/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/NinePatchPlugin.java b/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/NinePatchPlugin.java index 3e179b69..76ee57b2 100644 --- a/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/NinePatchPlugin.java +++ b/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/NinePatchPlugin.java @@ -1,6 +1,5 @@ package games.rednblack.editor.plugin.ninepatch; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.renderer.components.MainItemComponent; import games.rednblack.editor.renderer.factory.EntityFactory; @@ -23,7 +22,7 @@ public class NinePatchPlugin extends H2DPluginAdapter { private MainPanelMediator performancePanelMediator; - public Entity currEditingEntity; + public int currEditingEntity; public NinePatchPlugin() { super(CLASS_NAME); @@ -38,10 +37,10 @@ public class NinePatchPlugin extends H2DPluginAdapter { } @Override - public void onDropDownOpen(Set selectedEntities, Array actionsSet) { + public void onDropDownOpen(Set selectedEntities, Array actionsSet) { if(selectedEntities.size() == 1) { - Entity entity = selectedEntities.stream().findFirst().get(); - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + int entity = selectedEntities.stream().findFirst().get(); + MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class, getAPI().getEngine()); if(mainItemComponent.entityType == EntityFactory.NINE_PATCH) { // it's our guy diff --git a/plugin-performance/build.gradle b/plugin-performance/build.gradle index 8e55e48f..579dce9e 100644 --- a/plugin-performance/build.gradle +++ b/plugin-performance/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'games.rednblack' -version '0.0.7' +version '0.0.8' repositories { mavenCentral() @@ -12,8 +12,8 @@ repositories { dependencies { implementation "com.badlogicgames.gdx:gdx:$gdxVersion" - implementation "com.badlogicgames.ashley:ashley:$ashleyVersion" implementation "com.kotcrab.vis:vis-ui:$visuiVersion" + implementation "net.onedaybeard.artemis:artemis-odb:$artemisVersion" implementation 'net.mountainblade:modular:1.0' diff --git a/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanel.java b/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanel.java index d9b63496..4fe9a831 100644 --- a/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanel.java +++ b/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanel.java @@ -1,6 +1,8 @@ package games.rednblack.editor.plugin.performance; -import com.badlogic.ashley.core.Engine; +import com.artemis.Aspect; +import com.artemis.EntitySubscription; +import com.artemis.utils.IntBag; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.profiling.GLProfiler; import com.kotcrab.vis.ui.widget.VisLabel; @@ -16,7 +18,7 @@ public class PerformancePanel extends UIDraggablePanel { private VisLabel entitiesCount, memoryLabel, fpsLbl, glCalls, drawCalls, shaderSwitch, textureBind, vertexCount; - private Engine engine; + private EntitySubscription entitySubscription; private final GLProfiler profiler; public PerformancePanel() { @@ -87,7 +89,7 @@ public class PerformancePanel extends UIDraggablePanel { @Override public void act(float delta) { super.act(delta); - entitiesCount.setText(engine.getEntities().size()); + entitiesCount.setText(entitySubscription.getEntities().size()); fpsLbl.setText(Gdx.graphics.getFramesPerSecond()); MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); long usedMemory = memoryUsage.getUsed() / (1024 * 1024); @@ -109,7 +111,8 @@ public class PerformancePanel extends UIDraggablePanel { profiler.reset(); } - public void setEngine(Engine engine) { - this.engine = engine; + public void setEngine(com.artemis.World engine) { + entitySubscription = engine.getAspectSubscriptionManager() + .get(Aspect.all()); } } \ No newline at end of file diff --git a/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanelMediator.java b/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanelMediator.java index 520d9f91..30cdea3a 100644 --- a/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanelMediator.java +++ b/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanelMediator.java @@ -1,6 +1,5 @@ package games.rednblack.editor.plugin.performance; -import com.badlogic.ashley.core.Engine; import games.rednblack.h2d.common.MsgAPI; import org.puremvc.java.interfaces.INotification; import org.puremvc.java.patterns.mediator.Mediator; @@ -33,7 +32,7 @@ public class PerformancePanelMediator extends Mediator { switch (notification.getName()) { case MsgAPI.SCENE_LOADED: viewComponent.initView(); - Engine engine = performancePlugin.getAPI().getEngine(); + com.artemis.World engine = performancePlugin.getAPI().getEngine(); viewComponent.setEngine(engine); break; case PerformancePlugin.PANEL_OPEN: diff --git a/plugin-skin-composer/build.gradle b/plugin-skin-composer/build.gradle index 02602a36..784a0c26 100644 --- a/plugin-skin-composer/build.gradle +++ b/plugin-skin-composer/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'games.rednblack' -version '0.0.7' +version '0.0.8' repositories { mavenCentral() @@ -12,8 +12,8 @@ repositories { dependencies { implementation "com.badlogicgames.gdx:gdx:$gdxVersion" - implementation "com.badlogicgames.ashley:ashley:$ashleyVersion" implementation "com.kotcrab.vis:vis-ui:$visuiVersion" + implementation "net.onedaybeard.artemis:artemis-odb:$artemisVersion" implementation 'net.mountainblade:modular:1.0' diff --git a/plugin-tiled/build.gradle b/plugin-tiled/build.gradle index 992bb055..bf2b3e9c 100644 --- a/plugin-tiled/build.gradle +++ b/plugin-tiled/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'games.rednblack' -version '0.0.7' +version '0.0.8' ext { pack = ["assets/textures", "assets/pack/", "tiled"] @@ -16,8 +16,8 @@ repositories { dependencies { implementation "com.badlogicgames.gdx:gdx:$gdxVersion" - implementation "com.badlogicgames.ashley:ashley:$ashleyVersion" implementation "com.kotcrab.vis:vis-ui:$visuiVersion" + implementation "net.onedaybeard.artemis:artemis-odb:$artemisVersion" implementation "com.esotericsoftware.spine:spine-libgdx:$spineVersion" diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPanel.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPanel.java index fc0552f5..55149c9b 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPanel.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPanel.java @@ -20,7 +20,6 @@ package games.rednblack.editor.plugin.tiled; import org.puremvc.java.interfaces.IFacade; -import com.badlogic.ashley.core.Engine; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.kotcrab.vis.ui.widget.VisLabel; import com.kotcrab.vis.ui.widget.VisTable; @@ -60,7 +59,7 @@ public class TiledPanel extends UIDraggablePanel { private SettingsTab settingsTab; private AutoGridTilesTab autoGridTilesTab; private VisTable mainTable; - private Engine engine; + private com.artemis.World engine; private ResourcesManager resourcesManager; private boolean isAutoGridTabSelected; @@ -246,7 +245,7 @@ public class TiledPanel extends UIDraggablePanel { mainTable.add(new VisLabel("no scenes open")).right(); } - public void setEngine(Engine engine) { + public void setEngine(com.artemis.World engine) { this.engine = engine; } diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPanelMediator.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPanelMediator.java index a1908d85..12ea4a57 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPanelMediator.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPanelMediator.java @@ -26,8 +26,6 @@ import games.rednblack.editor.renderer.data.TexturePackVO; import org.puremvc.java.interfaces.INotification; import org.puremvc.java.patterns.mediator.Mediator; -import com.badlogic.ashley.core.Engine; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.files.FileHandle; @@ -118,7 +116,7 @@ public class TiledPanelMediator extends Mediator { targetGrid = initTarget(targetGrid, viewComponent.getDropTable(), false); targetAutoGrid = initTarget(targetAutoGrid, viewComponent.getAutoGridDropTable(), true); - Engine engine = tiledPlugin.getAPI().getEngine(); + com.artemis.World engine = tiledPlugin.getAPI().getEngine(); viewComponent.setEngine(engine); viewComponent.setFixedPosition(); break; @@ -289,8 +287,8 @@ public class TiledPanelMediator extends Mediator { tiledPlugin.saveDataManager.save(); break; case TiledPlugin.ACTION_SET_GRID_SIZE_FROM_ITEM: - Entity observable = notification.getBody(); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(observable, DimensionsComponent.class); + int observable = notification.getBody(); + DimensionsComponent dimensionsComponent = ComponentRetriever.get(observable, DimensionsComponent.class, tiledPlugin.getAPI().getEngine()); tiledPlugin.dataToSave.setGrid(dimensionsComponent.width, dimensionsComponent.height); tiledPlugin.facade.sendNotification(TiledPlugin.GRID_CHANGED); break; diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPlugin.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPlugin.java index 3ddbf599..4902392b 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPlugin.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/TiledPlugin.java @@ -21,7 +21,6 @@ package games.rednblack.editor.plugin.tiled; import java.io.File; import java.util.Set; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.ui.Skin; @@ -156,7 +155,7 @@ public class TiledPlugin extends H2DPluginAdapter { } @Override - public void onDropDownOpen(Set selectedEntities, Array actionsSet) { + public void onDropDownOpen(Set selectedEntities, Array actionsSet) { if(selectedEntities.size() == 1) { actionsSet.add(ACTION_SET_GRID_SIZE_FROM_ITEM); } @@ -172,29 +171,29 @@ public class TiledPlugin extends H2DPluginAdapter { deleteTileTool = new DeleteTileTool(this); } - public Entity getPluginEntityWithParams(int row, int column) { - for (Entity entity : pluginAPI.getProjectEntities()) { + public int getPluginEntityWithParams(int row, int column) { + for (int entity : pluginAPI.getProjectEntities()) { if(!isTile(entity)) continue; boolean isEntityVisible = pluginAPI.isEntityVisible(entity); if (!isEntityVisible || !isOnCurrentSelectedLayer(entity)) continue; - currentEntityMainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + currentEntityMainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class, getAPI().getEngine()); currentEntityCustomVariables = currentEntityMainItemComponent.customVariables; if (currentEntityCustomVariables.getIntegerVariable(ROW) == row && currentEntityCustomVariables.getIntegerVariable(COLUMN) == column) { return entity; } } - return null; + return -1; } - public Entity getPluginEntityWithCoords(float x, float y) { - for (Entity entity : pluginAPI.getProjectEntities()) { + public int getPluginEntityWithCoords(float x, float y) { + for (int entity : pluginAPI.getProjectEntities()) { if (!isTile(entity)) continue; boolean isEntityVisible = pluginAPI.isEntityVisible(entity); if (!isEntityVisible || !isOnCurrentSelectedLayer(entity)) continue; - currentEntityTransformComponent = ComponentRetriever.get(entity, TransformComponent.class); + currentEntityTransformComponent = ComponentRetriever.get(entity, TransformComponent.class, getAPI().getEngine()); Rectangle tmp = new Rectangle( currentEntityTransformComponent.x, currentEntityTransformComponent.y, @@ -205,21 +204,21 @@ public class TiledPlugin extends H2DPluginAdapter { return entity; } } - return null; + return -1; } public float getPixelToWorld() { return pluginAPI.getSceneLoader().getRm().getProjectVO().pixelToWorld; } - public boolean isTile(Entity entity) { - if (entity == null) + public boolean isTile(int entity) { + if (entity == -1) return false; - return ComponentRetriever.get(entity, MainItemComponent.class).tags.contains(TILE_TAG); + return ComponentRetriever.get(entity, MainItemComponent.class, getAPI().getEngine()).tags.contains(TILE_TAG); } - public boolean isOnCurrentSelectedLayer(Entity entity) { - ZIndexComponent entityZComponent = ComponentRetriever.get(entity, ZIndexComponent.class); + public boolean isOnCurrentSelectedLayer(int entity) { + ZIndexComponent entityZComponent = ComponentRetriever.get(entity, ZIndexComponent.class, getAPI().getEngine()); return entityZComponent.layerName.equals(pluginAPI.getCurrentSelectedLayerName()); } @@ -274,8 +273,8 @@ public class TiledPlugin extends H2DPluginAdapter { public void applySelectedTileGridOffset() { pluginAPI.getProjectEntities().forEach(entity -> { if (!(isTile(entity))) return; - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class, getAPI().getEngine()); + TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class, getAPI().getEngine()); if (selectedTileVO.regionName.equals(textureRegionComponent.regionName)) { transformComponent.x -= selectedTileVO.gridOffset.x; transformComponent.y -= selectedTileVO.gridOffset.y; diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/manager/AutoGridTileManager.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/manager/AutoGridTileManager.java index fa10de33..ef0ab4be 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/manager/AutoGridTileManager.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/manager/AutoGridTileManager.java @@ -1,7 +1,5 @@ package games.rednblack.editor.plugin.tiled.manager; -import com.badlogic.ashley.core.Entity; - import games.rednblack.editor.plugin.tiled.TiledPlugin; import games.rednblack.editor.renderer.components.MainItemComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; @@ -27,8 +25,8 @@ public class AutoGridTileManager { } public void autoFill() { - for (Entity entity : tiledPlugin.getAPI().getProjectEntities()) { - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + for (int entity : tiledPlugin.getAPI().getProjectEntities()) { + MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class, tiledPlugin.getAPI().getEngine()); if (!mainItemComponent.tags.contains(TiledPlugin.AUTO_TILE_TAG)) { continue; } @@ -37,43 +35,43 @@ public class AutoGridTileManager { int c = 0; int val = 0; - Entity ul = tiledPlugin.getPluginEntityWithParams(row + 1, col - 1); - if (ul != null) { + int ul = tiledPlugin.getPluginEntityWithParams(row + 1, col - 1); + if (ul != -1) { c++; val += UL; } - Entity u = tiledPlugin.getPluginEntityWithParams(row + 1, col); - if (u != null) { + int u = tiledPlugin.getPluginEntityWithParams(row + 1, col); + if (u != -1) { c++; val += U; } - Entity ur = tiledPlugin.getPluginEntityWithParams(row + 1, col + 1); - if (ur != null) { + int ur = tiledPlugin.getPluginEntityWithParams(row + 1, col + 1); + if (ur != -1) { c++; val += UR; } - Entity r = tiledPlugin.getPluginEntityWithParams(row, col + 1); - if (r != null) { + int r = tiledPlugin.getPluginEntityWithParams(row, col + 1); + if (r != -1) { c++; val += R; } - Entity dr = tiledPlugin.getPluginEntityWithParams(row - 1, col + 1); - if (dr != null) { + int dr = tiledPlugin.getPluginEntityWithParams(row - 1, col + 1); + if (dr != -1) { c++; val += DR; } - Entity d = tiledPlugin.getPluginEntityWithParams(row - 1, col); - if (d != null) { + int d = tiledPlugin.getPluginEntityWithParams(row - 1, col); + if (d != -1) { c++; val += D; } - Entity dl = tiledPlugin.getPluginEntityWithParams(row - 1, col - 1); - if (dl != null) { + int dl = tiledPlugin.getPluginEntityWithParams(row - 1, col - 1); + if (dl != -1) { c++; val += DL; } - Entity l = tiledPlugin.getPluginEntityWithParams(row, col - 1); - if (l != null) { + int l = tiledPlugin.getPluginEntityWithParams(row, col - 1); + if (l != -1) { c++; val += L; } diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/DeleteTileTool.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/DeleteTileTool.java index d51b461b..abbcdf13 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/DeleteTileTool.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/DeleteTileTool.java @@ -5,7 +5,6 @@ import java.util.Set; import org.puremvc.java.interfaces.INotification; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -72,24 +71,24 @@ public class DeleteTileTool implements Tool { } @Override - public boolean itemMouseDown(Entity entity, float x, float y) { + public boolean itemMouseDown(int entity, float x, float y) { deleteEntityWithCoordinate(x, y); tiledPlugin.facade.sendNotification(TiledPlugin.AUTO_FILL_TILES); return true; } @Override - public void itemMouseUp(Entity entity, float x, float y) { + public void itemMouseUp(int entity, float x, float y) { tiledPlugin.facade.sendNotification(TiledPlugin.AUTO_FILL_TILES); } @Override - public void itemMouseDragged(Entity entity, float x, float y) { + public void itemMouseDragged(int entity, float x, float y) { deleteEntityWithCoordinate(x, y); } @Override - public void itemMouseDoubleClick(Entity entity, float x, float y) { + public void itemMouseDoubleClick(int entity, float x, float y) { } @@ -104,12 +103,12 @@ public class DeleteTileTool implements Tool { } @Override - public void keyDown(Entity entity, int keycode) { + public void keyDown(int entity, int keycode) { } @Override - public void keyUp(Entity entity, int keycode) { + public void keyUp(int entity, int keycode) { if(isHotswapped) { if(keycode == Input.Keys.SHIFT_LEFT || keycode == Input.Keys.SHIFT_RIGHT) { isHotswapped = false; @@ -118,8 +117,8 @@ public class DeleteTileTool implements Tool { } } - Set items = new HashSet<>(); - private void deleteEntity(Entity entity) { + Set items = new HashSet<>(); + private void deleteEntity(int entity) { if (tiledPlugin.isTile(entity) && tiledPlugin.isOnCurrentSelectedLayer(entity)) { items.clear(); items.add(entity); @@ -129,8 +128,8 @@ public class DeleteTileTool implements Tool { } private void deleteEntityWithCoordinate (float x, float y) { - Entity entity = tiledPlugin.getPluginEntityWithCoords(x, y); - if (entity != null) { + int entity = tiledPlugin.getPluginEntityWithCoords(x, y); + if (entity != -1) { deleteEntity(entity); } } diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/DrawTileTool.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/DrawTileTool.java index bf45e72b..3623c243 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/DrawTileTool.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/DrawTileTool.java @@ -2,7 +2,6 @@ package games.rednblack.editor.plugin.tiled.tools; import org.puremvc.java.interfaces.INotification; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -91,9 +90,9 @@ public class DrawTileTool implements Tool { } @Override - public boolean itemMouseDown(Entity entity, float x, float y) { + public boolean itemMouseDown(int entity, float x, float y) { initGridThings(); - if (entity == null) + if (entity == -1) drawTile(x, y); else drawOnEntity(entity); @@ -101,23 +100,23 @@ public class DrawTileTool implements Tool { } @Override - public void itemMouseUp(Entity entity, float x, float y) { + public void itemMouseUp(int entity, float x, float y) { tiledPlugin.facade.sendNotification(TiledPlugin.AUTO_FILL_TILES); } @Override - public void itemMouseDragged(Entity entity, float x, float y) { + public void itemMouseDragged(int entity, float x, float y) { drawTile(x, y); } @Override - public void itemMouseDoubleClick(Entity entity, float x, float y) { + public void itemMouseDoubleClick(int entity, float x, float y) { if (!tiledPlugin.isOnCurrentSelectedLayer(entity)) return; - if (entity != null && tiledPlugin.isTile(entity)) { + if (entity != -1 && tiledPlugin.isTile(entity)) { //rotate TransformCommandBuilder commandBuilder = new TransformCommandBuilder(); - commandBuilder.begin(entity); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + commandBuilder.begin(entity, tiledPlugin.getAPI().getEngine()); + TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class, tiledPlugin.getAPI().getEngine()); if (transformComponent.scaleX > 0 && transformComponent.scaleY > 0) { commandBuilder.setScale(transformComponent.scaleX * -1f, transformComponent.scaleY); } else if (transformComponent.scaleX < 0 && transformComponent.scaleY > 0) { @@ -142,7 +141,7 @@ public class DrawTileTool implements Tool { } @Override - public void keyDown(Entity entity, int keycode) { + public void keyDown(int entity, int keycode) { if(keycode == Input.Keys.SHIFT_LEFT || keycode == Input.Keys.SHIFT_RIGHT) { tiledPlugin.getAPI().toolHotSwap(tiledPlugin.deleteTileTool); tiledPlugin.deleteTileTool.setHotSwapped(); @@ -150,7 +149,7 @@ public class DrawTileTool implements Tool { } @Override - public void keyUp(Entity entity, int keycode) { + public void keyUp(int entity, int keycode) { } @@ -191,7 +190,7 @@ public class DrawTileTool implements Tool { currentDrawStrategy.drawTile(newX, newY, row, column); } - private void drawOnEntity(Entity entity) { + private void drawOnEntity(int entity) { chooseDrawStrategy(); currentDrawStrategy.updateTile(entity); } diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/AutoTileDrawStrategy.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/AutoTileDrawStrategy.java index 60007bba..d9874793 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/AutoTileDrawStrategy.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/AutoTileDrawStrategy.java @@ -1,7 +1,5 @@ package games.rednblack.editor.plugin.tiled.tools.drawStrategy; -import com.badlogic.ashley.core.Entity; - import games.rednblack.editor.plugin.tiled.TiledPlugin; import games.rednblack.editor.plugin.tiled.data.AutoTileVO; import games.rednblack.editor.renderer.components.MainItemComponent; @@ -22,8 +20,8 @@ public class AutoTileDrawStrategy extends BasicDrawStrategy { @Override public void drawTile(float x, float y, int row, int column) { - Entity underneathTile = tiledPlugin.getPluginEntityWithParams(row, column); - if (underneathTile != null) { + int underneathTile = tiledPlugin.getPluginEntityWithParams(row, column); + if (underneathTile != -1) { updateTile(underneathTile); return; } @@ -32,7 +30,7 @@ public class AutoTileDrawStrategy extends BasicDrawStrategy { temp.set(x, y); tileToDraw = selectTileToDraw(); if (itemFactory.createSimpleImage(tileToDraw + TiledPlugin.AUTO_TILE_DRAW_SUFFIX, temp)) { - Entity imageEntity = itemFactory.getCreatedEntity(); + int imageEntity = itemFactory.getCreatedEntity(); postProcessEntity(imageEntity, x, y, row, column); } } @@ -64,10 +62,10 @@ public class AutoTileDrawStrategy extends BasicDrawStrategy { } @Override - public void updateTile(Entity entity) { + public void updateTile(int entity) { if (!checkValidTile(entity)) return; - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class, tiledPlugin.getAPI().getEngine()); if (tiledPlugin.getSelectedAutoTileName().equals(mainItemComponent.customVariables.getStringVariable(TiledPlugin.ORIG_AUTO_TILE))) { // we only allow an update when the auto-tiles is different // firstly, it does not make any sense to randomly reselect another alternative tile @@ -75,7 +73,7 @@ public class AutoTileDrawStrategy extends BasicDrawStrategy { return; } - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); + TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class, tiledPlugin.getAPI().getEngine()); if (textureRegionComponent != null && textureRegionComponent.regionName != null) { // there is already other tile under this one String selectedAutoTileName = selectTileToDraw(); @@ -94,10 +92,10 @@ public class AutoTileDrawStrategy extends BasicDrawStrategy { } @Override - protected void postProcessEntity(Entity entity, float x, float y, int row, int column) { + protected void postProcessEntity(int entity, float x, float y, int row, int column) { super.postProcessEntity(entity, x, y, row, column); - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class, tiledPlugin.getAPI().getEngine()); mainItemComponent.tags.add(TiledPlugin.AUTO_TILE_TAG); mainItemComponent.setCustomVars(TiledPlugin.REGION, tileToDraw); mainItemComponent.setCustomVars(TiledPlugin.ORIG_AUTO_TILE, tiledPlugin.getSelectedAutoTileName()); diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/BasicDrawStrategy.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/BasicDrawStrategy.java index 583a4e8a..91cea066 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/BasicDrawStrategy.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/BasicDrawStrategy.java @@ -1,6 +1,5 @@ package games.rednblack.editor.plugin.tiled.tools.drawStrategy; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import games.rednblack.editor.plugin.tiled.TiledPlugin; import games.rednblack.editor.renderer.components.MainItemComponent; @@ -15,20 +14,20 @@ public abstract class BasicDrawStrategy implements IDrawStrategy { tiledPlugin = plugin; } - protected void postProcessEntity(Entity entity, float x, float y, int row, int column) { - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + protected void postProcessEntity(int entity, float x, float y, int row, int column) { + MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class, tiledPlugin.getAPI().getEngine()); mainItemComponent.tags.add(TiledPlugin.TILE_TAG); mainItemComponent.setCustomVars(TiledPlugin.ROW, Integer.toString(row)); mainItemComponent.setCustomVars(TiledPlugin.COLUMN, Integer.toString(column)); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class, tiledPlugin.getAPI().getEngine()); transformComponent.x = x; transformComponent.y = y; } - protected boolean checkValidTile(Entity entity) { + protected boolean checkValidTile(int entity) { return tiledPlugin.isOnCurrentSelectedLayer(entity) && tiledPlugin.isTile(entity) - && ComponentRetriever.get(entity, MainItemComponent.class).entityType == tiledPlugin.getSelectedTileType(); + && ComponentRetriever.get(entity, MainItemComponent.class, tiledPlugin.getAPI().getEngine()).entityType == tiledPlugin.getSelectedTileType(); } } diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/IDrawStrategy.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/IDrawStrategy.java index 41ee1ad1..4010ad0a 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/IDrawStrategy.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/IDrawStrategy.java @@ -1,8 +1,6 @@ package games.rednblack.editor.plugin.tiled.tools.drawStrategy; -import com.badlogic.ashley.core.Entity; - public interface IDrawStrategy { void drawTile(float x, float y, int row, int column); - void updateTile(Entity entity); + void updateTile(int entity); } diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/ImageDrawStrategy.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/ImageDrawStrategy.java index 44ee762b..eb791323 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/ImageDrawStrategy.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/ImageDrawStrategy.java @@ -1,7 +1,5 @@ package games.rednblack.editor.plugin.tiled.tools.drawStrategy; -import com.badlogic.ashley.core.Entity; - import games.rednblack.editor.plugin.tiled.TiledPlugin; import games.rednblack.editor.renderer.components.MainItemComponent; import games.rednblack.editor.renderer.components.TextureRegionComponent; @@ -18,8 +16,8 @@ public class ImageDrawStrategy extends BasicDrawStrategy { @Override public void drawTile(float x, float y, int row, int column) { - Entity underneathTile = tiledPlugin.getPluginEntityWithParams(row, column); - if (underneathTile != null) { + int underneathTile = tiledPlugin.getPluginEntityWithParams(row, column); + if (underneathTile != -1) { updateTile(underneathTile); return; } @@ -27,16 +25,16 @@ public class ImageDrawStrategy extends BasicDrawStrategy { IFactory itemFactory = tiledPlugin.getAPI().getItemFactory(); temp.set(x, y); if (itemFactory.createSimpleImage(tiledPlugin.getSelectedTileName(), temp)) { - Entity imageEntity = itemFactory.getCreatedEntity(); + int imageEntity = itemFactory.getCreatedEntity(); postProcessEntity(imageEntity, x, y, row, column); } } @Override - public void updateTile(Entity entity) { + public void updateTile(int entity) { if (!checkValidTile(entity)) return; - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); + TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class, tiledPlugin.getAPI().getEngine()); if (textureRegionComponent != null && textureRegionComponent.regionName != null) { // there is already other tile under this one if (!textureRegionComponent.regionName.equals(tiledPlugin.getSelectedTileName())) { @@ -46,7 +44,7 @@ public class ImageDrawStrategy extends BasicDrawStrategy { replaceRegionCommandBuilder.setRegionName(region); replaceRegionCommandBuilder.execute(tiledPlugin.facade); - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class, tiledPlugin.getAPI().getEngine()); mainItemComponent.tags.remove(TiledPlugin.AUTO_TILE_TAG); mainItemComponent.removeCustomVars(TiledPlugin.REGION); } diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/SpineDrawStrategy.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/SpineDrawStrategy.java index 22f51459..f4db4045 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/SpineDrawStrategy.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/SpineDrawStrategy.java @@ -1,6 +1,5 @@ package games.rednblack.editor.plugin.tiled.tools.drawStrategy; -import com.badlogic.ashley.core.Entity; import com.esotericsoftware.spine.Skeleton; import com.esotericsoftware.spine.SkeletonData; import com.esotericsoftware.spine.SkeletonJson; @@ -21,8 +20,8 @@ public class SpineDrawStrategy extends BasicDrawStrategy { @Override public void drawTile(float x, float y, int row, int column) { - Entity underneathTile = tiledPlugin.getPluginEntityWithParams(row, column); - if (underneathTile != null) { + int underneathTile = tiledPlugin.getPluginEntityWithParams(row, column); + if (underneathTile != -1) { updateTile(underneathTile); return; } @@ -31,16 +30,16 @@ public class SpineDrawStrategy extends BasicDrawStrategy { temp.set(x, y); if (itemFactory.createSpineAnimation(tiledPlugin.getSelectedTileName(), temp)) { - Entity imageEntity = itemFactory.getCreatedEntity(); + int imageEntity = itemFactory.getCreatedEntity(); postProcessEntity(imageEntity, x, y, row, column); } } @Override - public void updateTile(Entity entity) { + public void updateTile(int entity) { if (!checkValidTile(entity)) return; - SpineDataComponent spineDataComponent = ComponentRetriever.get(entity, SpineDataComponent.class); + SpineDataComponent spineDataComponent = ComponentRetriever.get(entity, SpineDataComponent.class, tiledPlugin.getAPI().getEngine()); if (!spineDataComponent.animationName.equals(tiledPlugin.getSelectedTileName())) { replaceSpineCommandBuilder.begin(entity); String animName = tiledPlugin.getSelectedTileName(); diff --git a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/SpriteDrawStrategy.java b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/SpriteDrawStrategy.java index f7719b00..d4b74dbe 100644 --- a/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/SpriteDrawStrategy.java +++ b/plugin-tiled/src/main/java/games/rednblack/editor/plugin/tiled/tools/drawStrategy/SpriteDrawStrategy.java @@ -1,6 +1,5 @@ package games.rednblack.editor.plugin.tiled.tools.drawStrategy; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.plugin.tiled.TiledPlugin; @@ -18,8 +17,8 @@ public class SpriteDrawStrategy extends BasicDrawStrategy { @Override public void drawTile(float x, float y, int row, int column) { - Entity underneathTile = tiledPlugin.getPluginEntityWithParams(row, column); - if (underneathTile != null) { + int underneathTile = tiledPlugin.getPluginEntityWithParams(row, column); + if (underneathTile != -1) { updateTile(underneathTile); return; } @@ -28,16 +27,16 @@ public class SpriteDrawStrategy extends BasicDrawStrategy { temp.set(x, y); if (itemFactory.createSpriteAnimation(tiledPlugin.getSelectedTileName(), temp)) { - Entity imageEntity = itemFactory.getCreatedEntity(); + int imageEntity = itemFactory.getCreatedEntity(); postProcessEntity(imageEntity, x, y, row, column); } } @Override - public void updateTile(Entity entity) { + public void updateTile(int entity) { if (!checkValidTile(entity)) return; - SpriteAnimationComponent spriteAnimationComponent = ComponentRetriever.get(entity, SpriteAnimationComponent.class); + SpriteAnimationComponent spriteAnimationComponent = ComponentRetriever.get(entity, SpriteAnimationComponent.class, tiledPlugin.getAPI().getEngine()); if (!spriteAnimationComponent.animationName.equals(tiledPlugin.getSelectedTileName())) { Array regions = getRegions(tiledPlugin.getSelectedTileName()); diff --git a/src/main/java/games/rednblack/editor/controller/commands/AddComponentToItemCommand.java b/src/main/java/games/rednblack/editor/controller/commands/AddComponentToItemCommand.java index d4a7d7fc..3aeefc62 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/AddComponentToItemCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/AddComponentToItemCommand.java @@ -1,7 +1,7 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Component; -import com.badlogic.ashley.core.Entity; +import com.artemis.Component; +import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; @@ -13,20 +13,20 @@ public class AddComponentToItemCommand extends EntityModifyRevertibleCommand { private static final String CLASS_NAME = "games.rednblack.editor.controller.commands.AddComponentToItemCommand"; public static final String DONE = CLASS_NAME + "DONE"; - private Entity entity; - private Component component; + private int entity; + private Class component; private void collectData() { Object[] payload = getNotification().getBody(); - entity = (Entity) payload[0]; - component = (Component) payload[1]; + entity = (int) payload[0]; + component = (Class) payload[1]; } @Override public void doAction() { collectData(); - entity.add(component); + Sandbox.getInstance().getEngine().edit(entity).create(component); HyperLap2DFacade.getInstance().sendNotification(DONE, entity); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); @@ -34,13 +34,14 @@ public class AddComponentToItemCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - entity.remove(component.getClass()); + Sandbox.getInstance().getEngine().edit(entity).remove(component); + Sandbox.getInstance().getEngine().process(); HyperLap2DFacade.getInstance().sendNotification(DONE, entity); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object[] payload(Entity entity, Component component) { + public static Object[] payload(int entity, Class component) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = component; diff --git a/src/main/java/games/rednblack/editor/controller/commands/AddSelectionCommand.java b/src/main/java/games/rednblack/editor/controller/commands/AddSelectionCommand.java index 0f201e64..61ed8716 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/AddSelectionCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/AddSelectionCommand.java @@ -20,7 +20,6 @@ package games.rednblack.editor.controller.commands; import java.util.Set; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.editor.utils.runtime.EntityUtils; @@ -39,18 +38,18 @@ public class AddSelectionCommand extends RevertibleCommand { public void doAction() { cancel(); if(entityIds == null) { - Set items = getNotification().getBody(); + Set items = getNotification().getBody(); entityIds = EntityUtils.getEntityId(items); } - Set items = EntityUtils.getByUniqueId(entityIds); + Set items = EntityUtils.getByUniqueId(entityIds); Sandbox.getInstance().getSelector().addSelections(items); facade.sendNotification(DONE); } @Override public void undoAction() { - Set items = EntityUtils.getByUniqueId(entityIds); + Set items = EntityUtils.getByUniqueId(entityIds); Sandbox.getInstance().getSelector().releaseSelections(items); facade.sendNotification(DONE); } diff --git a/src/main/java/games/rednblack/editor/controller/commands/AddToLibraryCommand.java b/src/main/java/games/rednblack/editor/controller/commands/AddToLibraryCommand.java index 41ea2a23..da876d34 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/AddToLibraryCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/AddToLibraryCommand.java @@ -18,7 +18,7 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.proxy.ProjectManager; @@ -43,11 +43,11 @@ public class AddToLibraryCommand extends RevertibleCommand { public void doAction() { Object[] payload = getNotification().getBody(); - Entity item = ((Entity) payload[0]); + int item = ((int) payload[0]); entityId = EntityUtils.getEntityId(item); createdLibraryItemName = (String) payload[1]; - MainItemComponent mainItemComponent = ComponentRetriever.get(item, MainItemComponent.class); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(item, MainItemComponent.class); if(createdLibraryItemName.length() > 0) { ProjectManager projectManager = HyperLap2DFacade.getInstance().retrieveProxy(ProjectManager.NAME); @@ -58,7 +58,7 @@ public class AddToLibraryCommand extends RevertibleCommand { } CompositeItemVO newVO = new CompositeItemVO(); - newVO.loadFromEntity(item); + newVO.loadFromEntity(item, sandbox.getEngine()); newVO.cleanIds(); libraryItems.put(createdLibraryItemName, newVO); @@ -86,14 +86,14 @@ public class AddToLibraryCommand extends RevertibleCommand { } facade.sendNotification(MsgAPI.LIBRARY_LIST_UPDATED); } else { - Entity entity = EntityUtils.getByUniqueId(entityId); - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + int entity = EntityUtils.getByUniqueId(entityId); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); mainItemComponent.libraryLink = prevName; facade.sendNotification(MsgAPI.ITEM_DATA_UPDATED); } } - public static Object payloadUnLink(Entity entity) { + public static Object payloadUnLink(int entity) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = ""; @@ -101,7 +101,7 @@ public class AddToLibraryCommand extends RevertibleCommand { return payload; } - public static Object payloadLink(Entity entity, String link) { + public static Object payloadLink(int entity, String link) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = link; diff --git a/src/main/java/games/rednblack/editor/controller/commands/ChangeOriginPointPosition.java b/src/main/java/games/rednblack/editor/controller/commands/ChangeOriginPointPosition.java index a3986501..80351608 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/ChangeOriginPointPosition.java +++ b/src/main/java/games/rednblack/editor/controller/commands/ChangeOriginPointPosition.java @@ -1,10 +1,10 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.SandboxCommand; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.command.TransformCommandBuilder; import games.rednblack.editor.view.ui.validator.FloatInputValidator; import games.rednblack.h2d.common.view.ui.dialog.MultipleInputDialog; @@ -17,14 +17,14 @@ public class ChangeOriginPointPosition extends SandboxCommand { public void execute(INotification notification) { super.execute(notification); - Entity entity = notification.getBody(); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + int entity = notification.getBody(); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); MultipleInputDialog dialog = new MultipleInputDialog("Origin Position", new String[]{"X : ", "Y : "}, false, new FloatInputValidator(), new MultipleInputDialogListener() { @Override public void finished(String[] input) { TransformCommandBuilder commandBuilder = new TransformCommandBuilder(); - commandBuilder.begin(entity); + commandBuilder.begin(entity, sandbox.getEngine()); commandBuilder.setOrigin(Float.parseFloat(input[0]), Float.parseFloat(input[1])); commandBuilder.execute(HyperLap2DFacade.getInstance()); } diff --git a/src/main/java/games/rednblack/editor/controller/commands/ChangePolygonVertexPositionCommand.java b/src/main/java/games/rednblack/editor/controller/commands/ChangePolygonVertexPositionCommand.java index 82252d02..5b2f4d97 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/ChangePolygonVertexPositionCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/ChangePolygonVertexPositionCommand.java @@ -7,6 +7,7 @@ import games.rednblack.editor.controller.commands.component.UpdatePolygonDataCom import games.rednblack.editor.renderer.components.PolygonComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.poly.PolygonUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.ui.followers.PolygonFollower; import games.rednblack.editor.view.ui.validator.FloatInputValidator; import games.rednblack.h2d.common.MsgAPI; @@ -36,7 +37,7 @@ public class ChangePolygonVertexPositionCommand extends SandboxCommand { @Override public void finished(String[] input) { Vector2[] points = follower.getOriginalPoints().toArray(new Vector2[0]); - PolygonComponent polygonComponent = ComponentRetriever.get(follower.getEntity(), PolygonComponent.class); + PolygonComponent polygonComponent = SandboxComponentRetriever.get(follower.getEntity(), PolygonComponent.class); points[anchor].set(Float.parseFloat(input[0]), Float.parseFloat(input[1])); // check if any of near lines intersect diff --git a/src/main/java/games/rednblack/editor/controller/commands/CompositeCameraChangeCommand.java b/src/main/java/games/rednblack/editor/controller/commands/CompositeCameraChangeCommand.java index 78a0b085..5fd775b0 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/CompositeCameraChangeCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/CompositeCameraChangeCommand.java @@ -18,9 +18,9 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.viewport.Viewport; import games.rednblack.editor.renderer.components.ParentNodeComponent; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.components.ViewPortComponent; @@ -43,8 +43,8 @@ public class CompositeCameraChangeCommand extends RevertibleCommand { @Override public void doAction() { cancel(); - Entity entity = getNotification().getBody(); - Entity oldEntity = sandbox.getCurrentViewingEntity(); + int entity = getNotification().getBody(); + int oldEntity = sandbox.getCurrentViewingEntity(); // check if entity is selected wasPrevSelected = sandbox.getSelector().isSelected(entity); @@ -52,21 +52,20 @@ public class CompositeCameraChangeCommand extends RevertibleCommand { if(enteringInto == null) enteringInto = EntityUtils.getEntityId(entity); if(previousViewEntityId == null) previousViewEntityId = EntityUtils.getEntityId(oldEntity); - ViewPortComponent viewPortComponent = ComponentRetriever.get(oldEntity, ViewPortComponent.class); + ViewPortComponent viewPortComponent = SandboxComponentRetriever.get(oldEntity, ViewPortComponent.class); Viewport currViewport = viewPortComponent.viewPort; - oldEntity.remove(ViewPortComponent.class); + sandbox.getEngine().edit(oldEntity).remove(ViewPortComponent.class); - ViewPortComponent newViewPortComponent = sandbox.getEngine().createComponent(ViewPortComponent.class); + ViewPortComponent newViewPortComponent = sandbox.getEngine().edit(entity).create(ViewPortComponent.class); newViewPortComponent.viewPort = currViewport; - entity.add(newViewPortComponent); sandbox.setCurrentViewingEntity(entity); sandbox.getSelector().clearSelections(); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - TransformComponent previousTransformComponent = ComponentRetriever.get(oldEntity, TransformComponent.class); - ParentNodeComponent parentNodeComponent = ComponentRetriever.get(entity, ParentNodeComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + TransformComponent previousTransformComponent = SandboxComponentRetriever.get(oldEntity, TransformComponent.class); + ParentNodeComponent parentNodeComponent = SandboxComponentRetriever.get(entity, ParentNodeComponent.class); if (parentNodeComponent == null || oldEntity != parentNodeComponent.parentEntity) previousTransformComponent.enableTransform(); transformComponent.disableTransform(); @@ -80,22 +79,21 @@ public class CompositeCameraChangeCommand extends RevertibleCommand { @Override public void undoAction() { - Entity oldEntity = EntityUtils.getByUniqueId(previousViewEntityId); - Entity currEntity = sandbox.getCurrentViewingEntity(); + int oldEntity = EntityUtils.getByUniqueId(previousViewEntityId); + int currEntity = sandbox.getCurrentViewingEntity(); - ViewPortComponent viewPortComponent = ComponentRetriever.get(currEntity, ViewPortComponent.class); + ViewPortComponent viewPortComponent = SandboxComponentRetriever.get(currEntity, ViewPortComponent.class); Viewport currViewport = viewPortComponent.viewPort; - currEntity.remove(ViewPortComponent.class); + sandbox.getEngine().edit(currEntity).remove(ViewPortComponent.class); - ViewPortComponent newViewPortComponent = sandbox.getEngine().createComponent(ViewPortComponent.class); + ViewPortComponent newViewPortComponent = sandbox.getEngine().edit(oldEntity).create(ViewPortComponent.class); newViewPortComponent.viewPort = currViewport; - oldEntity.add(newViewPortComponent); sandbox.setCurrentViewingEntity(oldEntity); facade.sendNotification(DONE, previousViewEntityId); - TransformComponent transformComponent = ComponentRetriever.get(currEntity, TransformComponent.class); - TransformComponent previousTransformComponent = ComponentRetriever.get(oldEntity, TransformComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(currEntity, TransformComponent.class); + TransformComponent previousTransformComponent = SandboxComponentRetriever.get(oldEntity, TransformComponent.class); previousTransformComponent.disableTransform(); transformComponent.enableTransform(); diff --git a/src/main/java/games/rednblack/editor/controller/commands/ConvertToButtonCommand.java b/src/main/java/games/rednblack/editor/controller/commands/ConvertToButtonCommand.java index 262f2800..44d1068c 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/ConvertToButtonCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/ConvertToButtonCommand.java @@ -18,7 +18,6 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.components.LayerMapComponent; import games.rednblack.editor.renderer.components.MainItemComponent; import games.rednblack.editor.renderer.components.additional.ButtonComponent; @@ -26,6 +25,7 @@ import games.rednblack.editor.renderer.data.LayerItemVO; import games.rednblack.editor.renderer.factory.EntityFactory; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import java.util.HashSet; @@ -37,10 +37,10 @@ public class ConvertToButtonCommand extends ConvertToCompositeCommand { @Override public void doAction() { - Entity entity; + int entity; - HashSet entities = (HashSet) sandbox.getSelector().getSelectedItems(); - Entity item = entities.iterator().next(); + HashSet entities = (HashSet) sandbox.getSelector().getSelectedItems(); + int item = entities.iterator().next(); if(entities.size() == 1 && EntityUtils.getType(item) == EntityFactory.COMPOSITE_TYPE) { entity = item; @@ -50,14 +50,14 @@ public class ConvertToButtonCommand extends ConvertToCompositeCommand { } //create layers - LayerMapComponent layerMapComponent = ComponentRetriever.get(entity, LayerMapComponent.class); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(entity, LayerMapComponent.class); layerMapComponent.addLayer(new LayerItemVO("normal")); layerMapComponent.addLayer(new LayerItemVO("pressed")); // adding button logic - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); mainItemComponent.tags.add("button"); - entity.add(new ButtonComponent()); + sandbox.getEngine().edit(entity).create(ButtonComponent.class); } @Override diff --git a/src/main/java/games/rednblack/editor/controller/commands/ConvertToCompositeCommand.java b/src/main/java/games/rednblack/editor/controller/commands/ConvertToCompositeCommand.java index cf3f6e5d..e3b72bfa 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/ConvertToCompositeCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/ConvertToCompositeCommand.java @@ -18,8 +18,8 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.factory.ItemFactory; @@ -50,14 +50,14 @@ public class ConvertToCompositeCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { // get entity list - HashSet entities = (HashSet) sandbox.getSelector().getSelectedItems(); + HashSet entities = (HashSet) sandbox.getSelector().getSelectedItems(); UILayerBoxMediator layerBoxMediator = facade.retrieveMediator(UILayerBoxMediator.NAME); if(layersBackup == null) { // backup layer data layersBackup = new HashMap<>(); - for(Entity entity: entities) { - ZIndexComponent zIndexComponent = ComponentRetriever.get(entity, ZIndexComponent.class); + for(int entity: entities) { + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(entity, ZIndexComponent.class); int tmpId = EntityUtils.getEntityId(entity); layersBackup.put(tmpId, zIndexComponent.layerName); } @@ -67,9 +67,8 @@ public class ConvertToCompositeCommand extends EntityModifyRevertibleCommand { Vector2 position = EntityUtils.getLeftBottomPoint(entities); //create new entity - Entity entity = ItemFactory.get().createCompositeItem(position); + int entity = ItemFactory.get().createCompositeItem(position); entityId = EntityUtils.getEntityId(entity); - sandbox.getEngine().addEntity(entity); // what was the parent component of entities parentEntityId = EntityUtils.getEntityId(sandbox.getCurrentViewingEntity()); @@ -78,26 +77,28 @@ public class ConvertToCompositeCommand extends EntityModifyRevertibleCommand { EntityUtils.changeParent(entities, entity); //reposition children - for(Entity childEntity: entities) { - TransformComponent transformComponent = ComponentRetriever.get(childEntity, TransformComponent.class); + for(int childEntity: entities) { + TransformComponent transformComponent = SandboxComponentRetriever.get(childEntity, TransformComponent.class); transformComponent.x -= position.x; transformComponent.y -=position.y; // put it on default layer - ZIndexComponent zIndexComponent = ComponentRetriever.get(childEntity, ZIndexComponent.class); + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(childEntity, ZIndexComponent.class); zIndexComponent.layerName = "Default"; } // recalculate composite size - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); Vector2 newSize = EntityUtils.getRightTopPoint(entities); dimensionsComponent.width = newSize.x; dimensionsComponent.height = newSize.y; dimensionsComponent.boundBox.set(0, 0, newSize.x, newSize.y); - ZIndexComponent zIndexComponent = ComponentRetriever.get(entity, ZIndexComponent.class); + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(entity, ZIndexComponent.class); zIndexComponent.layerName = layerBoxMediator.getCurrentSelectedLayerName(); + sandbox.getEngine().process(); + //let everyone know HyperLap2DFacade.getInstance().sendNotification(DONE); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.NEW_ITEM_ADDED, entity); @@ -110,11 +111,11 @@ public class ConvertToCompositeCommand extends EntityModifyRevertibleCommand { FollowersUIMediator followersUIMediator = HyperLap2DFacade.getInstance().retrieveMediator(FollowersUIMediator.NAME); //get the entity - Entity entity = EntityUtils.getByUniqueId(entityId); - Entity oldParentEntity = EntityUtils.getByUniqueId(parentEntityId); - if (entity == null || oldParentEntity == null) + int entity = EntityUtils.getByUniqueId(entityId); + int oldParentEntity = EntityUtils.getByUniqueId(parentEntityId); + if (entity == -1 || oldParentEntity == -1) return; - HashSet children = EntityUtils.getChildren(entity); + HashSet children = EntityUtils.getChildren(entity); if (children == null) return; // what will be the position diff of children? @@ -124,19 +125,20 @@ public class ConvertToCompositeCommand extends EntityModifyRevertibleCommand { EntityUtils.changeParent(children, oldParentEntity); //reposition children - for(Entity tmpEntity: children) { - TransformComponent transformComponent = ComponentRetriever.get(tmpEntity, TransformComponent.class); + for(int tmpEntity: children) { + TransformComponent transformComponent = SandboxComponentRetriever.get(tmpEntity, TransformComponent.class); transformComponent.x+=positionDiff.x; transformComponent.y+=positionDiff.y; // put layer data back - ZIndexComponent zIndexComponent = ComponentRetriever.get(entity, ZIndexComponent.class); + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(entity, ZIndexComponent.class); zIndexComponent.layerName = layersBackup.get(EntityUtils.getEntityId(tmpEntity)); } // remove composite followersUIMediator.removeFollower(entity); - sandbox.getEngine().removeEntity(entity); + sandbox.getEngine().delete(entity); + sandbox.getEngine().process(); HyperLap2DFacade.getInstance().sendNotification(DONE); diff --git a/src/main/java/games/rednblack/editor/controller/commands/CreateItemCommand.java b/src/main/java/games/rednblack/editor/controller/commands/CreateItemCommand.java index e7812b70..fcf998c8 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/CreateItemCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/CreateItemCommand.java @@ -18,8 +18,8 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.factory.EntityFactory; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.renderer.components.NodeComponent; @@ -43,11 +43,11 @@ public class CreateItemCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { - Entity entity = getNotification().getBody(); + int entity = getNotification().getBody(); if (serializedEntity != null) { EntityFactory factory = Sandbox.getInstance().sceneControl.sceneLoader.getEntityFactory(); - Entity parentEntity = Sandbox.getInstance().getCurrentViewingEntity(); + int parentEntity = Sandbox.getInstance().getCurrentViewingEntity(); entity = EntityUtils.getEntityFromJson(serializedEntity, entityType, factory, parentEntity); serializedEntity = null; } @@ -55,29 +55,29 @@ public class CreateItemCommand extends EntityModifyRevertibleCommand { entityId = EntityUtils.getEntityId(entity); entityType = EntityUtils.getType(entity); - sandbox.getEngine().addEntity(entity); - // z-index - NodeComponent nodeComponent = ComponentRetriever.get(Sandbox.getInstance().getCurrentViewingEntity(), NodeComponent.class); - ZIndexComponent zindexComponent = ComponentRetriever.get(entity, ZIndexComponent.class); + NodeComponent nodeComponent = SandboxComponentRetriever.get(Sandbox.getInstance().getCurrentViewingEntity(), NodeComponent.class); + ZIndexComponent zindexComponent = SandboxComponentRetriever.get(entity, ZIndexComponent.class); zindexComponent.setZIndex(nodeComponent.children.size); + sandbox.getEngine().process(); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.NEW_ITEM_ADDED, entity); - Set items = new HashSet<>(); + Set items = new HashSet<>(); items.add(entity); facade.sendNotification(MsgAPI.ACTION_SET_SELECTION, items); } @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); serializedEntity = EntityUtils.getJsonStringFromEntity(entity); FollowersUIMediator followersUIMediator = HyperLap2DFacade.getInstance().retrieveMediator(FollowersUIMediator.NAME); followersUIMediator.removeFollower(entity); - sandbox.getEngine().removeEntity(entity); + sandbox.getEngine().delete(entity); + sandbox.getEngine().process(); facade.sendNotification(MsgAPI.DELETE_ITEMS_COMMAND_DONE); } } diff --git a/src/main/java/games/rednblack/editor/controller/commands/CustomVariableModifyCommand.java b/src/main/java/games/rednblack/editor/controller/commands/CustomVariableModifyCommand.java index 8281e2c7..b4fe0ce4 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/CustomVariableModifyCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/CustomVariableModifyCommand.java @@ -1,9 +1,9 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.components.MainItemComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; /** * Created by CyberJoe on 11/6/2015. @@ -41,14 +41,14 @@ public class CustomVariableModifyCommand extends EntityModifyRevertibleCommand { } private void addVariable(String key, String value) { - Entity entity = EntityUtils.getByUniqueId(entityId); - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + int entity = EntityUtils.getByUniqueId(entityId); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); mainItemComponent.setCustomVars(key, value); } private void removeVariable(String key) { - Entity entity = EntityUtils.getByUniqueId(entityId); - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + int entity = EntityUtils.getByUniqueId(entityId); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); value = mainItemComponent.customVariables.getStringVariable(key); //storing the backup mainItemComponent.removeCustomVars(key); } @@ -57,7 +57,7 @@ public class CustomVariableModifyCommand extends EntityModifyRevertibleCommand { if(entityId == null) { // First time call, need to prepare the data and fetch payload Object[] payload = getNotification().getBody(); - Entity item = (Entity) payload[0]; + int item = (int) payload[0]; entityId = EntityUtils.getEntityId(item); key = (String) payload[2]; isAdding = false; @@ -68,7 +68,7 @@ public class CustomVariableModifyCommand extends EntityModifyRevertibleCommand { } } - public static Object addCustomVariable(Entity entity, String key, String value) { + public static Object addCustomVariable(int entity, String key, String value) { Object[] payload = new Object[4]; payload[0] = entity; payload[1] = true; // is adding type @@ -78,7 +78,7 @@ public class CustomVariableModifyCommand extends EntityModifyRevertibleCommand { return payload; } - public static Object removeCustomVariable(Entity entity, String key) { + public static Object removeCustomVariable(int entity, String key) { Object[] payload = new Object[3]; payload[0] = entity; payload[1] = true; diff --git a/src/main/java/games/rednblack/editor/controller/commands/CutItemsCommand.java b/src/main/java/games/rednblack/editor/controller/commands/CutItemsCommand.java index 03d8a3b3..eec2e310 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/CutItemsCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/CutItemsCommand.java @@ -18,8 +18,6 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Json; import games.rednblack.editor.utils.runtime.EntityUtils; import games.rednblack.h2d.common.MsgAPI; @@ -51,9 +49,10 @@ public class CutItemsCommand extends EntityModifyRevertibleCommand { public void undoAction() { Json json = new Json(); CompositeVO compositeVO = json.fromJson(CompositeVO.class, backup); - Set newEntitiesList = PasteItemsCommand.createEntitiesFromVO(compositeVO); + Set newEntitiesList = PasteItemsCommand.createEntitiesFromVO(compositeVO); - for (Entity entity : newEntitiesList) { + sandbox.getEngine().process(); + for (int entity : newEntitiesList) { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.NEW_ITEM_ADDED, entity); } diff --git a/src/main/java/games/rednblack/editor/controller/commands/DeleteItemsCommand.java b/src/main/java/games/rednblack/editor/controller/commands/DeleteItemsCommand.java index badc6f52..b637aa0b 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/DeleteItemsCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/DeleteItemsCommand.java @@ -18,7 +18,6 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Json; import games.rednblack.h2d.common.MsgAPI; @@ -39,11 +38,11 @@ public class DeleteItemsCommand extends EntityModifyRevertibleCommand { private Array entityIdsToDelete; private void backup() { - Set entitySet = new HashSet<>(); + Set entitySet = new HashSet<>(); if(entityIdsToDelete == null) { entityIdsToDelete = new Array<>(); entitySet = sandbox.getSelector().getSelectedItems(); - for(Entity entity: entitySet) { + for(int entity: entitySet) { entityIdsToDelete.add(EntityUtils.getEntityId(entity)); } } else { @@ -61,10 +60,11 @@ public class DeleteItemsCommand extends EntityModifyRevertibleCommand { FollowersUIMediator followersUIMediator = HyperLap2DFacade.getInstance().retrieveMediator(FollowersUIMediator.NAME); for (Integer entityId : entityIdsToDelete) { - Entity item = EntityUtils.getByUniqueId(entityId); + int item = EntityUtils.getByUniqueId(entityId); followersUIMediator.removeFollower(item); - sandbox.getEngine().removeEntity(item); + sandbox.getEngine().delete(item); } + sandbox.getEngine().process(); sandbox.getSelector().getCurrentSelection().clear(); @@ -75,18 +75,19 @@ public class DeleteItemsCommand extends EntityModifyRevertibleCommand { public void undoAction() { Json json = new Json(); CompositeVO compositeVO = json.fromJson(CompositeVO.class, backup); - Set newEntitiesList = PasteItemsCommand.createEntitiesFromVO(compositeVO); + Set newEntitiesList = PasteItemsCommand.createEntitiesFromVO(compositeVO); - for (Entity entity : newEntitiesList) { + sandbox.getEngine().process(); + for (int entity : newEntitiesList) { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.NEW_ITEM_ADDED, entity); } sandbox.getSelector().setSelections(newEntitiesList, true); } - public void setItemsToDelete(Set entities) { + public void setItemsToDelete(Set entities) { entityIdsToDelete = new Array<>(); - for(Entity entity: entities) { + for(int entity: entities) { entityIdsToDelete.add(EntityUtils.getEntityId(entity)); } } diff --git a/src/main/java/games/rednblack/editor/controller/commands/DeleteLayerAtomCommand.java b/src/main/java/games/rednblack/editor/controller/commands/DeleteLayerAtomCommand.java index 273753a9..514e0edd 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/DeleteLayerAtomCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/DeleteLayerAtomCommand.java @@ -1,9 +1,9 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.components.LayerMapComponent; import games.rednblack.editor.renderer.data.LayerItemVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; /** @@ -24,10 +24,8 @@ public class DeleteLayerAtomCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { - Entity viewingEntity = Sandbox.getInstance().getCurrentViewingEntity(); - LayerMapComponent layerMapComponent = ComponentRetriever.get(viewingEntity, LayerMapComponent.class); - - + int viewingEntity = Sandbox.getInstance().getCurrentViewingEntity(); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class); if(layerMapComponent.getLayers().size() > 1) { layerMapComponent.deleteLayer(layerName); @@ -38,8 +36,8 @@ public class DeleteLayerAtomCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity viewingEntity = Sandbox.getInstance().getCurrentViewingEntity(); - LayerMapComponent layerMapComponent = ComponentRetriever.get(viewingEntity, LayerMapComponent.class); + int viewingEntity = Sandbox.getInstance().getCurrentViewingEntity(); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class); layerMapComponent.addLayer(layerIndex, layerItemVO); } diff --git a/src/main/java/games/rednblack/editor/controller/commands/DeleteLayerCommand.java b/src/main/java/games/rednblack/editor/controller/commands/DeleteLayerCommand.java index 3e7d95a7..fe3c2c42 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/DeleteLayerCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/DeleteLayerCommand.java @@ -1,9 +1,9 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.components.NodeComponent; import games.rednblack.editor.renderer.components.ZIndexComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import java.util.HashSet; @@ -40,13 +40,13 @@ public class DeleteLayerCommand extends TransactiveCommand { facade.sendNotification(UNDONE, layerName); } - public Set getItemsByLayerName(String layerName) { - Set result = new HashSet<>(); - Entity viewingEntity = Sandbox.getInstance().getCurrentViewingEntity(); - NodeComponent nodeComponent = ComponentRetriever.get(viewingEntity, NodeComponent.class); + public Set getItemsByLayerName(String layerName) { + Set result = new HashSet<>(); + int viewingEntity = Sandbox.getInstance().getCurrentViewingEntity(); + NodeComponent nodeComponent = SandboxComponentRetriever.get(viewingEntity, NodeComponent.class); for(int i = 0; i < nodeComponent.children.size; i++) { - Entity child = nodeComponent.children.get(i); - ZIndexComponent zIndexComponent = ComponentRetriever.get(child, ZIndexComponent.class); + int child = nodeComponent.children.get(i); + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(child, ZIndexComponent.class); if(zIndexComponent.layerName.equals(layerName)) { result.add(child); } diff --git a/src/main/java/games/rednblack/editor/controller/commands/DeletePolygonVertexCommand.java b/src/main/java/games/rednblack/editor/controller/commands/DeletePolygonVertexCommand.java index e8cb223d..330ca96a 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/DeletePolygonVertexCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/DeletePolygonVertexCommand.java @@ -8,6 +8,7 @@ import games.rednblack.editor.controller.commands.component.UpdatePolygonDataCom import games.rednblack.editor.renderer.components.PolygonComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.poly.PolygonUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.ui.followers.PolygonFollower; import games.rednblack.h2d.common.MsgAPI; import org.puremvc.java.interfaces.INotification; @@ -31,7 +32,7 @@ public class DeletePolygonVertexCommand extends SandboxCommand { PolygonFollower follower = (PolygonFollower) payload[0]; int anchor = (int) payload[1]; - PolygonComponent polygonComponent = ComponentRetriever.get(follower.getEntity(), PolygonComponent.class); + PolygonComponent polygonComponent = SandboxComponentRetriever.get(follower.getEntity(), PolygonComponent.class); if(polygonComponent == null || polygonComponent.vertices == null || polygonComponent.vertices.length == 0) return; if(follower.getOriginalPoints().size() <= 3) return; diff --git a/src/main/java/games/rednblack/editor/controller/commands/EntityModifyRevertibleCommand.java b/src/main/java/games/rednblack/editor/controller/commands/EntityModifyRevertibleCommand.java index 632e66d7..9841e807 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/EntityModifyRevertibleCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/EntityModifyRevertibleCommand.java @@ -18,8 +18,6 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Engine; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.proxy.ProjectManager; @@ -29,6 +27,7 @@ import games.rednblack.editor.renderer.components.NodeComponent; import games.rednblack.editor.renderer.data.CompositeItemVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import java.util.HashMap; @@ -50,10 +49,10 @@ public abstract class EntityModifyRevertibleCommand extends RevertibleCommand { protected void postChange() { Integer parentId = EntityUtils.getEntityId(sandbox.getCurrentViewingEntity()); - Entity entity = EntityUtils.getByUniqueId(parentId); + int entity = EntityUtils.getByUniqueId(parentId); // Update item library data if it was in library - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); String link = mainItemComponent.libraryLink; if(link != null && link.length() > 0) { @@ -61,23 +60,23 @@ public abstract class EntityModifyRevertibleCommand extends RevertibleCommand { HashMap libraryItems = projectManager.currentProjectInfoVO.libraryItems; if (libraryItems.containsKey(mainItemComponent.libraryLink)) { CompositeItemVO itemVO = new CompositeItemVO(); - itemVO.loadFromEntity(entity); + itemVO.loadFromEntity(entity, sandbox.getEngine()); itemVO.cleanIds(); libraryItems.put(mainItemComponent.libraryLink, itemVO); } - Array linkedEntities = EntityUtils.getByLibraryLink(link); - for (Entity dependable : linkedEntities) { + Array linkedEntities = EntityUtils.getByLibraryLink(link); + for (int dependable : linkedEntities) { if(dependable == entity) continue; - NodeComponent nodeComponent = ComponentRetriever.get(dependable, NodeComponent.class); - for(Entity child: nodeComponent.children) { - sandbox.getEngine().removeEntity(child); + NodeComponent nodeComponent = SandboxComponentRetriever.get(dependable, NodeComponent.class); + for(int child: nodeComponent.children) { + sandbox.getEngine().delete(child); } nodeComponent.children.clear(); + sandbox.getEngine().process(); - Engine engine = sandbox.getSceneControl().sceneLoader.getEngine(); EntityFactory factory = sandbox.getSceneControl().sceneLoader.getEntityFactory(); - factory.initAllChildren(engine, dependable, libraryItems.get(link).composite); + factory.initAllChildren(dependable, libraryItems.get(link).composite); } } } diff --git a/src/main/java/games/rednblack/editor/controller/commands/ItemChildrenTransformCommand.java b/src/main/java/games/rednblack/editor/controller/commands/ItemChildrenTransformCommand.java index cc0baf6e..dac5ad18 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/ItemChildrenTransformCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/ItemChildrenTransformCommand.java @@ -1,8 +1,8 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.renderer.components.DimensionsComponent; @@ -20,19 +20,19 @@ public class ItemChildrenTransformCommand extends EntityModifyRevertibleCommand private HashMap prevPosMap = new HashMap<>(); private HashMap parentPositionAndSizeMap = new HashMap<>(); - private Entity entity; + private int entity; private Vector2 prevLo; private void doActionOnParent() { Array objects = getNotification().getBody(); Object[] itemData = objects.get(0); - Entity entity = (Entity) itemData[0]; + int entity = (int) itemData[0]; Vector2 newPos = (Vector2) itemData[1]; Vector2 newSize = (Vector2) itemData[2]; - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); Vector2 prevLocation = new Vector2(transformComponent.x, transformComponent.y); Vector2 prevSize = new Vector2(dimensionsComponent.width, dimensionsComponent.height); PositionSize positionSize = new PositionSize(prevLocation, prevSize); @@ -56,8 +56,8 @@ public class ItemChildrenTransformCommand extends EntityModifyRevertibleCommand Vector2 prevLocation = positionSize.position; Vector2 prevSize = positionSize.size; entity = EntityUtils.getByUniqueId(entityUniqueId); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); setState(transformComponent, prevLocation, dimensionsComponent, prevSize); // transformComponent.x = prevLocation.x; // transformComponent.y = prevLocation.y; @@ -77,9 +77,9 @@ public class ItemChildrenTransformCommand extends EntityModifyRevertibleCommand Array payload = notification.getBody(); for (int i = 1; i < payload.size; i++) { Object[] objectData = payload.get(i); - Entity entity = (Entity) objectData[0]; + int entity = (int) objectData[0]; Vector2 newPos = (Vector2) objectData[1]; - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); Vector2 prevPos = new Vector2(transformComponent.x, transformComponent.y); prevPosMap.put(EntityUtils.getEntityId(entity), prevPos); // EntityUtils.setPosition(entity, newPos); @@ -95,8 +95,8 @@ public class ItemChildrenTransformCommand extends EntityModifyRevertibleCommand for (Map.Entry entry : prevPosMap.entrySet()) { Integer entityUniqueId = entry.getKey(); Vector2 oldPosition = entry.getValue(); - Entity entity = EntityUtils.getByUniqueId(entityUniqueId); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + int entity = EntityUtils.getByUniqueId(entityUniqueId); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); transformComponent.x = oldPosition.x; transformComponent.y = oldPosition.y; } diff --git a/src/main/java/games/rednblack/editor/controller/commands/ItemTransformCommand.java b/src/main/java/games/rednblack/editor/controller/commands/ItemTransformCommand.java index 763e5b8c..2eec8d8d 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/ItemTransformCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/ItemTransformCommand.java @@ -1,12 +1,8 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; -import games.rednblack.editor.renderer.components.PolygonComponent; -import games.rednblack.editor.renderer.components.TextureRegionComponent; -import games.rednblack.editor.renderer.components.light.LightBodyComponent; -import games.rednblack.editor.renderer.components.physics.PhysicsBodyComponent; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.renderer.components.DimensionsComponent; @@ -26,7 +22,7 @@ public class ItemTransformCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { payload = getNotification().getBody(); - Entity entity = (Entity) payload.get(0); + int entity = (int) payload.get(0); Object[] newData = (Object[]) payload.get(2); entityId = EntityUtils.getEntityId(entity); @@ -37,8 +33,8 @@ public class ItemTransformCommand extends EntityModifyRevertibleCommand { Float newRotation = (Float) newData[3]; Vector2 newOrigin = (Vector2) newData[4]; - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); if(newPos != null) transformComponent.x = newPos.x; if(newPos != null) transformComponent.y = newPos.y; @@ -57,7 +53,7 @@ public class ItemTransformCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); Object[] prevData = (Object[]) payload.get(1); Vector2 prevPos = (Vector2) prevData[0]; @@ -66,8 +62,8 @@ public class ItemTransformCommand extends EntityModifyRevertibleCommand { Float prevRotation = (Float) prevData[3]; Vector2 prevOrigin = (Vector2) prevData[4]; - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); transformComponent.x = prevPos.x; transformComponent.y = prevPos.y; diff --git a/src/main/java/games/rednblack/editor/controller/commands/ItemsMoveCommand.java b/src/main/java/games/rednblack/editor/controller/commands/ItemsMoveCommand.java index ee564c09..675316ad 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/ItemsMoveCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/ItemsMoveCommand.java @@ -18,9 +18,9 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.renderer.components.TransformComponent; @@ -44,10 +44,10 @@ public class ItemsMoveCommand extends EntityModifyRevertibleCommand { for(int i = 0; i < payload.size; i++) { Object[] itemData = payload.get(i); - Entity entity = (Entity) itemData[0]; + int entity = (int) itemData[0]; Vector2 newLocation = (Vector2) itemData[1]; - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); Vector2 prevLocation = new Vector2(transformComponent.x, transformComponent.y); if(itemData.length > 2) { @@ -69,9 +69,9 @@ public class ItemsMoveCommand extends EntityModifyRevertibleCommand { Integer entityUniqueId = entry.getKey(); Vector2 prevLocation = entry.getValue(); - Entity entity = EntityUtils.getByUniqueId(entityUniqueId); + int entity = EntityUtils.getByUniqueId(entityUniqueId); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); transformComponent.x = prevLocation.x; transformComponent.y = prevLocation.y; diff --git a/src/main/java/games/rednblack/editor/controller/commands/LayerSwapCommand.java b/src/main/java/games/rednblack/editor/controller/commands/LayerSwapCommand.java index ef2d96e0..824683e0 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/LayerSwapCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/LayerSwapCommand.java @@ -18,10 +18,10 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.components.LayerMapComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; /** @@ -49,8 +49,8 @@ public class LayerSwapCommand extends EntityModifyRevertibleCommand { public void doAction() { backup(); - Entity viewingEntity = EntityUtils.getByUniqueId(entityId); - LayerMapComponent layerMapComponent = ComponentRetriever.get(viewingEntity, LayerMapComponent.class); + int viewingEntity = EntityUtils.getByUniqueId(entityId); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class); layerMapComponent.swap(sourceName, targetName); facade.sendNotification(DONE); @@ -59,8 +59,8 @@ public class LayerSwapCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity viewingEntity = EntityUtils.getByUniqueId(entityId); - LayerMapComponent layerMapComponent = ComponentRetriever.get(viewingEntity, LayerMapComponent.class); + int viewingEntity = EntityUtils.getByUniqueId(entityId); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class); layerMapComponent.swap(targetName, sourceName); facade.sendNotification(DONE); diff --git a/src/main/java/games/rednblack/editor/controller/commands/NewLayerCommand.java b/src/main/java/games/rednblack/editor/controller/commands/NewLayerCommand.java index 5ae95dd2..f8950032 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/NewLayerCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/NewLayerCommand.java @@ -1,9 +1,9 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.components.LayerMapComponent; import games.rednblack.editor.renderer.data.LayerItemVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; /** @@ -21,8 +21,8 @@ public class NewLayerCommand extends EntityModifyRevertibleCommand { int index = (int) payload[0]; layerName = (String) payload[1]; - Entity viewingEntity = Sandbox.getInstance().getCurrentViewingEntity(); - LayerMapComponent layerMapComponent = ComponentRetriever.get(viewingEntity, LayerMapComponent.class); + int viewingEntity = Sandbox.getInstance().getCurrentViewingEntity(); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class); LayerItemVO vo = new LayerItemVO(layerName); vo.isVisible = true; @@ -33,8 +33,8 @@ public class NewLayerCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity viewingEntity = Sandbox.getInstance().getCurrentViewingEntity(); - LayerMapComponent layerMapComponent = ComponentRetriever.get(viewingEntity, LayerMapComponent.class); + int viewingEntity = Sandbox.getInstance().getCurrentViewingEntity(); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class); layerMapComponent.deleteLayer(layerName); diff --git a/src/main/java/games/rednblack/editor/controller/commands/PasteItemsCommand.java b/src/main/java/games/rednblack/editor/controller/commands/PasteItemsCommand.java index 84eb7a02..b1ff2ea4 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/PasteItemsCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/PasteItemsCommand.java @@ -18,10 +18,10 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Json; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.renderer.components.TransformComponent; @@ -64,12 +64,13 @@ public class PasteItemsCommand extends EntityModifyRevertibleCommand { Json json = new Json(); CompositeVO compositeVO = json.fromJson(CompositeVO.class, (String) payload[1]); forceIdChange(compositeVO); - Set newEntitiesList = createEntitiesFromVO(compositeVO); - for (Entity entity : newEntitiesList) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + Set newEntitiesList = createEntitiesFromVO(compositeVO); + sandbox.getEngine().process(); + for (int entity : newEntitiesList) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); transformComponent.x += diff.x; transformComponent.y += diff.y; - ZIndexComponent zIndexComponent = ComponentRetriever.get(entity, ZIndexComponent.class); + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(entity, ZIndexComponent.class); // UILayerBoxMediator layerBoxMediator = facade.retrieveMediator(UILayerBoxMediator.NAME); zIndexComponent.layerName = layerBoxMediator.getCurrentSelectedLayerName(); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.NEW_ITEM_ADDED, entity); @@ -82,9 +83,10 @@ public class PasteItemsCommand extends EntityModifyRevertibleCommand { public void undoAction() { FollowersUIMediator followersUIMediator = HyperLap2DFacade.getInstance().retrieveMediator(FollowersUIMediator.NAME); for (Integer entityId : pastedEntityIds) { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); followersUIMediator.removeFollower(entity); - sandbox.getEngine().removeEntity(entity); + sandbox.getEngine().delete(entity); + sandbox.getEngine().process(); facade.sendNotification(MsgAPI.DELETE_ITEMS_COMMAND_DONE); } pastedEntityIds.clear(); @@ -98,62 +100,52 @@ public class PasteItemsCommand extends EntityModifyRevertibleCommand { } - public static Set createEntitiesFromVO(CompositeVO compositeVO) { - Set entities = new HashSet<>(); + public static Set createEntitiesFromVO(CompositeVO compositeVO) { + Set entities = new HashSet<>(); EntityFactory factory = Sandbox.getInstance().sceneControl.sceneLoader.getEntityFactory(); - Entity parentEntity = Sandbox.getInstance().getCurrentViewingEntity(); + int parentEntity = Sandbox.getInstance().getCurrentViewingEntity(); for (int i = 0; i < compositeVO.sImages.size(); i++) { - Entity child = factory.createEntity(parentEntity, compositeVO.sImages.get(i)); - Sandbox.getInstance().getEngine().addEntity(child); + int child = factory.createEntity(parentEntity, compositeVO.sImages.get(i)); entities.add(child); } for (int i = 0; i < compositeVO.sImage9patchs.size(); i++) { - Entity child = factory.createEntity(parentEntity, compositeVO.sImage9patchs.get(i)); - Sandbox.getInstance().getEngine().addEntity(child); + int child = factory.createEntity(parentEntity, compositeVO.sImage9patchs.get(i)); entities.add(child); } for (int i = 0; i < compositeVO.sLabels.size(); i++) { - Entity child = factory.createEntity(parentEntity, compositeVO.sLabels.get(i)); - Sandbox.getInstance().getEngine().addEntity(child); + int child = factory.createEntity(parentEntity, compositeVO.sLabels.get(i)); entities.add(child); } for (int i = 0; i < compositeVO.sParticleEffects.size(); i++) { - Entity child = factory.createEntity(parentEntity, compositeVO.sParticleEffects.get(i)); - Sandbox.getInstance().getEngine().addEntity(child); + int child = factory.createEntity(parentEntity, compositeVO.sParticleEffects.get(i)); entities.add(child); } for (int i = 0; i < compositeVO.sTalosVFX.size(); i++) { - Entity child = factory.createEntity(parentEntity, compositeVO.sTalosVFX.get(i)); - Sandbox.getInstance().getEngine().addEntity(child); + int child = factory.createEntity(parentEntity, compositeVO.sTalosVFX.get(i)); entities.add(child); } for (int i = 0; i < compositeVO.sLights.size(); i++) { - Entity child = factory.createEntity(parentEntity, compositeVO.sLights.get(i)); - Sandbox.getInstance().getEngine().addEntity(child); + int child = factory.createEntity(parentEntity, compositeVO.sLights.get(i)); entities.add(child); } for (int i = 0; i < compositeVO.sSpineAnimations.size(); i++) { - Entity child = factory.createEntity(parentEntity, compositeVO.sSpineAnimations.get(i)); - Sandbox.getInstance().getEngine().addEntity(child); + int child = factory.createEntity(parentEntity, compositeVO.sSpineAnimations.get(i)); entities.add(child); } for (int i = 0; i < compositeVO.sSpriteAnimations.size(); i++) { - Entity child = factory.createEntity(parentEntity, compositeVO.sSpriteAnimations.get(i)); - Sandbox.getInstance().getEngine().addEntity(child); + int child = factory.createEntity(parentEntity, compositeVO.sSpriteAnimations.get(i)); entities.add(child); } for (int i = 0; i < compositeVO.sColorPrimitives.size(); i++) { - Entity child = factory.createEntity(parentEntity, compositeVO.sColorPrimitives.get(i)); - Sandbox.getInstance().getEngine().addEntity(child); + int child = factory.createEntity(parentEntity, compositeVO.sColorPrimitives.get(i)); entities.add(child); } for (int i = 0; i < compositeVO.sComposites.size(); i++) { - Entity child = factory.createEntity(parentEntity, compositeVO.sComposites.get(i)); - Sandbox.getInstance().getEngine().addEntity(child); + int child = factory.createEntity(parentEntity, compositeVO.sComposites.get(i)); entities.add(child); - factory.initAllChildren(Sandbox.getInstance().getEngine(), child, compositeVO.sComposites.get(i).composite); + factory.initAllChildren(child, compositeVO.sComposites.get(i).composite); } return entities; diff --git a/src/main/java/games/rednblack/editor/controller/commands/ReleaseSelectionCommand.java b/src/main/java/games/rednblack/editor/controller/commands/ReleaseSelectionCommand.java index 0fd57f94..08b6cc35 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/ReleaseSelectionCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/ReleaseSelectionCommand.java @@ -22,7 +22,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.editor.utils.runtime.EntityUtils; @@ -40,7 +39,7 @@ public class ReleaseSelectionCommand extends RevertibleCommand { @Override public void doAction() { cancel(); - Set items = new HashSet<>(getNotification().>getBody()); + Set items = new HashSet<>(getNotification().>getBody()); Sandbox.getInstance().getSelector().releaseSelections(items); entityIds = EntityUtils.getEntityId(items); @@ -50,7 +49,7 @@ public class ReleaseSelectionCommand extends RevertibleCommand { @Override public void undoAction() { - Set items = EntityUtils.getByUniqueId(entityIds); + Set items = EntityUtils.getByUniqueId(entityIds); Sandbox.getInstance().getSelector().addSelections(items); facade.sendNotification(DONE); diff --git a/src/main/java/games/rednblack/editor/controller/commands/RemoveComponentFromItemCommand.java b/src/main/java/games/rednblack/editor/controller/commands/RemoveComponentFromItemCommand.java index f9b69140..c8f72024 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/RemoveComponentFromItemCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/RemoveComponentFromItemCommand.java @@ -1,9 +1,10 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Component; -import com.badlogic.ashley.core.Entity; -import games.rednblack.editor.renderer.components.RemovableComponent; +import com.artemis.Component; +import games.rednblack.editor.renderer.components.RemovableObject; +import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.ComponentCloner; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; @@ -15,23 +16,25 @@ public class RemoveComponentFromItemCommand extends EntityModifyRevertibleComman private static final String CLASS_NAME = "games.rednblack.editor.controller.commands.RemoveComponentFromItemCommand"; public static final String DONE = CLASS_NAME + "DONE"; - private Entity entity; + private int entity; private Component component; + private Class componentClass; private void collectData() { Object[] payload = getNotification().getBody(); - entity = (Entity) payload[0]; - Class componentClass = (Class) payload[1]; - component = ComponentCloner.get(entity.getComponent(componentClass)); + entity = (int) payload[0]; + componentClass = (Class) payload[1]; + component = ComponentCloner.get(SandboxComponentRetriever.get(entity, componentClass)); } @Override public void doAction() { collectData(); - if (component instanceof RemovableComponent) { - ((RemovableComponent) component).onRemove(); + if (component instanceof RemovableObject) { + ((RemovableObject) component).onRemove(); } - entity.remove(component.getClass()); + sandbox.getEngine().edit(entity).remove(component.getClass()); + sandbox.getEngine().process(); HyperLap2DFacade.getInstance().sendNotification(DONE, entity); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); @@ -39,15 +42,16 @@ public class RemoveComponentFromItemCommand extends EntityModifyRevertibleComman @Override public void undoAction() { - if (entity.getComponent(component.getClass()) == null) { - entity.add(component); + if (SandboxComponentRetriever.get(entity, component.getClass()) == null) { + Component newComponent = sandbox.getEngine().edit(entity).create(componentClass); + ComponentCloner.set(newComponent, component); } HyperLap2DFacade.getInstance().sendNotification(DONE, entity); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object[] payload(Entity entity, Class componentClass) { + public static Object[] payload(int entity, Class componentClass) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = componentClass; diff --git a/src/main/java/games/rednblack/editor/controller/commands/RenameLayerCommand.java b/src/main/java/games/rednblack/editor/controller/commands/RenameLayerCommand.java index a0cef5d7..bb0623f3 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/RenameLayerCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/RenameLayerCommand.java @@ -18,11 +18,11 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.components.LayerMapComponent; import games.rednblack.editor.renderer.components.NodeComponent; import games.rednblack.editor.renderer.components.ZIndexComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; /** @@ -57,9 +57,9 @@ public class RenameLayerCommand extends EntityModifyRevertibleCommand { } private void renameLayer(String fromName, String toName) { - Entity viewEntity = Sandbox.getInstance().getCurrentViewingEntity(); - NodeComponent nodeComponent = ComponentRetriever.get(viewEntity, NodeComponent.class); - LayerMapComponent layerMapComponent = ComponentRetriever.get(viewEntity, LayerMapComponent.class); + int viewEntity = Sandbox.getInstance().getCurrentViewingEntity(); + NodeComponent nodeComponent = SandboxComponentRetriever.get(viewEntity, NodeComponent.class); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewEntity, LayerMapComponent.class); if (layerMapComponent.getLayer(toName) != null) { cancel(); @@ -68,8 +68,8 @@ public class RenameLayerCommand extends EntityModifyRevertibleCommand { layerMapComponent.rename(fromName, toName); - for(Entity childEntity: nodeComponent.children) { - ZIndexComponent zIndexComponent = ComponentRetriever.get(childEntity, ZIndexComponent.class); + for(int childEntity: nodeComponent.children) { + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(childEntity, ZIndexComponent.class); if(zIndexComponent.layerName.equals(fromName)) { zIndexComponent.layerName = toName; } diff --git a/src/main/java/games/rednblack/editor/controller/commands/SetSelectionCommand.java b/src/main/java/games/rednblack/editor/controller/commands/SetSelectionCommand.java index 31b2a10f..297b5221 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/SetSelectionCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/SetSelectionCommand.java @@ -22,8 +22,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.Array; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.editor.renderer.components.NodeComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; @@ -42,10 +42,10 @@ public class SetSelectionCommand extends RevertibleCommand { @Override public void doAction() { cancel(); - HashSet previousSelection = new HashSet<>(Sandbox.getInstance().getSelector().getSelectedItems()); + HashSet previousSelection = new HashSet<>(Sandbox.getInstance().getSelector().getSelectedItems()); previousSelectionIds = EntityUtils.getEntityId(previousSelection); - Set items = getNotification().getBody(); + Set items = getNotification().getBody(); if(items == null) { // deselect all @@ -55,10 +55,10 @@ public class SetSelectionCommand extends RevertibleCommand { } // check if items are in viewable element, if no - cancel - NodeComponent nodeComponent = ComponentRetriever.get(sandbox.getCurrentViewingEntity(), NodeComponent.class); - for (Iterator iterator = items.iterator(); iterator.hasNext();) { - Entity item = iterator.next(); - if(!nodeComponent.children.contains(item, true)) { + NodeComponent nodeComponent = SandboxComponentRetriever.get(sandbox.getCurrentViewingEntity(), NodeComponent.class); + for (Iterator iterator = items.iterator(); iterator.hasNext();) { + int item = iterator.next(); + if(!nodeComponent.children.contains(item, false)) { iterator.remove(); } } diff --git a/src/main/java/games/rednblack/editor/controller/commands/UpdateEntityComponentsCommand.java b/src/main/java/games/rednblack/editor/controller/commands/UpdateEntityComponentsCommand.java index d0f9ee9d..61d2527f 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/UpdateEntityComponentsCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/UpdateEntityComponentsCommand.java @@ -18,9 +18,9 @@ package games.rednblack.editor.controller.commands; -import com.badlogic.ashley.core.Component; -import com.badlogic.ashley.core.Entity; +import com.artemis.Component; import com.badlogic.gdx.utils.Array; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.renderer.utils.ComponentRetriever; @@ -39,13 +39,13 @@ public class UpdateEntityComponentsCommand extends EntityModifyRevertibleCommand public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; entityId = EntityUtils.getEntityId(entity); Array components = (Array) payload[1]; for(int i = 0; i < components.size; i++) { //backup the original component - Component originalComponent = ComponentRetriever.get(entity, components.get(i).getClass()); + Component originalComponent = SandboxComponentRetriever.get(entity, components.get(i).getClass()); backupComponents.add(ComponentCloner.get(originalComponent)); //now modify the entity component from provided data @@ -59,9 +59,9 @@ public class UpdateEntityComponentsCommand extends EntityModifyRevertibleCommand @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); for(int i = 0; i < backupComponents.size; i++) { - Component entityComponent = ComponentRetriever.get(entity, backupComponents.get(i).getClass()); + Component entityComponent = SandboxComponentRetriever.get(entity, backupComponents.get(i).getClass()); ComponentCloner.set(entityComponent, backupComponents.get(i)); } diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceRegionCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceRegionCommand.java index 6ddb466c..c70ab466 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceRegionCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceRegionCommand.java @@ -1,6 +1,5 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.graphics.g2d.TextureRegion; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; @@ -10,6 +9,7 @@ import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.data.ProjectInfoVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.common.MsgAPI; @@ -22,15 +22,15 @@ public class ReplaceRegionCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; String regionName = (String) payload[1]; TextureRegion region = (TextureRegion) payload[2]; entityId = EntityUtils.getEntityId(entity); - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); - DimensionsComponent size = ComponentRetriever.get(entity, DimensionsComponent.class); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + TextureRegionComponent textureRegionComponent = SandboxComponentRetriever.get(entity, TextureRegionComponent.class); + DimensionsComponent size = SandboxComponentRetriever.get(entity, DimensionsComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); backupRegionName = textureRegionComponent.regionName; backupRegion = textureRegionComponent.region; @@ -50,11 +50,11 @@ public class ReplaceRegionCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); - DimensionsComponent size = ComponentRetriever.get(entity, DimensionsComponent.class); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + TextureRegionComponent textureRegionComponent = SandboxComponentRetriever.get(entity, TextureRegionComponent.class); + DimensionsComponent size = SandboxComponentRetriever.get(entity, DimensionsComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); textureRegionComponent.regionName = backupRegionName; textureRegionComponent.region = backupRegion; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceSpineCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceSpineCommand.java index ff01a67b..225f468e 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceSpineCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceSpineCommand.java @@ -1,6 +1,5 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import com.esotericsoftware.spine.*; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; @@ -9,6 +8,7 @@ import games.rednblack.editor.renderer.components.SpineDataComponent; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.h2d.extention.spine.SpineObjectComponent; @@ -22,7 +22,7 @@ public class ReplaceSpineCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; String animName = (String) payload[1]; SkeletonJson skeletonJson = (SkeletonJson) payload[2]; Skeleton skeleton = (Skeleton) payload[3]; @@ -30,10 +30,10 @@ public class ReplaceSpineCommand extends EntityModifyRevertibleCommand { entityId = EntityUtils.getEntityId(entity); - SpineDataComponent spineDataComponent = ComponentRetriever.get(entity, SpineDataComponent.class); - SpineObjectComponent spineObjectComponent = ComponentRetriever.get(entity, SpineObjectComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + SpineDataComponent spineDataComponent = SandboxComponentRetriever.get(entity, SpineDataComponent.class); + SpineObjectComponent spineObjectComponent = SandboxComponentRetriever.get(entity, SpineObjectComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); backupAnimName = spineDataComponent.animationName; backupSkeletonJson = spineObjectComponent.skeletonJson; @@ -63,12 +63,12 @@ public class ReplaceSpineCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); - SpineDataComponent spineDataComponent = ComponentRetriever.get(entity, SpineDataComponent.class); - SpineObjectComponent spineObjectComponent = ComponentRetriever.get(entity, SpineObjectComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + SpineDataComponent spineDataComponent = SandboxComponentRetriever.get(entity, SpineDataComponent.class); + SpineObjectComponent spineObjectComponent = SandboxComponentRetriever.get(entity, SpineObjectComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); spineDataComponent.animationName = backupAnimName; spineObjectComponent.skeletonJson = backupSkeletonJson; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceSpriteAnimationCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceSpriteAnimationCommand.java index 2d8eb4af..2f81422e 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceSpriteAnimationCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/ReplaceSpriteAnimationCommand.java @@ -1,6 +1,5 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.utils.Array; @@ -15,6 +14,7 @@ import games.rednblack.editor.renderer.data.FrameRange; import games.rednblack.editor.renderer.data.ProjectInfoVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.common.MsgAPI; @@ -27,17 +27,17 @@ public class ReplaceSpriteAnimationCommand extends EntityModifyRevertibleCommand @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; String animName = (String) payload[1]; Array regions = (Array) payload[2]; entityId = EntityUtils.getEntityId(entity); - SpriteAnimationComponent spriteAnimationComponent = ComponentRetriever.get(entity, SpriteAnimationComponent.class); - SpriteAnimationStateComponent spriteAnimationStateComponent = ComponentRetriever.get(entity, SpriteAnimationStateComponent.class); - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); - DimensionsComponent size = ComponentRetriever.get(entity, DimensionsComponent.class); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + SpriteAnimationComponent spriteAnimationComponent = SandboxComponentRetriever.get(entity, SpriteAnimationComponent.class); + SpriteAnimationStateComponent spriteAnimationStateComponent = SandboxComponentRetriever.get(entity, SpriteAnimationStateComponent.class); + TextureRegionComponent textureRegionComponent = SandboxComponentRetriever.get(entity, TextureRegionComponent.class); + DimensionsComponent size = SandboxComponentRetriever.get(entity, DimensionsComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); backupAnimName = spriteAnimationComponent.animationName; backupAnimRegions = spriteAnimationStateComponent.allRegions; @@ -67,13 +67,13 @@ public class ReplaceSpriteAnimationCommand extends EntityModifyRevertibleCommand @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); - SpriteAnimationComponent spriteAnimationComponent = ComponentRetriever.get(entity, SpriteAnimationComponent.class); - SpriteAnimationStateComponent spriteAnimationStateComponent = ComponentRetriever.get(entity, SpriteAnimationStateComponent.class); - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); - DimensionsComponent size = ComponentRetriever.get(entity, DimensionsComponent.class); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + SpriteAnimationComponent spriteAnimationComponent = SandboxComponentRetriever.get(entity, SpriteAnimationComponent.class); + SpriteAnimationStateComponent spriteAnimationStateComponent = SandboxComponentRetriever.get(entity, SpriteAnimationStateComponent.class); + TextureRegionComponent textureRegionComponent = SandboxComponentRetriever.get(entity, TextureRegionComponent.class); + DimensionsComponent size = SandboxComponentRetriever.get(entity, DimensionsComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); spriteAnimationComponent.animationName = backupAnimName; spriteAnimationComponent.frameRangeMap.clear(); diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateCompositeDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateCompositeDataCommand.java index c72f639e..a7cb80e2 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateCompositeDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateCompositeDataCommand.java @@ -1,6 +1,5 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.renderer.components.CompositeTransformComponent; @@ -8,6 +7,7 @@ import games.rednblack.editor.renderer.components.MainItemComponent; import games.rednblack.editor.renderer.data.CompositeItemVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; public class UpdateCompositeDataCommand extends EntityModifyRevertibleCommand { @@ -17,14 +17,14 @@ public class UpdateCompositeDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; CompositeItemVO vo = (CompositeItemVO) payload[1]; entityId = EntityUtils.getEntityId(entity); backup = new CompositeItemVO(); - backup.loadFromEntity(entity); + backup.loadFromEntity(entity, sandbox.getEngine()); - CompositeTransformComponent transformComponent = ComponentRetriever.get(entity, CompositeTransformComponent.class); + CompositeTransformComponent transformComponent = SandboxComponentRetriever.get(entity, CompositeTransformComponent.class); transformComponent.automaticResize = vo.automaticResize; transformComponent.scissorsEnabled = vo.scissorsEnabled; transformComponent.renderToFBO = vo.renderToFBO; @@ -32,16 +32,16 @@ public class UpdateCompositeDataCommand extends EntityModifyRevertibleCommand { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); if (!transformComponent.renderToFBO) { - String tag = ComponentRetriever.get(entity, MainItemComponent.class).itemIdentifier; + String tag = SandboxComponentRetriever.get(entity, MainItemComponent.class).itemIdentifier; sandbox.getSceneControl().sceneLoader.getFrameBufferManager().dispose(tag); } } @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); - CompositeTransformComponent transformComponent = ComponentRetriever.get(entity, CompositeTransformComponent.class); + CompositeTransformComponent transformComponent = SandboxComponentRetriever.get(entity, CompositeTransformComponent.class); transformComponent.automaticResize = backup.automaticResize; transformComponent.scissorsEnabled = backup.scissorsEnabled; transformComponent.renderToFBO = backup.renderToFBO; @@ -49,12 +49,12 @@ public class UpdateCompositeDataCommand extends EntityModifyRevertibleCommand { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); if (!transformComponent.renderToFBO) { - String tag = ComponentRetriever.get(entity, MainItemComponent.class).itemIdentifier; + String tag = SandboxComponentRetriever.get(entity, MainItemComponent.class).itemIdentifier; sandbox.getSceneControl().sceneLoader.getFrameBufferManager().dispose(tag); } } - public static Object payload(Entity entity, CompositeItemVO vo) { + public static Object payload(int entity, CompositeItemVO vo) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = vo; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateImageItemDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateImageItemDataCommand.java index 9d06cbf8..962fe195 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateImageItemDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateImageItemDataCommand.java @@ -1,15 +1,13 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.renderer.components.DimensionsComponent; -import games.rednblack.editor.renderer.components.PolygonComponent; import games.rednblack.editor.renderer.components.TextureRegionComponent; -import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.data.SimpleImageVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; public class UpdateImageItemDataCommand extends EntityModifyRevertibleCommand { @@ -20,11 +18,11 @@ public class UpdateImageItemDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; SimpleImageVO vo = (SimpleImageVO) payload[1]; entityId = EntityUtils.getEntityId(entity); - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); + TextureRegionComponent textureRegionComponent = SandboxComponentRetriever.get(entity, TextureRegionComponent.class); backup = new SimpleImageVO(); backup.loadFromComponent(textureRegionComponent); @@ -39,8 +37,8 @@ public class UpdateImageItemDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); + int entity = EntityUtils.getByUniqueId(entityId); + TextureRegionComponent textureRegionComponent = SandboxComponentRetriever.get(entity, TextureRegionComponent.class); textureRegionComponent.isRepeat = backup.isRepeat; textureRegionComponent.isPolygon = backup.isPolygon; @@ -50,9 +48,9 @@ public class UpdateImageItemDataCommand extends EntityModifyRevertibleCommand { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - private void updateEntity(Entity entity) { - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + private void updateEntity(int entity) { + TextureRegionComponent textureRegionComponent = SandboxComponentRetriever.get(entity, TextureRegionComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); if (!textureRegionComponent.isPolygon) { dimensionsComponent.polygon = null; @@ -61,7 +59,7 @@ public class UpdateImageItemDataCommand extends EntityModifyRevertibleCommand { textureRegionComponent.scheduleRefresh(); } - public static Object payload(Entity entity, SimpleImageVO vo) { + public static Object payload(int entity, SimpleImageVO vo) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = vo; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLabelDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLabelDataCommand.java index b81519de..6a6c4247 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLabelDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLabelDataCommand.java @@ -18,8 +18,8 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.scenes.scene2d.ui.Label; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.renderer.components.label.LabelComponent; @@ -48,10 +48,10 @@ public class UpdateLabelDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; entityId = EntityUtils.getEntityId(entity); - LabelComponent labelComponent = ComponentRetriever.get(entity, LabelComponent.class); + LabelComponent labelComponent = SandboxComponentRetriever.get(entity, LabelComponent.class); this.prevFontName = labelComponent.fontName; this.prevFontSize = labelComponent.fontSize; @@ -85,8 +85,8 @@ public class UpdateLabelDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - final Entity entity = EntityUtils.getByUniqueId(entityId); - final LabelComponent labelComponent = ComponentRetriever.get(entity, LabelComponent.class); + final int entity = EntityUtils.getByUniqueId(entityId); + final LabelComponent labelComponent = SandboxComponentRetriever.get(entity, LabelComponent.class); labelComponent.fontName = prevFontName; labelComponent.fontSize = prevFontSize; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLightBodyDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLightBodyDataCommand.java index d4cdb59d..d7867e9e 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLightBodyDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLightBodyDataCommand.java @@ -1,12 +1,12 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.renderer.components.light.LightBodyComponent; import games.rednblack.editor.renderer.data.LightBodyDataVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; public class UpdateLightBodyDataCommand extends EntityModifyRevertibleCommand { @@ -17,11 +17,11 @@ public class UpdateLightBodyDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; LightBodyDataVO vo = (LightBodyDataVO) payload[1]; entityId = EntityUtils.getEntityId(entity); - LightBodyComponent lightComponent = ComponentRetriever.get(entity, LightBodyComponent.class); + LightBodyComponent lightComponent = SandboxComponentRetriever.get(entity, LightBodyComponent.class); backup = new LightBodyDataVO(); backup.loadFromComponent(lightComponent); @@ -47,8 +47,8 @@ public class UpdateLightBodyDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); - LightBodyComponent lightComponent = ComponentRetriever.get(entity, LightBodyComponent.class); + int entity = EntityUtils.getByUniqueId(entityId); + LightBodyComponent lightComponent = SandboxComponentRetriever.get(entity, LightBodyComponent.class); lightComponent.rayDirection = backup.rayDirection; lightComponent.distance = backup.distance; @@ -69,7 +69,7 @@ public class UpdateLightBodyDataCommand extends EntityModifyRevertibleCommand { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object payload(Entity entity, LightBodyDataVO vo) { + public static Object payload(int entity, LightBodyDataVO vo) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = vo; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLightDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLightDataCommand.java index b9ca7b7b..7df21888 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLightDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateLightDataCommand.java @@ -18,13 +18,13 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.renderer.components.light.LightObjectComponent; import games.rednblack.editor.renderer.data.LightVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; public class UpdateLightDataCommand extends EntityModifyRevertibleCommand { @@ -35,14 +35,14 @@ public class UpdateLightDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; LightVO vo = (LightVO) payload[1]; entityId = EntityUtils.getEntityId(entity); backup = new LightVO(); - backup.loadFromEntity(entity); + backup.loadFromEntity(entity, sandbox.getEngine()); - LightObjectComponent lightObjectComponent = ComponentRetriever.get(entity, LightObjectComponent.class); + LightObjectComponent lightObjectComponent = SandboxComponentRetriever.get(entity, LightObjectComponent.class); lightObjectComponent.rays = vo.rays; lightObjectComponent.isStatic = vo.isStatic; @@ -61,8 +61,8 @@ public class UpdateLightDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); - LightObjectComponent lightObjectComponent = ComponentRetriever.get(entity, LightObjectComponent.class); + int entity = EntityUtils.getByUniqueId(entityId); + LightObjectComponent lightObjectComponent = SandboxComponentRetriever.get(entity, LightObjectComponent.class); lightObjectComponent.rays = backup.rays; lightObjectComponent.isStatic = backup.isStatic; @@ -79,7 +79,7 @@ public class UpdateLightDataCommand extends EntityModifyRevertibleCommand { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object payload(Entity entity, LightVO vo) { + public static Object payload(int entity, LightVO vo) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = vo; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateParticleDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateParticleDataCommand.java index d6ff5708..c3bb58dd 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateParticleDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateParticleDataCommand.java @@ -1,12 +1,12 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.renderer.components.particle.ParticleComponent; import games.rednblack.editor.renderer.data.ParticleEffectVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; public class UpdateParticleDataCommand extends EntityModifyRevertibleCommand { @@ -17,14 +17,14 @@ public class UpdateParticleDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; ParticleEffectVO vo = (ParticleEffectVO) payload[1]; entityId = EntityUtils.getEntityId(entity); backup = new ParticleEffectVO(); - backup.loadFromEntity(entity); + backup.loadFromEntity(entity, sandbox.getEngine()); - ParticleComponent particleComponent = ComponentRetriever.get(entity, ParticleComponent.class); + ParticleComponent particleComponent = SandboxComponentRetriever.get(entity, ParticleComponent.class); particleComponent.transform = vo.transform; particleComponent.particleEffect.setPosition(0, 0); @@ -34,15 +34,15 @@ public class UpdateParticleDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); - ParticleComponent particleComponent = ComponentRetriever.get(entity, ParticleComponent.class); + ParticleComponent particleComponent = SandboxComponentRetriever.get(entity, ParticleComponent.class); particleComponent.transform = backup.transform; HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object payload(Entity entity, ParticleEffectVO vo) { + public static Object payload(int entity, ParticleEffectVO vo) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = vo; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdatePhysicsDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdatePhysicsDataCommand.java index 4a967f49..a854cb02 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdatePhysicsDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdatePhysicsDataCommand.java @@ -1,12 +1,12 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.renderer.components.physics.PhysicsBodyComponent; import games.rednblack.editor.renderer.data.PhysicsBodyDataVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; public class UpdatePhysicsDataCommand extends EntityModifyRevertibleCommand { @@ -17,11 +17,11 @@ public class UpdatePhysicsDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; PhysicsBodyDataVO vo = (PhysicsBodyDataVO) payload[1]; entityId = EntityUtils.getEntityId(entity); - PhysicsBodyComponent physicsComponent = ComponentRetriever.get(entity, PhysicsBodyComponent.class); + PhysicsBodyComponent physicsComponent = SandboxComponentRetriever.get(entity, PhysicsBodyComponent.class); backup = new PhysicsBodyDataVO(); backup.loadFromComponent(physicsComponent); @@ -54,8 +54,8 @@ public class UpdatePhysicsDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); - PhysicsBodyComponent physicsComponent = ComponentRetriever.get(entity, PhysicsBodyComponent.class); + int entity = EntityUtils.getByUniqueId(entityId); + PhysicsBodyComponent physicsComponent = SandboxComponentRetriever.get(entity, PhysicsBodyComponent.class); physicsComponent.bodyType = backup.bodyType; physicsComponent.mass = backup.mass; @@ -83,7 +83,7 @@ public class UpdatePhysicsDataCommand extends EntityModifyRevertibleCommand { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object payload(Entity entity, PhysicsBodyDataVO vo) { + public static Object payload(int entity, PhysicsBodyDataVO vo) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = vo; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdatePolygonDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdatePolygonDataCommand.java index d4796c74..ea263240 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdatePolygonDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdatePolygonDataCommand.java @@ -18,8 +18,8 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; @@ -38,7 +38,7 @@ public class UpdatePolygonDataCommand extends EntityModifyRevertibleCommand { private void collectData() { Object[] payload = getNotification().getBody(); - entityId = EntityUtils.getEntityId((Entity) payload[0]); + entityId = EntityUtils.getEntityId((int) payload[0]); dataFrom = (Vector2[][]) payload[1]; dataTo = (Vector2[][]) payload[2]; dataFrom = dataFrom.clone(); @@ -49,9 +49,9 @@ public class UpdatePolygonDataCommand extends EntityModifyRevertibleCommand { public void doAction() { collectData(); - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); - PolygonComponent polygonComponent = ComponentRetriever.get(entity, PolygonComponent.class); + PolygonComponent polygonComponent = SandboxComponentRetriever.get(entity, PolygonComponent.class); polygonComponent.vertices = dataTo; EntityUtils.refreshComponents(entity); @@ -62,9 +62,9 @@ public class UpdatePolygonDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); - PolygonComponent polygonComponent = ComponentRetriever.get(entity, PolygonComponent.class); + PolygonComponent polygonComponent = SandboxComponentRetriever.get(entity, PolygonComponent.class); polygonComponent.vertices = dataFrom; EntityUtils.refreshComponents(entity); @@ -72,8 +72,8 @@ public class UpdatePolygonDataCommand extends EntityModifyRevertibleCommand { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object[] payloadInitialState(Entity entity) { - PolygonComponent polygonComponent = ComponentRetriever.get(entity, PolygonComponent.class); + public static Object[] payloadInitialState(int entity) { + PolygonComponent polygonComponent = SandboxComponentRetriever.get(entity, PolygonComponent.class); Object[] payload = new Object[3]; payload[0] = entity; payload[1] = cloneData(polygonComponent.vertices); diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSensorDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSensorDataCommand.java index 1d830f7b..1b93c476 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSensorDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSensorDataCommand.java @@ -1,13 +1,12 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; - import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.renderer.components.physics.SensorComponent; import games.rednblack.editor.renderer.data.SensorDataVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; /** @@ -26,11 +25,11 @@ public class UpdateSensorDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; SensorDataVO vo = (SensorDataVO) payload[1]; entityId = EntityUtils.getEntityId(entity); - SensorComponent sensorComponent = ComponentRetriever.get(entity, SensorComponent.class); + SensorComponent sensorComponent = SandboxComponentRetriever.get(entity, SensorComponent.class); backup = new SensorDataVO(); backup.loadFromComponent(sensorComponent); @@ -52,8 +51,8 @@ public class UpdateSensorDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); - SensorComponent sensorComponent = ComponentRetriever.get(entity, SensorComponent.class); + int entity = EntityUtils.getByUniqueId(entityId); + SensorComponent sensorComponent = SandboxComponentRetriever.get(entity, SensorComponent.class); sensorComponent.bottom = backup.bottom; sensorComponent.left = backup.left; @@ -70,7 +69,7 @@ public class UpdateSensorDataCommand extends EntityModifyRevertibleCommand { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object payload(Entity entity, SensorDataVO vo) { + public static Object payload(int entity, SensorDataVO vo) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = vo; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateShaderDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateShaderDataCommand.java index ac48cc36..f1e4e20f 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateShaderDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateShaderDataCommand.java @@ -1,12 +1,12 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.proxy.ResourceManager; import games.rednblack.editor.renderer.components.ShaderComponent; import games.rednblack.editor.renderer.data.MainItemVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; public class UpdateShaderDataCommand extends EntityModifyRevertibleCommand { @@ -18,12 +18,12 @@ public class UpdateShaderDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; String shaderName = (String) payload[1]; MainItemVO.RenderingLayer renderingLayer = (MainItemVO.RenderingLayer) payload[2]; entityId = EntityUtils.getEntityId(entity); - ShaderComponent shaderComponent = ComponentRetriever.get(entity, ShaderComponent.class); + ShaderComponent shaderComponent = SandboxComponentRetriever.get(entity, ShaderComponent.class); if (shaderComponent == null) { cancel(); return; @@ -45,8 +45,8 @@ public class UpdateShaderDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); - ShaderComponent shaderComponent = ComponentRetriever.get(entity, ShaderComponent.class); + int entity = EntityUtils.getByUniqueId(entityId); + ShaderComponent shaderComponent = SandboxComponentRetriever.get(entity, ShaderComponent.class); if (shaderComponent == null) return; ResourceManager resourceManager = facade.retrieveProxy(ResourceManager.NAME); @@ -61,7 +61,7 @@ public class UpdateShaderDataCommand extends EntityModifyRevertibleCommand { facade.sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object payload(Entity entity, String shaderName, MainItemVO.RenderingLayer layer) { + public static Object payload(int entity, String shaderName, MainItemVO.RenderingLayer layer) { Object[] payload = new Object[3]; payload[0] = entity; payload[1] = shaderName; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSpineDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSpineDataCommand.java index 76f8376b..342204f9 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSpineDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSpineDataCommand.java @@ -1,12 +1,12 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.renderer.components.SpineDataComponent; import games.rednblack.editor.renderer.data.SpineVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.h2d.extention.spine.SpineObjectComponent; @@ -18,15 +18,15 @@ public class UpdateSpineDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; SpineVO vo = (SpineVO) payload[1]; entityId = EntityUtils.getEntityId(entity); backup = new SpineVO(); - backup.loadFromEntity(entity); + backup.loadFromEntity(entity, sandbox.getEngine()); - SpineDataComponent spineDataComponent = ComponentRetriever.get(entity, SpineDataComponent.class); - SpineObjectComponent spineObjectComponent = ComponentRetriever.get(entity, SpineObjectComponent.class); + SpineDataComponent spineDataComponent = SandboxComponentRetriever.get(entity, SpineDataComponent.class); + SpineObjectComponent spineObjectComponent = SandboxComponentRetriever.get(entity, SpineObjectComponent.class); spineDataComponent.currentAnimationName = vo.currentAnimationName; spineObjectComponent.setAnimation(vo.currentAnimationName); @@ -36,9 +36,9 @@ public class UpdateSpineDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); - SpineDataComponent spineDataComponent = ComponentRetriever.get(entity, SpineDataComponent.class); - SpineObjectComponent spineObjectComponent = ComponentRetriever.get(entity, SpineObjectComponent.class); + int entity = EntityUtils.getByUniqueId(entityId); + SpineDataComponent spineDataComponent = SandboxComponentRetriever.get(entity, SpineDataComponent.class); + SpineObjectComponent spineObjectComponent = SandboxComponentRetriever.get(entity, SpineObjectComponent.class); spineDataComponent.currentAnimationName = backup.currentAnimationName; spineObjectComponent.setAnimation(backup.currentAnimationName); @@ -46,7 +46,7 @@ public class UpdateSpineDataCommand extends EntityModifyRevertibleCommand { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object payload(Entity entity, SpineVO vo) { + public static Object payload(int entity, SpineVO vo) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = vo; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSpriteAnimationDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSpriteAnimationDataCommand.java index 80fd1974..724b1f60 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSpriteAnimationDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateSpriteAnimationDataCommand.java @@ -1,6 +1,5 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.graphics.g2d.Animation; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; @@ -8,6 +7,7 @@ import games.rednblack.editor.renderer.components.sprite.SpriteAnimationComponen import games.rednblack.editor.renderer.components.sprite.SpriteAnimationStateComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; /** @@ -24,15 +24,15 @@ public class UpdateSpriteAnimationDataCommand extends EntityModifyRevertibleComm @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; entityId = EntityUtils.getEntityId(entity); int fps = (int) payload[1]; String animName = (String) payload[2]; Animation.PlayMode playMode = (Animation.PlayMode) payload[3]; - SpriteAnimationComponent spriteAnimationComponent = ComponentRetriever.get(entity, SpriteAnimationComponent.class); - SpriteAnimationStateComponent spriteAnimationStateComponent = ComponentRetriever.get(entity, SpriteAnimationStateComponent.class); + SpriteAnimationComponent spriteAnimationComponent = SandboxComponentRetriever.get(entity, SpriteAnimationComponent.class); + SpriteAnimationStateComponent spriteAnimationStateComponent = SandboxComponentRetriever.get(entity, SpriteAnimationStateComponent.class); previousFps = spriteAnimationComponent.fps; previousAnimationName = spriteAnimationComponent.currentAnimation; previousPlayMode = spriteAnimationComponent.playMode; @@ -47,10 +47,10 @@ public class UpdateSpriteAnimationDataCommand extends EntityModifyRevertibleComm @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); - SpriteAnimationComponent spriteAnimationComponent = ComponentRetriever.get(entity, SpriteAnimationComponent.class); - SpriteAnimationStateComponent spriteAnimationStateComponent = ComponentRetriever.get(entity, SpriteAnimationStateComponent.class); + SpriteAnimationComponent spriteAnimationComponent = SandboxComponentRetriever.get(entity, SpriteAnimationComponent.class); + SpriteAnimationStateComponent spriteAnimationStateComponent = SandboxComponentRetriever.get(entity, SpriteAnimationStateComponent.class); spriteAnimationComponent.fps = previousFps; spriteAnimationComponent.currentAnimation = previousAnimationName; spriteAnimationComponent.playMode = previousPlayMode; @@ -59,7 +59,7 @@ public class UpdateSpriteAnimationDataCommand extends EntityModifyRevertibleComm HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object payload(Entity entity, int fps, String animName, Animation.PlayMode playMode) { + public static Object payload(int entity, int fps, String animName, Animation.PlayMode playMode) { Object[] payload = new Object[4]; payload[0] = entity; payload[1] = fps; diff --git a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateTalosDataCommand.java b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateTalosDataCommand.java index 2fe1d1f2..09e5cbeb 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/component/UpdateTalosDataCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/component/UpdateTalosDataCommand.java @@ -1,12 +1,12 @@ package games.rednblack.editor.controller.commands.component; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.EntityModifyRevertibleCommand; import games.rednblack.editor.renderer.components.particle.TalosDataComponent; import games.rednblack.editor.renderer.data.TalosVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.h2d.extension.talos.TalosComponent; @@ -18,17 +18,17 @@ public class UpdateTalosDataCommand extends EntityModifyRevertibleCommand { @Override public void doAction() { Object[] payload = getNotification().getBody(); - Entity entity = (Entity) payload[0]; + int entity = (int) payload[0]; TalosVO vo = (TalosVO) payload[1]; entityId = EntityUtils.getEntityId(entity); backup = new TalosVO(); - backup.loadFromEntity(entity); + backup.loadFromEntity(entity, sandbox.getEngine()); - TalosDataComponent dataComponent = ComponentRetriever.get(entity, TalosDataComponent.class); + TalosDataComponent dataComponent = SandboxComponentRetriever.get(entity, TalosDataComponent.class); dataComponent.transform = vo.transform; - TalosComponent talosComponent = ComponentRetriever.get(entity, TalosComponent.class); + TalosComponent talosComponent = SandboxComponentRetriever.get(entity, TalosComponent.class); talosComponent.effect.setPosition(0, 0); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); @@ -36,18 +36,18 @@ public class UpdateTalosDataCommand extends EntityModifyRevertibleCommand { @Override public void undoAction() { - Entity entity = EntityUtils.getByUniqueId(entityId); + int entity = EntityUtils.getByUniqueId(entityId); - TalosDataComponent particleComponent = ComponentRetriever.get(entity, TalosDataComponent.class); + TalosDataComponent particleComponent = SandboxComponentRetriever.get(entity, TalosDataComponent.class); particleComponent.transform = backup.transform; - TalosComponent talosComponent = ComponentRetriever.get(entity, TalosComponent.class); + TalosComponent talosComponent = SandboxComponentRetriever.get(entity, TalosComponent.class); talosComponent.effect.setPosition(0, 0); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } - public static Object payload(Entity entity, TalosVO vo) { + public static Object payload(int entity, TalosVO vo) { Object[] payload = new Object[2]; payload[0] = entity; payload[1] = vo; diff --git a/src/main/java/games/rednblack/editor/factory/ItemFactory.java b/src/main/java/games/rednblack/editor/factory/ItemFactory.java index 9022a5f2..d565c331 100644 --- a/src/main/java/games/rednblack/editor/factory/ItemFactory.java +++ b/src/main/java/games/rednblack/editor/factory/ItemFactory.java @@ -18,10 +18,9 @@ package games.rednblack.editor.factory; -import com.badlogic.ashley.core.Engine; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.PasteItemsCommand; @@ -48,7 +47,7 @@ public class ItemFactory implements IFactory { private final EntityFactory entityFactory; private final SceneLoader sceneLoader; private final Sandbox sandbox; - private Entity createdEntity; + private int createdEntity; private static ItemFactory instance; @@ -97,7 +96,7 @@ public class ItemFactory implements IFactory { } @Override - public Entity getCreatedEntity() { + public int getCreatedEntity() { return createdEntity; } @@ -144,7 +143,7 @@ public class ItemFactory implements IFactory { vo.originY = vo.shape.polygons[0][2].y / 2; if(!setEssentialData(vo, position)) return false; - Entity entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); + int entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_CREATE_ITEM, entity); @@ -161,10 +160,10 @@ public class ItemFactory implements IFactory { PasteItemsCommand.forceIdChange(itemVO.composite); createdEntity = createCompositeItem(itemVO, position); - if (createdEntity == null) return false; + if (createdEntity == -1) return false; //adding library name - MainItemComponent mainItemComponent = ComponentRetriever.get(createdEntity, MainItemComponent.class); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(createdEntity, MainItemComponent.class); mainItemComponent.libraryLink = libraryName; HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_CREATE_ITEM, createdEntity); @@ -172,26 +171,24 @@ public class ItemFactory implements IFactory { return true; } - public Entity createCompositeItem(CompositeItemVO vo, Vector2 position) { - if(!setEssentialData(vo, position)) return null; + public int createCompositeItem(CompositeItemVO vo, Vector2 position) { + if(!setEssentialData(vo, position)) return -1; - Entity entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); - Engine engine = sceneLoader.getEngine(); + int entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); EntityFactory factory = sceneLoader.getEntityFactory(); - factory.initAllChildren(engine, entity, vo.composite); + factory.initAllChildren(entity, vo.composite); return entity; } - public Entity createCompositeItem(Vector2 position) { + public int createCompositeItem(Vector2 position) { CompositeItemVO vo = new CompositeItemVO(); - Entity entity = createCompositeItem(vo, position); - return entity; + return createCompositeItem(vo, position); } - public Entity createLightItem(LightVO vo, Vector2 position) { - if(!setEssentialData(vo, position)) return null; - Entity entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); + public int createLightItem(LightVO vo, Vector2 position) { + if(!setEssentialData(vo, position)) return -1; + int entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_CREATE_ITEM, entity); /* @@ -204,54 +201,50 @@ public class ItemFactory implements IFactory { } public boolean tryCreateParticleItem(String particleName, Vector2 position) { - Entity entity = createParticleItem(particleName, position); + int entity = createParticleItem(particleName, position); /* DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); float boundBoxSize = 10f; dimensionsComponent.boundBox = new Rectangle(-boundBoxSize / 2f, -boundBoxSize / 2f, boundBoxSize, boundBoxSize);*/ - if(entity == null) return false; - - return true; + return entity != -1; } - public Entity createParticleItem(String particleName, Vector2 position) { + public int createParticleItem(String particleName, Vector2 position) { ParticleEffectVO vo = new ParticleEffectVO(); vo.particleName = particleName; - if(!setEssentialData(vo, position)) return null; - Entity entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); + if(!setEssentialData(vo, position)) return -1; + int entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_CREATE_ITEM, entity); return entity; } public boolean tryCreateTalosItem(String particleName, Vector2 position) { - Entity entity = createTalosItem(particleName, position); + int entity = createTalosItem(particleName, position); /* DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); float boundBoxSize = 10f; dimensionsComponent.boundBox = new Rectangle(-boundBoxSize / 2f, -boundBoxSize / 2f, boundBoxSize, boundBoxSize);*/ - if(entity == null) return false; - - return true; + return entity != -1; } - public Entity createTalosItem(String particleName, Vector2 position) { + public int createTalosItem(String particleName, Vector2 position) { TalosVO vo = new TalosVO(); vo.particleName = particleName; - if(!setEssentialData(vo, position)) return null; - Entity entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); + if(!setEssentialData(vo, position)) return -1; + int entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_CREATE_ITEM, entity); return entity; } - public Entity createLabel(TextTool textSettings, Vector2 position) { + public int createLabel(TextTool textSettings, Vector2 position) { LabelVO vo = new LabelVO(); - if(!setEssentialData(vo, position)) return null; + if(!setEssentialData(vo, position)) return -1; HyperLap2DFacade facade = HyperLap2DFacade.getInstance(); ResourceManager resourceManager = facade.retrieveProxy(ResourceManager.NAME); @@ -267,7 +260,7 @@ public class ItemFactory implements IFactory { vo.width = 120f/Sandbox.getInstance().getPixelPerWU(); vo.height = 50f/Sandbox.getInstance().getPixelPerWU(); - Entity entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); + int entity = entityFactory.createEntity(sandbox.getCurrentViewingEntity(), vo); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_CREATE_ITEM, entity); return entity; diff --git a/src/main/java/games/rednblack/editor/graph/actions/ActionFieldType.java b/src/main/java/games/rednblack/editor/graph/actions/ActionFieldType.java index 05f889cc..78a4ca4f 100644 --- a/src/main/java/games/rednblack/editor/graph/actions/ActionFieldType.java +++ b/src/main/java/games/rednblack/editor/graph/actions/ActionFieldType.java @@ -20,7 +20,7 @@ public enum ActionFieldType implements FieldType { case Delay: return value instanceof DelayData; case Entity: - return value instanceof com.badlogic.ashley.core.Entity; + return value instanceof Integer; case Color: return value instanceof com.badlogic.gdx.graphics.Color; case Boolean: diff --git a/src/main/java/games/rednblack/editor/live/LivePreviewScreen.java b/src/main/java/games/rednblack/editor/live/LivePreviewScreen.java index 874c98e0..d10faf4e 100644 --- a/src/main/java/games/rednblack/editor/live/LivePreviewScreen.java +++ b/src/main/java/games/rednblack/editor/live/LivePreviewScreen.java @@ -15,6 +15,7 @@ import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.proxy.ProjectManager; import games.rednblack.editor.proxy.ResolutionManager; import games.rednblack.editor.proxy.ResourceManager; +import games.rednblack.editor.renderer.SceneConfiguration; import games.rednblack.editor.renderer.SceneLoader; import games.rednblack.editor.renderer.components.additional.ButtonComponent; import games.rednblack.editor.view.stage.Sandbox; @@ -51,9 +52,12 @@ public class LivePreviewScreen extends ScreenAdapter implements GestureDetector. viewport = new ExtendViewport(worldSizeVO.getWorldWidth(), worldSizeVO.getWorldHeight()); mCamera = (OrthographicCamera) viewport.getCamera(); - sceneLoader = new SceneLoader(resourceManager); - sceneLoader.injectExternalItemType(new SpineItemType()); - sceneLoader.injectExternalItemType(new TalosItemType()); + SceneConfiguration config = new SceneConfiguration(); + config.setResourceRetriever(resourceManager); + config.addExternalItemType(new SpineItemType()); + config.addExternalItemType(new TalosItemType()); + sceneLoader = new SceneLoader(config); + sceneLoader.loadScene(projectManager.getCurrentSceneConfigVO().sceneName, viewport); bgColor = projectManager.currentProjectVO.backgroundColor; @@ -74,7 +78,8 @@ public class LivePreviewScreen extends ScreenAdapter implements GestureDetector. mCamera.position.lerp(cameraTargetPos, 0.5f); viewport.apply(); - sceneLoader.getEngine().update(delta); + sceneLoader.getEngine().setDelta(delta); + sceneLoader.getEngine().process(); if (projectManager.currentProjectVO.box2dDebugRender) mBox2DDebugRenderer.render(sceneLoader.getWorld(), mCamera.combined); diff --git a/src/main/java/games/rednblack/editor/proxy/PluginManager.java b/src/main/java/games/rednblack/editor/proxy/PluginManager.java index 4210a176..9eb92bd2 100644 --- a/src/main/java/games/rednblack/editor/proxy/PluginManager.java +++ b/src/main/java/games/rednblack/editor/proxy/PluginManager.java @@ -18,12 +18,8 @@ package games.rednblack.editor.proxy; -import com.badlogic.ashley.core.Entity; -import com.badlogic.ashley.core.PooledEngine; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.renderer.data.ProjectInfoVO; @@ -70,7 +66,7 @@ public class PluginManager extends Proxy implements PluginAPI { private ArrayList plugins = new ArrayList<>(); private String pluginDir, cacheDir; - private HashSet pluginEntities; + private HashSet pluginEntities; public PluginManager() { super(NAME); @@ -91,7 +87,7 @@ public class PluginManager extends Proxy implements PluginAPI { plugin.initPlugin(); } - public void dropDownActionSets(Set selectedEntities, Array actionsSet) { + public void dropDownActionSets(Set selectedEntities, Array actionsSet) { for(H2DPlugin plugin: plugins) { plugin.onDropDownOpen(selectedEntities, actionsSet); } @@ -138,7 +134,7 @@ public class PluginManager extends Proxy implements PluginAPI { } @Override - public void removeFollower(Entity entity) { + public void removeFollower(int entity) { FollowersUIMediator followersUIMediator = HyperLap2DFacade.getInstance().retrieveMediator(FollowersUIMediator.NAME); followersUIMediator.removeFollower(entity); } @@ -215,7 +211,7 @@ public class PluginManager extends Proxy implements PluginAPI { } @Override - public PooledEngine getEngine() { + public com.artemis.World getEngine() { return getSceneLoader().getEngine(); } @@ -229,13 +225,13 @@ public class PluginManager extends Proxy implements PluginAPI { return ItemFactory.get(); } - public boolean isEntityVisible(Entity e) { + public boolean isEntityVisible(int e) { LayerItemVO layer = EntityUtils.getEntityLayer(e); return layer != null && layer.isVisible; } @Override - public HashSet getProjectEntities() { + public HashSet getProjectEntities() { Sandbox sandbox = Sandbox.getInstance(); return sandbox.getSelector().getAllFreeItems(); } diff --git a/src/main/java/games/rednblack/editor/proxy/ProjectManager.java b/src/main/java/games/rednblack/editor/proxy/ProjectManager.java index b3590f82..4b8306c9 100755 --- a/src/main/java/games/rednblack/editor/proxy/ProjectManager.java +++ b/src/main/java/games/rednblack/editor/proxy/ProjectManager.java @@ -498,8 +498,9 @@ public class ProjectManager extends Proxy { try { HashMap fonts = fontManager.getFontsMap(); if (fonts.containsKey(font.fontName)) { - File source = new File(fonts.get(font.fontName)); - FileUtils.copyFileToDirectory(source, fontsDirectory.file()); + FileHandle source = new FileHandle(fonts.get(font.fontName)); + FileHandle dest = new FileHandle(fontsDirectory.path() + File.separator + font.fontName + ".ttf"); + FileUtils.copyFile(source.file(), dest.file()); } } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/games/rednblack/editor/system/ParticleContinuousSystem.java b/src/main/java/games/rednblack/editor/system/ParticleContinuousSystem.java index ad3bcedf..6e381e36 100644 --- a/src/main/java/games/rednblack/editor/system/ParticleContinuousSystem.java +++ b/src/main/java/games/rednblack/editor/system/ParticleContinuousSystem.java @@ -1,6 +1,6 @@ package games.rednblack.editor.system; -import com.badlogic.ashley.core.Entity; +import com.artemis.annotations.All; import com.badlogic.gdx.graphics.g2d.ParticleEffect; import games.rednblack.editor.renderer.components.particle.ParticleComponent; import games.rednblack.editor.renderer.systems.ParticleSystem; @@ -10,11 +10,12 @@ import games.rednblack.editor.renderer.systems.ParticleSystem; * This system will make sure they look continuous while in editor, so user will find and see them easily. * */ +@All(ParticleComponent.class) public class ParticleContinuousSystem extends ParticleSystem { @Override - protected void processEntity(Entity entity, float deltaTime) { - super.processEntity(entity, deltaTime); + protected void process(int entity) { + super.process(entity); ParticleComponent particleComponent = particleComponentMapper.get(entity); ParticleEffect particleEffect = particleComponent.particleEffect; diff --git a/src/main/java/games/rednblack/editor/system/PhysicsAdjustSystem.java b/src/main/java/games/rednblack/editor/system/PhysicsAdjustSystem.java index 16ca77af..48fdfca9 100644 --- a/src/main/java/games/rednblack/editor/system/PhysicsAdjustSystem.java +++ b/src/main/java/games/rednblack/editor/system/PhysicsAdjustSystem.java @@ -1,29 +1,28 @@ package games.rednblack.editor.system; -import com.badlogic.ashley.core.Entity; +import com.artemis.annotations.All; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.physics.box2d.World; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.components.physics.PhysicsBodyComponent; import games.rednblack.editor.renderer.systems.PhysicsSystem; -import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; +@All(PhysicsBodyComponent.class) public class PhysicsAdjustSystem extends PhysicsSystem { private final Vector2 transformVec = new Vector2(); - public PhysicsAdjustSystem(World world) { - super(world); + public PhysicsAdjustSystem() { setPhysicsOn(false); } @Override - protected void processEntity(Entity entity, float deltaTime) { + protected void process(int entity) { TransformComponent transformComponent = transformComponentMapper.get(entity); processBody(entity); - PhysicsBodyComponent physicsBodyComponent = ComponentRetriever.get(entity, PhysicsBodyComponent.class); + PhysicsBodyComponent physicsBodyComponent = SandboxComponentRetriever.get(entity, PhysicsBodyComponent.class); if(physicsBodyComponent.body == null) return; diff --git a/src/main/java/games/rednblack/editor/system/TalosContinuousSystem.java b/src/main/java/games/rednblack/editor/system/TalosContinuousSystem.java index 9fb608b3..d262d528 100644 --- a/src/main/java/games/rednblack/editor/system/TalosContinuousSystem.java +++ b/src/main/java/games/rednblack/editor/system/TalosContinuousSystem.java @@ -1,7 +1,8 @@ package games.rednblack.editor.system; -import com.badlogic.ashley.core.Entity; +import com.artemis.annotations.All; import com.talosvfx.talos.runtime.ParticleEffectInstance; +import games.rednblack.editor.renderer.components.particle.TalosDataComponent; import games.rednblack.h2d.extension.talos.TalosComponent; import games.rednblack.h2d.extension.talos.TalosSystem; @@ -10,11 +11,12 @@ import games.rednblack.h2d.extension.talos.TalosSystem; * This system will make sure they look continuous while in editor, so user will find and see them easily. * */ +@All({TalosComponent.class, TalosDataComponent.class}) public class TalosContinuousSystem extends TalosSystem { @Override - protected void processEntity(Entity entity, float deltaTime) { - super.processEntity(entity, deltaTime); + protected void process(int entity) { + super.process(entity); TalosComponent talosComponent = particleComponentMapper.get(entity); ParticleEffectInstance effect = talosComponent.effect; diff --git a/src/main/java/games/rednblack/editor/utils/AssetImporter.java b/src/main/java/games/rednblack/editor/utils/AssetImporter.java index afa5327e..0647d07d 100644 --- a/src/main/java/games/rednblack/editor/utils/AssetImporter.java +++ b/src/main/java/games/rednblack/editor/utils/AssetImporter.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; import com.kotcrab.vis.ui.util.dialog.Dialogs; @@ -123,14 +122,14 @@ public class AssetImporter { return null; } - public boolean deleteAsset(int type, Entity root, String name) { + public boolean deleteAsset(int type, int root, String name) { Asset asset = getDescriptorFor(type); if (asset != null) return asset.deleteAsset(root, name); return false; } - public boolean deleteAsset(Entity root, String name) { + public boolean deleteAsset(int root, String name) { for (Asset asset : new Array.ArrayIterator<>(assetDescriptors)) { if (asset.deleteAsset(root, name)) return true; diff --git a/src/main/java/games/rednblack/editor/utils/EntityBounds.java b/src/main/java/games/rednblack/editor/utils/EntityBounds.java index 4833bcfc..acf89ea7 100644 --- a/src/main/java/games/rednblack/editor/utils/EntityBounds.java +++ b/src/main/java/games/rednblack/editor/utils/EntityBounds.java @@ -18,7 +18,6 @@ package games.rednblack.editor.utils; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Matrix3; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; @@ -27,7 +26,7 @@ import games.rednblack.editor.renderer.components.DimensionsComponent; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.components.light.LightObjectComponent; import games.rednblack.editor.renderer.components.particle.ParticleComponent; -import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.extension.talos.TalosComponent; /** @@ -54,7 +53,7 @@ public class EntityBounds extends Rectangle { private final Array boundPointList = new Array<>(); private final float[] boundPoints = new float[8]; - public EntityBounds(Entity entity) { + public EntityBounds(int entity) { setEntity(entity); } @@ -62,9 +61,9 @@ public class EntityBounds extends Rectangle { } - public void setEntity(Entity entity) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + public void setEntity(int entity) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); x = transformComponent.x; y = transformComponent.y; scaleX = transformComponent.scaleX * (transformComponent.flipX ? -1 : 1); @@ -72,7 +71,7 @@ public class EntityBounds extends Rectangle { width = dimensionsComponent.width; height = dimensionsComponent.height; - if (ComponentRetriever.get(entity, LightObjectComponent.class) != null) { + if (SandboxComponentRetriever.get(entity, LightObjectComponent.class) != null) { x += dimensionsComponent.boundBox.x; y += dimensionsComponent.boundBox.y; scaleX = 1; @@ -81,8 +80,8 @@ public class EntityBounds extends Rectangle { height = dimensionsComponent.boundBox.height; } - if (ComponentRetriever.get(entity, ParticleComponent.class) != null - || ComponentRetriever.get(entity, TalosComponent.class) != null) { + if (SandboxComponentRetriever.get(entity, ParticleComponent.class) != null + || SandboxComponentRetriever.get(entity, TalosComponent.class) != null) { width = dimensionsComponent.boundBox.width; height = dimensionsComponent.boundBox.height; dimensionsComponent.width = width; @@ -186,7 +185,7 @@ public class EntityBounds extends Rectangle { return boundPoints; } - public float[] getBoundPoints(Entity entity) { + public float[] getBoundPoints(int entity) { setEntity(entity); return boundPoints; } @@ -197,7 +196,7 @@ public class EntityBounds extends Rectangle { return boundPointList; } - public Array getBoundPointsList(Entity entity) { + public Array getBoundPointsList(int entity) { setEntity(entity); return getBoundPointsList(); diff --git a/src/main/java/games/rednblack/editor/utils/MoveCommandBuilder.java b/src/main/java/games/rednblack/editor/utils/MoveCommandBuilder.java index d2492d79..80cafe9f 100644 --- a/src/main/java/games/rednblack/editor/utils/MoveCommandBuilder.java +++ b/src/main/java/games/rednblack/editor/utils/MoveCommandBuilder.java @@ -18,9 +18,9 @@ package games.rednblack.editor.utils; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; +import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.renderer.components.TransformComponent; @@ -37,17 +37,17 @@ public class MoveCommandBuilder { payload = new Array<>(); } - public void setX(Entity entity, float x) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + public void setX(int entity, float x) { + TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class, Sandbox.getInstance().getEngine()); setXY(entity, x, transformComponent.y); } - public void setY(Entity entity, float y) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + public void setY(int entity, float y) { + TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class, Sandbox.getInstance().getEngine()); setXY(entity, transformComponent.x, y); } - public void setXY(Entity entity, float x, float y) { + public void setXY(int entity, float x, float y) { Object[] data = new Object[2]; data[0] = entity; data[1] = new Vector2(x, y); diff --git a/src/main/java/games/rednblack/editor/utils/asset/Asset.java b/src/main/java/games/rednblack/editor/utils/asset/Asset.java index 0e472af5..25cd8885 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/Asset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/Asset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.HyperLap2DFacade; @@ -25,7 +24,7 @@ public abstract class Asset implements IAsset { protected ResolutionManager resolutionManager; protected ResourceManager resourceManager; - protected final ArrayList tmpEntityList = new ArrayList<>(); + protected final ArrayList tmpEntityList = new ArrayList<>(); protected final ArrayList tmpImageList = new ArrayList<>(); public Asset() { diff --git a/src/main/java/games/rednblack/editor/utils/asset/IAsset.java b/src/main/java/games/rednblack/editor/utils/asset/IAsset.java index 25a3fd4f..2af4906c 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/IAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/IAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; import games.rednblack.h2d.common.ProgressHandler; @@ -9,5 +8,5 @@ public interface IAsset { int matchType(Array files); boolean checkExistence(Array files); void importAsset(Array files, ProgressHandler progressHandler, boolean skipRepack); - boolean deleteAsset(Entity root, String name); + boolean deleteAsset(int root, String name); } diff --git a/src/main/java/games/rednblack/editor/utils/asset/impl/AtlasAsset.java b/src/main/java/games/rednblack/editor/utils/asset/impl/AtlasAsset.java index 8aa3d434..44b49bc1 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/impl/AtlasAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/impl/AtlasAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset.impl; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.utils.Array; @@ -74,7 +73,7 @@ public class AtlasAsset extends Asset { } @Override - public boolean deleteAsset(Entity root, String name) { + public boolean deleteAsset(int root, String name) { return false; } } diff --git a/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DActionAsset.java b/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DActionAsset.java index 8295a7ef..6543373d 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DActionAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DActionAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset.impl; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Json; @@ -45,7 +44,7 @@ public class HyperLap2DActionAsset extends Asset { } @Override - public boolean deleteAsset(Entity root, String name) { + public boolean deleteAsset(int root, String name) { HashMap libraryActions = projectManager.currentProjectInfoVO.libraryActions; libraryActions.remove(name); diff --git a/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DInternalLibraryAsset.java b/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DInternalLibraryAsset.java index c80b3302..e2cdb722 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DInternalLibraryAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DInternalLibraryAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset.impl; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Json; @@ -53,7 +52,7 @@ public class HyperLap2DInternalLibraryAsset extends Asset { } @Override - public boolean deleteAsset(Entity root, String name) { + public boolean deleteAsset(int root, String name) { return false; } diff --git a/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DLibraryAsset.java b/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DLibraryAsset.java index 22696ca8..3141459a 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DLibraryAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/impl/HyperLap2DLibraryAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset.impl; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.GdxRuntimeException; @@ -16,6 +15,7 @@ import games.rednblack.editor.utils.ImportUtils; import games.rednblack.editor.utils.ZipUtils; import games.rednblack.editor.utils.asset.Asset; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.common.ProgressHandler; import games.rednblack.h2d.common.vo.ExportMapperVO; @@ -134,14 +134,14 @@ public class HyperLap2DLibraryAsset extends Asset { } @Override - public boolean deleteAsset(Entity root, String name) { + public boolean deleteAsset(int root, String name) { HashMap libraryItems = projectManager.currentProjectInfoVO.libraryItems; libraryItems.remove(name); - Array linkedEntities = EntityUtils.getByLibraryLink(name); - for (Entity entity : linkedEntities) { - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + Array linkedEntities = EntityUtils.getByLibraryLink(name); + for (int entity : linkedEntities) { + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); mainItemComponent.libraryLink = ""; } diff --git a/src/main/java/games/rednblack/editor/utils/asset/impl/ImageAsset.java b/src/main/java/games/rednblack/editor/utils/asset/impl/ImageAsset.java index 05c5bca0..19d6175e 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/impl/ImageAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/impl/ImageAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset.impl; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.proxy.ProjectManager; @@ -15,6 +14,8 @@ import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.ImportUtils; import games.rednblack.editor.utils.asset.Asset; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; +import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.common.ProgressHandler; import java.io.File; @@ -70,7 +71,7 @@ public class ImageAsset extends Asset { } @Override - public boolean deleteAsset(Entity root, String name) { + public boolean deleteAsset(int root, String name) { for (ResolutionEntryVO resolutionEntryVO : projectManager.getCurrentProjectInfoVO().resolutions) { if(!deleteSingleImage(resolutionEntryVO.name, name)) return false; @@ -99,7 +100,7 @@ public class ImageAsset extends Asset { * Clear scenes and library items that contains deleted image * @param imageName image to delete */ - protected void postDeleteImage(Entity root, String imageName) { + protected void postDeleteImage(int root, String imageName) { deleteEntitiesWithImages(root, imageName); deleteAllItemsImages(imageName); } @@ -137,15 +138,15 @@ public class ImageAsset extends Asset { } } - private void deleteEntitiesWithImages(Entity rootEntity, String regionName) { + private void deleteEntitiesWithImages(int rootEntity, String regionName) { tmpEntityList.clear(); - Consumer action = (root) -> { - TextureRegionComponent regionComponent = ComponentRetriever.get(root, TextureRegionComponent.class); + Consumer action = (root) -> { + TextureRegionComponent regionComponent = SandboxComponentRetriever.get(root, TextureRegionComponent.class); if (regionComponent != null && regionComponent.regionName.equals(regionName)) { tmpEntityList.add(root); } - NinePatchComponent ninePatchComponent = ComponentRetriever.get(root, NinePatchComponent.class); + NinePatchComponent ninePatchComponent = SandboxComponentRetriever.get(root, NinePatchComponent.class); if (ninePatchComponent != null && ninePatchComponent.textureRegionName.equals(regionName)) { tmpEntityList.add(root); } diff --git a/src/main/java/games/rednblack/editor/utils/asset/impl/ParticleEffectAsset.java b/src/main/java/games/rednblack/editor/utils/asset/impl/ParticleEffectAsset.java index b94b15d1..a410d259 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/impl/ParticleEffectAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/impl/ParticleEffectAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset.impl; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; import com.kotcrab.vis.ui.util.dialog.Dialogs; @@ -13,6 +12,7 @@ import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.ImportUtils; import games.rednblack.editor.utils.asset.Asset; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.common.ProgressHandler; import org.apache.commons.io.FileUtils; @@ -95,7 +95,7 @@ public class ParticleEffectAsset extends Asset { } @Override - public boolean deleteAsset(Entity root, String name) { + public boolean deleteAsset(int root, String name) { String particlePath = projectManager.getCurrentProjectPath() + File.separator + ProjectManager.PARTICLE_DIR_PATH + File.separator; String filePath = particlePath + name; @@ -175,10 +175,10 @@ public class ParticleEffectAsset extends Asset { } } - private void deleteEntitiesWithParticleEffects(Entity rootEntity, String particleName) { + private void deleteEntitiesWithParticleEffects(int rootEntity, String particleName) { tmpEntityList.clear(); - Consumer action = (root) -> { - ParticleComponent particleComponent = ComponentRetriever.get(root, ParticleComponent.class); + Consumer action = (root) -> { + ParticleComponent particleComponent = SandboxComponentRetriever.get(root, ParticleComponent.class); if (particleComponent != null && particleComponent.particleName.equals(particleName)) { tmpEntityList.add(root); } diff --git a/src/main/java/games/rednblack/editor/utils/asset/impl/ShaderAsset.java b/src/main/java/games/rednblack/editor/utils/asset/impl/ShaderAsset.java index 9f522833..e652f8e5 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/impl/ShaderAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/impl/ShaderAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset.impl; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.proxy.ProjectManager; @@ -53,7 +52,7 @@ public class ShaderAsset extends Asset { } @Override - public boolean deleteAsset(Entity root, String name) { + public boolean deleteAsset(int root, String name) { return false; } } diff --git a/src/main/java/games/rednblack/editor/utils/asset/impl/SpineAsset.java b/src/main/java/games/rednblack/editor/utils/asset/impl/SpineAsset.java index 6ee7a2ec..bf8ccc36 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/impl/SpineAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/impl/SpineAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset.impl; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.utils.Array; @@ -18,6 +17,7 @@ import games.rednblack.editor.utils.HyperLap2DUtils; import games.rednblack.editor.utils.ImportUtils; import games.rednblack.editor.utils.asset.Asset; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.common.ProgressHandler; import games.rednblack.h2d.extention.spine.SpineItemType; @@ -77,7 +77,7 @@ public class SpineAsset extends Asset { } @Override - public boolean deleteAsset(Entity root, String spineName) { + public boolean deleteAsset(int root, String spineName) { for (ResolutionEntryVO resolutionEntryVO : projectManager.getCurrentProjectInfoVO().resolutions) { if(!deleteSpineAnimation(resolutionEntryVO.name, spineName)) return false; @@ -205,7 +205,7 @@ public class SpineAsset extends Asset { return true; } - protected void postDeleteSpineAnimation(Entity root, String spineAnimationName) { + protected void postDeleteSpineAnimation(int root, String spineAnimationName) { deleteEntitiesWithSpineAnimation(root, spineAnimationName); deleteAllItemsSpineAnimations(spineAnimationName); } @@ -233,10 +233,10 @@ public class SpineAsset extends Asset { } } - private void deleteEntitiesWithSpineAnimation(Entity rootEntity, String spineName) { + private void deleteEntitiesWithSpineAnimation(int rootEntity, String spineName) { tmpEntityList.clear(); - Consumer action = (root) -> { - SpineDataComponent spineDataComponent = ComponentRetriever.get(root, SpineDataComponent.class); + Consumer action = (root) -> { + SpineDataComponent spineDataComponent = SandboxComponentRetriever.get(root, SpineDataComponent.class); if (spineDataComponent != null && spineDataComponent.animationName.equals(spineName)) { tmpEntityList.add(root); } diff --git a/src/main/java/games/rednblack/editor/utils/asset/impl/SpriteAnimationAtlasAsset.java b/src/main/java/games/rednblack/editor/utils/asset/impl/SpriteAnimationAtlasAsset.java index fa5c1a26..b549c397 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/impl/SpriteAnimationAtlasAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/impl/SpriteAnimationAtlasAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset.impl; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.utils.Array; @@ -13,6 +12,8 @@ import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.ImportUtils; import games.rednblack.editor.utils.asset.Asset; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; +import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.common.ProgressHandler; import org.apache.commons.io.FileUtils; @@ -101,7 +102,7 @@ public class SpriteAnimationAtlasAsset extends Asset { } @Override - public boolean deleteAsset(Entity root, String name) { + public boolean deleteAsset(int root, String name) { for (ResolutionEntryVO resolutionEntryVO : projectManager.getCurrentProjectInfoVO().resolutions) { if(!deleteSpriteAnimation(resolutionEntryVO.name, name)) return false; @@ -128,7 +129,7 @@ public class SpriteAnimationAtlasAsset extends Asset { return ImportUtils.deleteDirectory(filePath); } - protected void postDeleteSpriteAnimation(Entity root, String spriteAnimationName) { + protected void postDeleteSpriteAnimation(int root, String spriteAnimationName) { deleteEntitiesWithSpriteAnimation(root, spriteAnimationName); deleteAllItemsSpriteAnimations(spriteAnimationName); } @@ -158,10 +159,10 @@ public class SpriteAnimationAtlasAsset extends Asset { } } - private void deleteEntitiesWithSpriteAnimation(Entity rootEntity, String spriteAnimationName) { + private void deleteEntitiesWithSpriteAnimation(int rootEntity, String spriteAnimationName) { tmpEntityList.clear(); - Consumer action = (root) -> { - SpriteAnimationComponent spriteAnimationComponent = ComponentRetriever.get(root, SpriteAnimationComponent.class); + Consumer action = (root) -> { + SpriteAnimationComponent spriteAnimationComponent = SandboxComponentRetriever.get(root, SpriteAnimationComponent.class); if (spriteAnimationComponent != null && spriteAnimationComponent.animationName.equals(spriteAnimationName)) { tmpEntityList.add(root); } diff --git a/src/main/java/games/rednblack/editor/utils/asset/impl/TalosVFXAsset.java b/src/main/java/games/rednblack/editor/utils/asset/impl/TalosVFXAsset.java index 6e3ea3c2..de7ec46d 100644 --- a/src/main/java/games/rednblack/editor/utils/asset/impl/TalosVFXAsset.java +++ b/src/main/java/games/rednblack/editor/utils/asset/impl/TalosVFXAsset.java @@ -1,6 +1,5 @@ package games.rednblack.editor.utils.asset.impl; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Json; @@ -15,6 +14,7 @@ import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.ImportUtils; import games.rednblack.editor.utils.asset.Asset; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.utils.runtime.TalosResources; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.common.ProgressHandler; @@ -115,7 +115,7 @@ public class TalosVFXAsset extends Asset { } @Override - public boolean deleteAsset(Entity root, String name) { + public boolean deleteAsset(int root, String name) { String particlePath = projectManager.getCurrentProjectPath() + File.separator + ProjectManager.TALOS_VFX_DIR_PATH + File.separator; String filePath = particlePath + name; @@ -217,10 +217,10 @@ public class TalosVFXAsset extends Asset { } } - private void deleteEntitiesWithParticleEffects(Entity rootEntity, String particleName) { + private void deleteEntitiesWithParticleEffects(int rootEntity, String particleName) { tmpEntityList.clear(); - Consumer action = (root) -> { - TalosDataComponent particleComponent = ComponentRetriever.get(root, TalosDataComponent.class); + Consumer action = (root) -> { + TalosDataComponent particleComponent = SandboxComponentRetriever.get(root, TalosDataComponent.class); if (particleComponent != null && particleComponent.particleName.equals(particleName)) { tmpEntityList.add(root); } diff --git a/src/main/java/games/rednblack/editor/utils/runtime/ComponentCloner.java b/src/main/java/games/rednblack/editor/utils/runtime/ComponentCloner.java index a59928ee..587bc665 100644 --- a/src/main/java/games/rednblack/editor/utils/runtime/ComponentCloner.java +++ b/src/main/java/games/rednblack/editor/utils/runtime/ComponentCloner.java @@ -23,7 +23,7 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; -import com.badlogic.ashley.core.Component; +import com.artemis.Component; import com.badlogic.gdx.utils.reflect.ClassReflection; import com.badlogic.gdx.utils.reflect.ReflectionException; diff --git a/src/main/java/games/rednblack/editor/utils/runtime/EntityUtils.java b/src/main/java/games/rednblack/editor/utils/runtime/EntityUtils.java index a96ab095..5517d0e3 100644 --- a/src/main/java/games/rednblack/editor/utils/runtime/EntityUtils.java +++ b/src/main/java/games/rednblack/editor/utils/runtime/EntityUtils.java @@ -18,11 +18,10 @@ package games.rednblack.editor.utils.runtime; -import com.badlogic.ashley.core.Component; -import com.badlogic.ashley.core.Entity; -import com.badlogic.ashley.core.Family; -import com.badlogic.ashley.core.PooledEngine; -import com.badlogic.ashley.utils.ImmutableArray; +import com.artemis.Aspect; +import com.artemis.Component; +import com.artemis.EntitySubscription; +import com.artemis.utils.IntBag; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.utils.Array; @@ -75,12 +74,12 @@ public class EntityUtils { itemTypeIconMap.put(TALOS_TYPE, "icon-particle-white"); } - public static String getItemName(Entity entity) { - ParentNodeComponent parentNodeComponent = ComponentRetriever.get(entity, ParentNodeComponent.class); + public static String getItemName(int entity) { + ParentNodeComponent parentNodeComponent = SandboxComponentRetriever.get(entity, ParentNodeComponent.class); if (parentNodeComponent == null) return Sandbox.getInstance().sceneControl.getCurrentSceneVO().sceneName; - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); if (mainItemComponent.itemIdentifier != null && !mainItemComponent.itemIdentifier.isEmpty()) { return mainItemComponent.itemIdentifier; } else { @@ -93,21 +92,21 @@ public class EntityUtils { } } - public static Drawable getItemIcon(Entity entity) { + public static Drawable getItemIcon(int entity) { int type = EntityUtils.getType(entity); String icon = itemTypeIconMap.get(type); return VisUI.getSkin().getDrawable(icon); } - public static Integer getEntityId(Entity entity) { - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + public static Integer getEntityId(int entity) { + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); return mainItemComponent.uniqueId; } - public static Array getEntityId(Iterable entities) { + public static Array getEntityId(Iterable entities) { Array entityIds = new Array<>(); - for (Entity entity : entities) { - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + for (int entity : entities) { + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); if (mainItemComponent != null) entityIds.add(mainItemComponent.uniqueId); } @@ -115,23 +114,23 @@ public class EntityUtils { return entityIds; } - public static Entity getByUniqueId(Integer id) { + public static int getByUniqueId(Integer id) { return Sandbox.getInstance().getSceneControl().sceneLoader.getEntityFactory().getEntityByUniqueId(id); } - public static HashSet getByUniqueId(Array ids) { - HashSet entities = new HashSet<>(); + public static HashSet getByUniqueId(Array ids) { + HashSet entities = new HashSet<>(); for (Integer id : ids) { - Entity entity = Sandbox.getInstance().getSceneControl().sceneLoader.getEntityFactory().getEntityByUniqueId(id); + Integer entity = Sandbox.getInstance().getSceneControl().sceneLoader.getEntityFactory().getEntityByUniqueId(id); entities.add(entity); } return entities; } - public static HashMap> cloneEntities(Set entities) { + /*public static HashMap> cloneEntities(Set entities) { HashMap> data = new HashMap<>(); - for (Entity entity : entities) { + for (int entity : entities) { Collection components = cloneEntityComponents(entity); data.put(EntityUtils.getEntityId(entity), components); } @@ -139,51 +138,51 @@ public class EntityUtils { return data; } - public static Entity cloneEntity(PooledEngine engine, Entity entity) { - Entity newEntity = engine.createEntity(); + public static int cloneEntity(com.artemis.World engine, int entity) { + int newEntity = engine.create(); Collection components = cloneEntityComponents(entity); for (Component component : components) { - Component c = engine.createComponent(component.getClass()); + Component c = engine.edit(newEntity).create(component.getClass()); ComponentCloner.set(c, component); - newEntity.add(component); } return newEntity; } - public static Collection cloneEntityComponents(Entity entity) { - Collection components = ComponentCloner.cloneAll(ComponentRetriever.getComponents(entity)); + public static Collection cloneEntityComponents(int entity) { + Array array = new Array<>(); + Collection components = ComponentCloner.cloneAll(ComponentRetriever.getComponents(entity, array)); return components; - } + }*/ - public static Vector2 getPosition(Entity entity) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + public static Vector2 getPosition(int entity) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); return new Vector2(transformComponent.x, transformComponent.y); } - public static void getPosition(Entity entity, Vector2 position) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + public static void getPosition(int entity, Vector2 position) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); position.set(transformComponent.x, transformComponent.y); } - public static TransformComponent setPosition(Entity entity, Vector2 position) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + public static TransformComponent setPosition(int entity, Vector2 position) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); transformComponent.x = position.x; transformComponent.y = position.y; return transformComponent; } - public static Vector2 getSize(Entity entity) { - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + public static Vector2 getSize(int entity) { + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); return new Vector2(dimensionsComponent.width, dimensionsComponent.height); } - public static void getSize(Entity entity, Vector2 size) { - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + public static void getSize(int entity, Vector2 size) { + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); size.set(dimensionsComponent.width, dimensionsComponent.height); } - public static DimensionsComponent setSize(Entity entity, Vector2 size) { - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + public static DimensionsComponent setSize(int entity, Vector2 size) { + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); dimensionsComponent.width = size.x; dimensionsComponent.height = size.y; if (dimensionsComponent.boundBox != null) { @@ -193,14 +192,14 @@ public class EntityUtils { return dimensionsComponent; } - public static Vector2 getRightTopPoint(Set entities) { + public static Vector2 getRightTopPoint(Set entities) { if (entities.size() == 0) return null; Vector2 rightTopPoint = getPosition(entities.stream().findFirst().get()); - for (Entity entity : entities) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + for (int entity : entities) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); if (rightTopPoint.x < transformComponent.x + dimensionsComponent.width) { rightTopPoint.x = transformComponent.x + dimensionsComponent.width; @@ -213,13 +212,13 @@ public class EntityUtils { return rightTopPoint; } - public static Vector2 getLeftBottomPoint(Set entities) { + public static Vector2 getLeftBottomPoint(Set entities) { if (entities.size() == 0) return null; Vector2 leftBottomPoint = getPosition(entities.stream().findFirst().get()); - for (Entity entity : entities) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + for (int entity : entities) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); if (leftBottomPoint.x > transformComponent.x) { leftBottomPoint.x = transformComponent.x; } @@ -231,16 +230,16 @@ public class EntityUtils { return leftBottomPoint; } - public static void changeParent(HashSet entities, Entity parent) { - for (Entity entity : entities) { - ParentNodeComponent parentNodeComponent = ComponentRetriever.get(entity, ParentNodeComponent.class); + public static void changeParent(HashSet entities, int parent) { + for (int entity : entities) { + ParentNodeComponent parentNodeComponent = SandboxComponentRetriever.get(entity, ParentNodeComponent.class); //remove me from previous parent children list - NodeComponent nodeComponent = ComponentRetriever.get(parentNodeComponent.parentEntity, NodeComponent.class); + NodeComponent nodeComponent = SandboxComponentRetriever.get(parentNodeComponent.parentEntity, NodeComponent.class); nodeComponent.children.removeValue(entity, true); //add me to new parent child list - NodeComponent rootNodeComponent = ComponentRetriever.get(parent, NodeComponent.class); + NodeComponent rootNodeComponent = SandboxComponentRetriever.get(parent, NodeComponent.class); rootNodeComponent.children.add(entity); //change my parent @@ -248,29 +247,31 @@ public class EntityUtils { } } - public static HashSet getChildren(Entity entity) { - HashSet entities; - NodeComponent nodeComponent = ComponentRetriever.get(entity, NodeComponent.class); + public static HashSet getChildren(int entity) { + HashSet entities; + NodeComponent nodeComponent = SandboxComponentRetriever.get(entity, NodeComponent.class); if (nodeComponent == null) return null; - Entity[] children = nodeComponent.children.toArray(); + Integer[] children = nodeComponent.children.toArray(); entities = new HashSet<>(Arrays.asList(children)); return entities; } - public static int getType(Entity entity) { - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + public static int getType(int entity) { + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); if (mainItemComponent == null) return UNKNOWN_TYPE; return mainItemComponent.entityType; } - public static Array getByLibraryLink(String link) { - Array result = new Array<>(); - ImmutableArray composites = Sandbox.getInstance().getEngine().getEntitiesFor(Family.all(NodeComponent.class).get()); - for (Entity composite : composites) { - MainItemComponent mainItemComponent = ComponentRetriever.get(composite, MainItemComponent.class); + public static Array getByLibraryLink(String link) { + Array result = new Array<>(); + EntitySubscription subscription = Sandbox.getInstance().getEngine().getAspectSubscriptionManager() + .get(Aspect.all(NodeComponent.class)); + IntBag composites = subscription.getEntities(); + for (int composite : composites.getData()) { + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(composite, MainItemComponent.class); if (mainItemComponent.libraryLink.equals(link)) { result.add(composite); } @@ -279,23 +280,9 @@ public class EntityUtils { return result; } - public static void reInstantiateChildren(Entity entity) { - NodeComponent nodeComponent = ComponentRetriever.get(entity, NodeComponent.class); - if (nodeComponent != null) { - CompositeVO compositeVo = new CompositeVO(); - compositeVo.loadFromEntity(entity); - - entity.remove(NodeComponent.class); - entity.add(new NodeComponent()); - - SceneLoader sceneLoader = Sandbox.getInstance().getSceneControl().sceneLoader; - sceneLoader.getEntityFactory().initAllChildren(Sandbox.getInstance().getEngine(), entity, compositeVo); - } - } - - public static LayerItemVO getEntityLayer(Entity entity) { - ZIndexComponent zIndexComponent = ComponentRetriever.get(entity, ZIndexComponent.class); - LayerMapComponent layerMapComponent = ComponentRetriever.get(entity.getComponent(ParentNodeComponent.class).parentEntity, LayerMapComponent.class); + public static LayerItemVO getEntityLayer(int entity) { + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(entity, ZIndexComponent.class); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(SandboxComponentRetriever.get(entity, ParentNodeComponent.class).parentEntity, LayerMapComponent.class); return layerMapComponent.getLayer(zIndexComponent.layerName); } @@ -306,11 +293,11 @@ public class EntityUtils { * @param root * @param action */ - public static void applyActionRecursivelyOnEntities(Entity root, Consumer action) { + public static void applyActionRecursivelyOnEntities(int root, Consumer action) { action.accept(root); - NodeComponent nodeComponent = ComponentRetriever.get(root, NodeComponent.class); + NodeComponent nodeComponent = SandboxComponentRetriever.get(root, NodeComponent.class); if (nodeComponent != null && nodeComponent.children != null) { - for (Entity targetEntity : nodeComponent.children) { + for (int targetEntity : nodeComponent.children) { applyActionRecursivelyOnEntities(targetEntity, action); } } @@ -325,30 +312,31 @@ public class EntityUtils { } } - public static void removeEntities(ArrayList entityList) { - for (Entity entity : entityList) { - Sandbox.getInstance().getEngine().removeEntity(entity); + public static void removeEntities(ArrayList entityList) { + for (int entity : entityList) { + Sandbox.getInstance().getEngine().delete(entity); } + Sandbox.getInstance().getEngine().process(); } - public static void refreshComponents(Entity entity) { - TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); + public static void refreshComponents(int entity) { + TextureRegionComponent textureRegionComponent = SandboxComponentRetriever.get(entity, TextureRegionComponent.class); if (textureRegionComponent != null) { textureRegionComponent.scheduleRefresh(); } - PhysicsBodyComponent physicsBodyComponent = ComponentRetriever.get(entity, PhysicsBodyComponent.class); + PhysicsBodyComponent physicsBodyComponent = SandboxComponentRetriever.get(entity, PhysicsBodyComponent.class); if (physicsBodyComponent != null) { physicsBodyComponent.scheduleRefresh(); } - LightBodyComponent lightBodyComponent = ComponentRetriever.get(entity, LightBodyComponent.class); + LightBodyComponent lightBodyComponent = SandboxComponentRetriever.get(entity, LightBodyComponent.class); if (lightBodyComponent != null) { lightBodyComponent.scheduleRefresh(); } } - public static Entity getEntityFromJson(String jsonString, int entityType, EntityFactory factory, Entity parent) { + public static int getEntityFromJson(String jsonString, int entityType, EntityFactory factory, int parent) { Json json = new Json(); if(entityType == EntityFactory.COMPOSITE_TYPE) { CompositeItemVO vo = json.fromJson(CompositeItemVO.class, jsonString); @@ -390,117 +378,119 @@ public class EntityUtils { LightVO vo = json.fromJson(LightVO.class, jsonString); return factory.createEntity(parent, vo); } - return null; + return -1; } - public static String getJsonStringFromEntity(Entity entity) { + public static String getJsonStringFromEntity(int entity) { Json json = new Json(); - int entityType = ComponentRetriever.get(entity, MainItemComponent.class).entityType; + com.artemis.World engine = Sandbox.getInstance().getEngine(); + int entityType = SandboxComponentRetriever.get(entity, MainItemComponent.class).entityType; if(entityType == EntityFactory.COMPOSITE_TYPE) { CompositeItemVO vo = new CompositeItemVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); return json.toJson(vo); } if(entityType == EntityFactory.IMAGE_TYPE) { SimpleImageVO vo = new SimpleImageVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); return json.toJson(vo); } if(entityType == EntityFactory.NINE_PATCH) { Image9patchVO vo = new Image9patchVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); return json.toJson(vo); } if(entityType == EntityFactory.LABEL_TYPE) { LabelVO vo = new LabelVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); return json.toJson(vo); } if(entityType == EntityFactory.PARTICLE_TYPE) { ParticleEffectVO vo = new ParticleEffectVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); return json.toJson(vo); } if(entityType == EntityFactory.TALOS_TYPE) { TalosVO vo = new TalosVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); return json.toJson(vo); } if(entityType == EntityFactory.SPRITE_TYPE) { SpriteAnimationVO vo = new SpriteAnimationVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); return json.toJson(vo); } if(entityType == EntityFactory.SPINE_TYPE) { SpineVO vo = new SpineVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); return json.toJson(vo); } if(entityType == EntityFactory.COLOR_PRIMITIVE) { ColorPrimitiveVO vo = new ColorPrimitiveVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); return json.toJson(vo); } if(entityType == EntityFactory.LIGHT_TYPE) { LightVO vo = new LightVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); return json.toJson(vo); } return null; } - public static String getJsonStringFromEntities(Set entities) { + public static String getJsonStringFromEntities(Set entities) { CompositeVO holderComposite = new CompositeVO(); - for(Entity entity : entities) { - int entityType = ComponentRetriever.get(entity, MainItemComponent.class).entityType; + com.artemis.World engine = Sandbox.getInstance().getEngine(); + for(int entity : entities) { + int entityType = SandboxComponentRetriever.get(entity, MainItemComponent.class).entityType; if(entityType == EntityFactory.COMPOSITE_TYPE) { CompositeItemVO vo = new CompositeItemVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); holderComposite.sComposites.add(vo); } if(entityType == EntityFactory.IMAGE_TYPE) { SimpleImageVO vo = new SimpleImageVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); holderComposite.sImages.add(vo); } if(entityType == EntityFactory.NINE_PATCH) { Image9patchVO vo = new Image9patchVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); holderComposite.sImage9patchs.add(vo); } if(entityType == EntityFactory.LABEL_TYPE) { LabelVO vo = new LabelVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); holderComposite.sLabels.add(vo); } if(entityType == EntityFactory.PARTICLE_TYPE) { ParticleEffectVO vo = new ParticleEffectVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); holderComposite.sParticleEffects.add(vo); } if(entityType == EntityFactory.TALOS_TYPE) { TalosVO vo = new TalosVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); holderComposite.sTalosVFX.add(vo); } if(entityType == EntityFactory.SPRITE_TYPE) { SpriteAnimationVO vo = new SpriteAnimationVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); holderComposite.sSpriteAnimations.add(vo); } if(entityType == EntityFactory.SPINE_TYPE) { SpineVO vo = new SpineVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); holderComposite.sSpineAnimations.add(vo); } if(entityType == EntityFactory.COLOR_PRIMITIVE) { ColorPrimitiveVO vo = new ColorPrimitiveVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); holderComposite.sColorPrimitives.add(vo); } if(entityType == EntityFactory.LIGHT_TYPE) { LightVO vo = new LightVO(); - vo.loadFromEntity(entity); + vo.loadFromEntity(entity, engine); holderComposite.sLights.add(vo); } } diff --git a/src/main/java/games/rednblack/editor/utils/runtime/SandboxComponentRetriever.java b/src/main/java/games/rednblack/editor/utils/runtime/SandboxComponentRetriever.java new file mode 100644 index 00000000..5df26890 --- /dev/null +++ b/src/main/java/games/rednblack/editor/utils/runtime/SandboxComponentRetriever.java @@ -0,0 +1,12 @@ +package games.rednblack.editor.utils.runtime; + +import com.artemis.Component; +import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.view.stage.Sandbox; + +public class SandboxComponentRetriever { + + public static T get(int entity, Class type) { + return ComponentRetriever.get(entity, type, Sandbox.getInstance().getEngine()); + } +} diff --git a/src/main/java/games/rednblack/editor/view/HyperLap2DScreen.java b/src/main/java/games/rednblack/editor/view/HyperLap2DScreen.java index 960559c0..267f83b2 100644 --- a/src/main/java/games/rednblack/editor/view/HyperLap2DScreen.java +++ b/src/main/java/games/rednblack/editor/view/HyperLap2DScreen.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view; -import com.badlogic.ashley.core.Engine; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Graphics; import com.badlogic.gdx.InputMultiplexer; @@ -55,7 +54,7 @@ public class HyperLap2DScreen implements Screen, InputProcessor { public UIStage uiStage; - private Engine engine; + private com.artemis.World engine; private final HyperLap2DFacade facade; @@ -95,7 +94,8 @@ public class HyperLap2DScreen implements Screen, InputProcessor { if (sandboxBackUI != null) sandboxBackUI.render(deltaTime); sandbox.render(deltaTime); - engine.update(deltaTime); + engine.setDelta(deltaTime); + engine.process(); } uiStage.getViewport().apply(); @@ -289,7 +289,7 @@ public class HyperLap2DScreen implements Screen, InputProcessor { return false; } - public void setEngine(Engine engine) { + public void setEngine(com.artemis.World engine) { this.engine = engine; } diff --git a/src/main/java/games/rednblack/editor/view/HyperLap2DScreenMediator.java b/src/main/java/games/rednblack/editor/view/HyperLap2DScreenMediator.java index 96a71464..162f2c30 100644 --- a/src/main/java/games/rednblack/editor/view/HyperLap2DScreenMediator.java +++ b/src/main/java/games/rednblack/editor/view/HyperLap2DScreenMediator.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view; -import com.badlogic.ashley.core.Engine; import games.rednblack.editor.proxy.ProjectManager; import games.rednblack.editor.proxy.SettingsManager; import games.rednblack.h2d.common.MsgAPI; @@ -72,7 +71,7 @@ public class HyperLap2DScreenMediator extends Mediator { facade = HyperLap2DFacade.getInstance(); SandboxMediator sandboxMediator = facade.retrieveMediator(SandboxMediator.NAME); - Engine engine = sandboxMediator.getViewComponent().getEngine(); + com.artemis.World engine = sandboxMediator.getViewComponent().getEngine(); getViewComponent().setEngine(engine); viewComponent.show(); diff --git a/src/main/java/games/rednblack/editor/view/ItemControlMediator.java b/src/main/java/games/rednblack/editor/view/ItemControlMediator.java index df5baedf..31ac64f2 100644 --- a/src/main/java/games/rednblack/editor/view/ItemControlMediator.java +++ b/src/main/java/games/rednblack/editor/view/ItemControlMediator.java @@ -20,10 +20,10 @@ package games.rednblack.editor.view; import java.util.Set; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.components.ZIndexComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; /** * Created by CyberJoe on 3/18/2015. @@ -39,9 +39,9 @@ public class ItemControlMediator { this.sceneControl = sceneControl; } - public void itemZIndexChange( Set currentSelection, boolean isUp) { - for (Entity item : currentSelection) { - zIndexComponent = ComponentRetriever.get(item, ZIndexComponent.class); + public void itemZIndexChange(Set currentSelection, boolean isUp) { + for (Integer item : currentSelection) { + zIndexComponent = SandboxComponentRetriever.get(item, ZIndexComponent.class); int ammount = 1; if (!isUp) ammount = -1; @@ -52,8 +52,8 @@ public class ItemControlMediator { } } - public void moveItemBy(Entity entity, float x, float y) { - transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + public void moveItemBy(int entity, float x, float y) { + transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); transformComponent.x+=x; transformComponent.y+=y; } diff --git a/src/main/java/games/rednblack/editor/view/SceneControlMediator.java b/src/main/java/games/rednblack/editor/view/SceneControlMediator.java index 32297342..07c28939 100644 --- a/src/main/java/games/rednblack/editor/view/SceneControlMediator.java +++ b/src/main/java/games/rednblack/editor/view/SceneControlMediator.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.viewport.ScreenViewport; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.proxy.ProjectManager; @@ -55,11 +54,6 @@ public class SceneControlMediator { */ private CompositeItemVO rootSceneVO; - /** - * current scene rendering item - */ - private Entity currentScene; - public SceneControlMediator(SceneLoader sceneLoader) { this.sceneLoader = sceneLoader; facade = HyperLap2DFacade.getInstance(); @@ -82,6 +76,7 @@ public class SceneControlMediator { currentSceneVo = sceneLoader.loadScene(sceneName, viewport); rootSceneVO = new CompositeItemVO(currentSceneVo.composite); + Sandbox.getInstance().getEngine().process(); } public void updateAmbientLights() { @@ -92,15 +87,11 @@ public class SceneControlMediator { return rootSceneVO; } - public Entity getCurrentScene() { - return currentScene; - } - public SceneVO getCurrentSceneVO() { return currentSceneVo; } - public Entity getRootEntity() { + public int getRootEntity() { return sceneLoader.getRoot(); } } diff --git a/src/main/java/games/rednblack/editor/view/stage/ItemSelector.java b/src/main/java/games/rednblack/editor/view/stage/ItemSelector.java index b5299334..a4ff478a 100644 --- a/src/main/java/games/rednblack/editor/view/stage/ItemSelector.java +++ b/src/main/java/games/rednblack/editor/view/stage/ItemSelector.java @@ -18,12 +18,12 @@ package games.rednblack.editor.view.stage; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.SnapshotArray; import games.rednblack.editor.renderer.components.TransformComponent; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.renderer.components.NodeComponent; @@ -56,7 +56,7 @@ public class ItemSelector { private SceneControlMediator sceneControl; /** list of current selected panels */ - private Set currentSelection = new HashSet<>(); + private Set currentSelection = new HashSet<>(); private FollowersUIMediator followersUIMediator; @@ -74,19 +74,19 @@ public class ItemSelector { /** * @return HashMap of selection rectangles that contain panels */ - public Set getCurrentSelection() { + public Set getCurrentSelection() { return currentSelection; } /** * @return one selected item */ - public Entity getSelectedItem() { + public int getSelectedItem() { if(currentSelection.size() > 0) { return currentSelection.iterator().next(); } - return null; + return -1; } /** @@ -107,12 +107,12 @@ public class ItemSelector { /** * @return list of currently selected panels */ - public Set getSelectedItems() { + public Set getSelectedItems() { return currentSelection; } - public BiConsumer broadestItem = (i, acc) -> { + public BiConsumer broadestItem = (i, acc) -> { if (acc.carryVal == null) acc.carryVal = Constants.FLOAT_MIN; EntityBounds bounds = new EntityBounds(i); final float width = bounds.getVisualWidth(); @@ -122,7 +122,7 @@ public class ItemSelector { } }; - public BiConsumer highestItem = (i, acc) -> { + public BiConsumer highestItem = (i, acc) -> { if (acc.carryVal == null) acc.carryVal = Constants.FLOAT_MIN; EntityBounds bounds = new EntityBounds(i); final float height = bounds.getVisualHeight(); @@ -132,7 +132,7 @@ public class ItemSelector { } }; - public BiConsumer rightmostItem = (i, acc) -> { + public BiConsumer rightmostItem = (i, acc) -> { if (acc.carryVal == null) acc.carryVal = Constants.FLOAT_MIN; EntityBounds bounds = new EntityBounds(i); final float x = bounds.getVisualRightX(); @@ -142,7 +142,7 @@ public class ItemSelector { } }; - public BiConsumer leftmostItem = (i, acc) -> { + public BiConsumer leftmostItem = (i, acc) -> { if (acc.carryVal == null) acc.carryVal = Constants.FLOAT_MAX; EntityBounds bounds = new EntityBounds(i); final float x = bounds.getVisualX(); @@ -152,7 +152,7 @@ public class ItemSelector { } }; - public BiConsumer topmostItem = (i, acc) -> { + public BiConsumer topmostItem = (i, acc) -> { if (acc.carryVal == null) acc.carryVal = Constants.FLOAT_MIN; EntityBounds bounds = new EntityBounds(i); final float y = bounds.getVisualTopY(); @@ -161,7 +161,7 @@ public class ItemSelector { acc.carry = i; } }; - public BiConsumer bottommostItem = (i, acc) -> { + public BiConsumer bottommostItem = (i, acc) -> { if (acc.carryVal == null) acc.carryVal = Constants.FLOAT_MAX; EntityBounds bounds = new EntityBounds(i); final float y = bounds.getVisualY(); @@ -177,14 +177,14 @@ public class ItemSelector { */ private static class AccContainer { public Float carryVal = null; - public Entity carry = null; + public int carry = -1; } - public Entity get(BiConsumer checkSelection) { + public int get(BiConsumer checkSelection) { final AccContainer acc = new AccContainer(); - for (Entity entity : currentSelection) { + for (int entity : currentSelection) { checkSelection.accept(entity, acc); } return acc.carry; @@ -212,7 +212,7 @@ public class ItemSelector { * @param item to select * @param removeOthers if set to true this item will become the only selection, otherwise will be added to existing */ - public void setSelection(Entity item, boolean removeOthers) { + public void setSelection(int item, boolean removeOthers) { if (currentSelection.contains(item)) return; if (removeOthers) clearSelections(); @@ -226,13 +226,13 @@ public class ItemSelector { * adds to selection a list of items * @param items list of panels to select */ - public void addSelections(Set items) { - for (Entity item : items) { + public void addSelections(Set items) { + for (int item : items) { setSelection(item, false); } } - public boolean isSelected(Entity entity) { + public boolean isSelected(int entity) { return currentSelection.contains(entity); } @@ -241,7 +241,7 @@ public class ItemSelector { * @param items list of panels to select * @param alsoShow if false, selection will remain hidden at this moment */ - public void setSelections(Set items, boolean alsoShow) { + public void setSelections(Set items, boolean alsoShow) { currentSelection.clear(); if(items == null) { @@ -263,8 +263,8 @@ public class ItemSelector { * remove selection to a list of items * @param items list of panels to remove selection */ - public void releaseSelections(Set items) { - for (Entity item : items) { + public void releaseSelections(Set items) { + for (int item : items) { releaseSelection(item); } } @@ -273,7 +273,7 @@ public class ItemSelector { * Un-selects item * @param item to un-select */ - public void releaseSelection(Entity item) { + public void releaseSelection(int item) { currentSelection.remove(item); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_SELECTION_CHANGED, currentSelection); @@ -292,15 +292,15 @@ public class ItemSelector { /** * Selects all panels on currently active scene */ - public HashSet getAllFreeItems() { - NodeComponent nodeComponent = ComponentRetriever.get(sandbox.getCurrentViewingEntity(), NodeComponent.class); - SnapshotArray childrenEntities = nodeComponent.children; + public HashSet getAllFreeItems() { + NodeComponent nodeComponent = SandboxComponentRetriever.get(sandbox.getCurrentViewingEntity(), NodeComponent.class); + SnapshotArray childrenEntities = nodeComponent.children; - Entity[] array = childrenEntities.toArray(); - HashSet result = new HashSet<>(Arrays.asList(array)); + Integer[] array = childrenEntities.toArray(); + HashSet result = new HashSet<>(Arrays.asList(array)); - for (Iterator i = result.iterator(); i.hasNext();) { - Entity element = i.next(); + for (Iterator i = result.iterator(); i.hasNext();) { + int element = i.next(); LayerItemVO layerItemVO = EntityUtils.getEntityLayer(element); if(layerItemVO != null && layerItemVO.isLocked) { i.remove(); @@ -318,22 +318,22 @@ public class ItemSelector { * removes all selected panels from the scene */ public void removeCurrentSelectedItems() { - for (Entity item : currentSelection) { + for (int item : currentSelection) { followersUIMediator.removeFollower(item); - sandbox.getEngine().removeEntity(item); + sandbox.getEngine().delete(item); } currentSelection.clear(); } - public void alignSelectionsByX(Entity relativeTo, boolean toHighestX) { - if (relativeTo == null) return; + public void alignSelectionsByX(int relativeTo, boolean toHighestX) { + if (relativeTo == -1) return; EntityBounds bounds = new EntityBounds(relativeTo); final float relativeToX = (toHighestX)? (bounds.getVisualRightX()) : bounds.getVisualX(); moveCommandBuilder.clear(); - for (Entity entity : currentSelection) { + for (int entity : currentSelection) { EntityBounds entityBounds = new EntityBounds(entity); final float deltaX = entityBounds.getX() - entityBounds.getVisualX(); final float visualX = relativeToX - ((toHighestX)? 1 : 0) * entityBounds.getVisualWidth(); @@ -343,14 +343,14 @@ public class ItemSelector { moveCommandBuilder.execute(); } - public void alignSelectionsByY(Entity relativeTo, boolean toHighestY) { - if (relativeTo == null) return; + public void alignSelectionsByY(int relativeTo, boolean toHighestY) { + if (relativeTo == -1) return; EntityBounds bounds = new EntityBounds(relativeTo); final float relativeToY = (toHighestY)? bounds.getVisualTopY() : bounds.getVisualY(); moveCommandBuilder.clear(); - for (Entity entity : currentSelection) { + for (int entity : currentSelection) { EntityBounds entityBounds = new EntityBounds(entity); final float deltaY = entityBounds.getY() - entityBounds.getVisualY(); final float visualY = relativeToY - ((toHighestY)? 1 : 0) * entityBounds.getVisualHeight(); @@ -360,14 +360,14 @@ public class ItemSelector { moveCommandBuilder.execute(); } - public void alignSelectionsAtLeftEdge(Entity relativeTo) { - if (relativeTo == null) return; + public void alignSelectionsAtLeftEdge(int relativeTo) { + if (relativeTo == -1) return; EntityBounds bounds = new EntityBounds(relativeTo); final float relativeToX = bounds.getVisualX(); moveCommandBuilder.clear(); - for (Entity entity : currentSelection) { + for (int entity : currentSelection) { if (entity == relativeTo) continue; EntityBounds entityBounds = new EntityBounds(entity); @@ -379,14 +379,14 @@ public class ItemSelector { moveCommandBuilder.execute(); } - public void alignSelectionsAtRightEdge(Entity relativeTo) { - if (relativeTo == null) return; + public void alignSelectionsAtRightEdge(int relativeTo) { + if (relativeTo == -1) return; EntityBounds bounds = new EntityBounds(relativeTo); final float relativeToRightX = bounds.getVisualRightX(); moveCommandBuilder.clear(); - for (Entity entity : currentSelection) { + for (int entity : currentSelection) { if (entity == relativeTo) continue; EntityBounds entityBounds = new EntityBounds(entity); @@ -397,14 +397,14 @@ public class ItemSelector { moveCommandBuilder.execute(); } - public void alignSelectionsAtTopEdge(Entity relativeTo) { - if (relativeTo == null) return; + public void alignSelectionsAtTopEdge(int relativeTo) { + if (relativeTo == -1) return; EntityBounds bounds = new EntityBounds(relativeTo); final float relativeToTopY = bounds.getVisualTopY(); moveCommandBuilder.clear(); - for (Entity entity : currentSelection) { + for (int entity : currentSelection) { if (entity == relativeTo) continue; EntityBounds entityBounds = new EntityBounds(entity); @@ -415,14 +415,14 @@ public class ItemSelector { moveCommandBuilder.execute(); } - public void alignSelectionsAtBottomEdge(Entity relativeTo) { - if (relativeTo == null) return; + public void alignSelectionsAtBottomEdge(int relativeTo) { + if (relativeTo == -1) return; EntityBounds bounds = new EntityBounds(relativeTo); final float relativeToY = bounds.getVisualY(); moveCommandBuilder.clear(); - for (Entity entity : currentSelection) { + for (int entity : currentSelection) { if (entity == relativeTo) continue; EntityBounds entityBounds = new EntityBounds(entity); @@ -434,15 +434,15 @@ public class ItemSelector { moveCommandBuilder.execute(); } - public void alignSelectionsVerticallyCentered(Entity relativeTo) { - if (relativeTo == null) return; + public void alignSelectionsVerticallyCentered(int relativeTo) { + if (relativeTo == -1) return; EntityBounds bounds = new EntityBounds(relativeTo); final float relativeToY = bounds.getVisualY(); final float relativeToHeight = bounds.getVisualHeight(); moveCommandBuilder.clear(); - for (Entity entity : currentSelection) { + for (int entity : currentSelection) { if (entity == relativeTo) continue; EntityBounds entityBounds = new EntityBounds(entity); @@ -454,15 +454,15 @@ public class ItemSelector { moveCommandBuilder.execute(); } - public void alignSelectionsHorizontallyCentered(Entity relativeTo) { - if (relativeTo == null) return; + public void alignSelectionsHorizontallyCentered(int relativeTo) { + if (relativeTo == -1) return; EntityBounds bounds = new EntityBounds(relativeTo); final float relativeToX = bounds.getVisualX(); final float relativeToWidth = bounds.getVisualWidth(); moveCommandBuilder.clear(); - for (Entity entity : currentSelection) { + for (int entity : currentSelection) { if (entity == relativeTo) continue; EntityBounds entityBounds = new EntityBounds(entity); @@ -521,7 +521,7 @@ public class ItemSelector { * @param y */ public void moveSelectedItemsBy(float x, float y) { - for (Entity entity : currentSelection) { + for (int entity : currentSelection) { sandbox.itemControl.moveItemBy(entity, x, y); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_DATA_UPDATED, entity); } @@ -535,8 +535,8 @@ public class ItemSelector { if(currentSelection.isEmpty()) return false; - Entity entity = currentSelection.stream().findFirst().get(); - NodeComponent nodeComponent = entity.getComponent(NodeComponent.class); + int entity = currentSelection.stream().findFirst().get(); + NodeComponent nodeComponent = SandboxComponentRetriever.get(entity, NodeComponent.class); return nodeComponent != null; } diff --git a/src/main/java/games/rednblack/editor/view/stage/Sandbox.java b/src/main/java/games/rednblack/editor/view/stage/Sandbox.java index 9703429f..d7f33840 100644 --- a/src/main/java/games/rednblack/editor/view/stage/Sandbox.java +++ b/src/main/java/games/rednblack/editor/view/stage/Sandbox.java @@ -18,8 +18,6 @@ package games.rednblack.editor.view.stage; -import com.badlogic.ashley.core.Entity; -import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; import com.badlogic.gdx.graphics.Color; @@ -34,11 +32,13 @@ import com.badlogic.gdx.utils.Json; import com.badlogic.gdx.utils.viewport.Viewport; import com.kotcrab.vis.ui.util.ToastManager; import games.rednblack.editor.proxy.*; +import games.rednblack.editor.renderer.SceneConfiguration; import games.rednblack.editor.renderer.physics.PhysicsBodyLoader; import games.rednblack.editor.renderer.systems.LightSystem; import games.rednblack.editor.renderer.systems.ParticleSystem; import games.rednblack.editor.system.ParticleContinuousSystem; import games.rednblack.editor.system.TalosContinuousSystem; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.tools.PanTool; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.h2d.extension.talos.TalosItemType; @@ -81,7 +81,7 @@ public class Sandbox { private final HashMap localClipboard = new HashMap<>(); - private Entity currentViewingEntity; + private int currentViewingEntity = -1; public String currentLoadedSceneFileName; private UIStage uiStage; @@ -129,24 +129,30 @@ public class Sandbox { UIStageMediator uiStageMediator = facade.retrieveMediator(UIStageMediator.NAME); uiStage = uiStageMediator.getViewComponent(); - sceneLoader = new SceneLoader(resourceManager); + SceneConfiguration config = new SceneConfiguration(); + config.setResourceRetriever(resourceManager); // adding spine as external component - sceneLoader.injectExternalItemType(new SpineItemType()); - sceneLoader.injectExternalItemType(new TalosItemType()); + config.addExternalItemType(new SpineItemType()); + config.addExternalItemType(new TalosItemType()); //Remove Physics System and add Adjusting System for box2d objects to follow items and stop world tick - sceneLoader.getEngine().removeSystem(sceneLoader.getEngine().getSystem(PhysicsSystem.class)); - sceneLoader.getEngine().removeSystem(sceneLoader.getEngine().getSystem(LightSystem.class)); + config.removeSystem(PhysicsSystem.class); + config.removeSystem(LightSystem.class); + PhysicsAdjustSystem physicsAdjustSystem = new PhysicsAdjustSystem(); + config.addSystem(physicsAdjustSystem); LightSystem lightSystem = new LightSystem(); - lightSystem.setRayHandler(sceneLoader.getRayHandler()); - sceneLoader.getEngine().addSystem(new PhysicsAdjustSystem(sceneLoader.getWorld())); - sceneLoader.getEngine().addSystem(lightSystem); + config.addSystem(lightSystem); //Remove particle system and use a continuous system for preview purpose - sceneLoader.getEngine().removeSystem(sceneLoader.getEngine().getSystem(ParticleSystem.class)); - sceneLoader.getEngine().addSystem(new ParticleContinuousSystem()); - sceneLoader.getEngine().removeSystem(sceneLoader.getEngine().getSystem(TalosSystem.class)); - sceneLoader.getEngine().addSystem(new TalosContinuousSystem()); + config.removeSystem(ParticleSystem.class); + config.addSystem(new ParticleContinuousSystem()); + config.removeSystem(TalosSystem.class); + config.addSystem(new TalosContinuousSystem()); + + sceneLoader = new SceneLoader(config); + + physicsAdjustSystem.setBox2DWorld(sceneLoader.getWorld()); + lightSystem.setRayHandler(sceneLoader.getRayHandler()); sceneControl = new SceneControlMediator(sceneLoader); itemControl = new ItemControlMediator(sceneControl); @@ -181,7 +187,7 @@ public class Sandbox { return sceneControl; } - public PooledEngine getEngine() { + public com.artemis.World getEngine() { return sceneLoader.getEngine(); } @@ -300,7 +306,7 @@ public class Sandbox { */ public SceneVO sceneVoFromItems() { CompositeVO newVo = new CompositeVO(); - newVo.loadFromEntity(getRootEntity()); + newVo.loadFromEntity(getRootEntity(), getEngine()); newVo.sStickyNotes.putAll(sceneControl.getCurrentSceneVO().composite.sStickyNotes); sceneControl.getCurrentSceneVO().composite = newVo; @@ -311,10 +317,6 @@ public class Sandbox { return selector; } - public Entity getCurrentScene() { - return sceneControl.getCurrentScene(); - } - public void prepareSelectionRectangle(float x, float y) { selectionRec.setOpacity(0.8f); selectionRec.setWidth(0); @@ -369,12 +371,12 @@ public class Sandbox { facade.sendNotification(MsgAPI.LOCK_LINES_CHANGED, lockLines); } - public Entity getRootEntity() { + public int getRootEntity() { return sceneControl.getRootEntity(); } public boolean isViewingRootEntity() { - return currentViewingEntity.equals(getRootEntity()); + return currentViewingEntity == getRootEntity(); } public void overrideAmbientLightInComposite() { @@ -410,17 +412,17 @@ public class Sandbox { return (OrthographicCamera) getViewport().getCamera(); } - public Entity getCurrentViewingEntity() { + public int getCurrentViewingEntity() { return currentViewingEntity; } - public void setCurrentViewingEntity(Entity entity) { + public void setCurrentViewingEntity(int entity) { currentViewingEntity = entity; } public ViewPortComponent getViewportComponent() { - if (getCurrentViewingEntity() == null) return null; - return ComponentRetriever.get(getCurrentViewingEntity(), ViewPortComponent.class); + if (getCurrentViewingEntity() == -1) return null; + return SandboxComponentRetriever.get(getCurrentViewingEntity(), ViewPortComponent.class); } public Viewport getViewport() { diff --git a/src/main/java/games/rednblack/editor/view/stage/SandboxMediator.java b/src/main/java/games/rednblack/editor/view/stage/SandboxMediator.java index cb5e864e..077f4449 100644 --- a/src/main/java/games/rednblack/editor/view/stage/SandboxMediator.java +++ b/src/main/java/games/rednblack/editor/view/stage/SandboxMediator.java @@ -18,9 +18,10 @@ package games.rednblack.editor.view.stage; -import com.badlogic.ashley.core.Engine; -import com.badlogic.ashley.core.Entity; -import com.badlogic.ashley.core.Family; +import com.artemis.Aspect; +import com.artemis.BaseComponentMapper; +import com.artemis.ComponentMapper; +import com.artemis.EntitySubscription; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.math.Vector2; @@ -29,6 +30,7 @@ import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.SnapshotArray; import com.kotcrab.vis.ui.FocusManager; import games.rednblack.editor.utils.KeyBindingsLayout; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.h2d.common.view.tools.Tool; import games.rednblack.editor.HyperLap2DFacade; @@ -156,13 +158,11 @@ public class SandboxMediator extends Mediator { } private void initItemListeners() { - Engine engine = getViewComponent().getEngine(); - Family rootFamily = Family.all(ViewPortComponent.class).get(); - Entity rootEntity = engine.getEntitiesFor(rootFamily).iterator().next(); - NodeComponent nodeComponent = ComponentRetriever.get(rootEntity, NodeComponent.class); - SnapshotArray childrenEntities = nodeComponent.children; + int rootEntity = Sandbox.getInstance().getCurrentViewingEntity(); + NodeComponent nodeComponent = SandboxComponentRetriever.get(rootEntity, NodeComponent.class); + SnapshotArray childrenEntities = nodeComponent.children; - for (Entity child: childrenEntities) { + for (int child: childrenEntities) { addListenerToItem(child); } } @@ -173,11 +173,11 @@ public class SandboxMediator extends Mediator { * * @param entity */ - private void addListenerToItem(Entity entity) { - InputListenerComponent inputListenerComponent = entity.getComponent(InputListenerComponent.class); + private void addListenerToItem(int entity) { + BaseComponentMapper mapper = ComponentMapper.getFor(InputListenerComponent.class, getViewComponent().getEngine()); + InputListenerComponent inputListenerComponent = mapper.get(entity); if(inputListenerComponent == null){ - inputListenerComponent = new InputListenerComponent(); - entity.add(inputListenerComponent); + inputListenerComponent = getViewComponent().getEngine().edit(entity).create(InputListenerComponent.class); } inputListenerComponent.removeAllListener(); inputListenerComponent.addListener(new SandboxItemEventListener(entity)); @@ -192,12 +192,12 @@ public class SandboxMediator extends Mediator { public class SandboxItemEventListener extends EntityClickListener { - public SandboxItemEventListener(final Entity entity) { + public SandboxItemEventListener(final int entity) { } @Override - public boolean touchDown(Entity entity, float x, float y, int pointer, int button) { + public boolean touchDown(int entity, float x, float y, int pointer, int button) { super.touchDown(entity, x, y, pointer, button); setSandboxFocus(); @@ -215,7 +215,7 @@ public class SandboxMediator extends Mediator { @Override - public void touchUp(Entity entity, float x, float y, int pointer, int button) { + public void touchUp(int entity, float x, float y, int pointer, int button) { super.touchUp(entity, x, y, pointer, button); Vector2 coords = getStageCoordinates(); @@ -239,7 +239,7 @@ public class SandboxMediator extends Mediator { } @Override - public void touchDragged(Entity entity, float x, float y, int pointer) { + public void touchDragged(int entity, float x, float y, int pointer) { Vector2 coords = getStageCoordinates(); if (currentSelectedTool != null) { @@ -248,7 +248,7 @@ public class SandboxMediator extends Mediator { } @Override - public boolean scrolled(Entity entity, float amountX, float amountY) { + public boolean scrolled(int entity, float amountX, float amountY) { return false; } @@ -260,7 +260,7 @@ public class SandboxMediator extends Mediator { } @Override - public boolean keyDown(Entity entity, int keycode) { + public boolean keyDown(int entity, int keycode) { Sandbox sandbox = Sandbox.getInstance(); if (sandbox.sceneControl.getCurrentSceneVO() == null) { return false; @@ -348,7 +348,7 @@ public class SandboxMediator extends Mediator { } @Override - public boolean keyUp(Entity entity, int keycode) { + public boolean keyUp(int entity, int keycode) { facade.sendNotification(MsgAPI.ACTION_KEY_UP, keycode); Sandbox sandbox = Sandbox.getInstance(); @@ -372,7 +372,7 @@ public class SandboxMediator extends Mediator { @Override - public boolean touchDown(Entity entity, float x, float y, int pointer, int button) { + public boolean touchDown(int entity, float x, float y, int pointer, int button) { super.touchDown(entity, x, y, pointer, button); setSandboxFocus(); @@ -392,7 +392,7 @@ public class SandboxMediator extends Mediator { } @Override - public void touchUp(Entity entity, float x, float y, int pointer, int button) { + public void touchUp(int entity, float x, float y, int pointer, int button) { super.touchUp(entity, x, y, pointer, button); if(currentSelectedTool != null) { @@ -420,7 +420,7 @@ public class SandboxMediator extends Mediator { } - private void doubleClick(Entity entity, float x, float y) { + private void doubleClick(int entity, float x, float y) { if (currentSelectedTool != null) { Sandbox sandbox = Sandbox.getInstance(); currentSelectedTool.stageMouseDoubleClick(x, y); @@ -428,7 +428,7 @@ public class SandboxMediator extends Mediator { } @Override - public void touchDragged(Entity entity, float x, float y, int pointer) { + public void touchDragged(int entity, float x, float y, int pointer) { if (currentSelectedTool != null) { Sandbox sandbox = Sandbox.getInstance(); currentSelectedTool.stageMouseDragged(x, y); @@ -437,7 +437,7 @@ public class SandboxMediator extends Mediator { @Override - public boolean scrolled(Entity entity, float amountX, float amountY) { + public boolean scrolled(int entity, float amountX, float amountY) { Sandbox sandbox = Sandbox.getInstance(); // well, duh if (amountX == 0 && amountY == 0) return false; diff --git a/src/main/java/games/rednblack/editor/view/stage/UIStageMediator.java b/src/main/java/games/rednblack/editor/view/stage/UIStageMediator.java index 8406d448..7def2bdd 100644 --- a/src/main/java/games/rednblack/editor/view/stage/UIStageMediator.java +++ b/src/main/java/games/rednblack/editor/view/stage/UIStageMediator.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.stage; -import com.badlogic.ashley.core.Entity; import games.rednblack.h2d.common.MsgAPI; import com.kotcrab.vis.ui.util.dialog.Dialogs; import com.kotcrab.vis.ui.util.dialog.InputDialogListener; @@ -57,7 +56,7 @@ public class UIStageMediator extends Mediator { case MsgAPI.SHOW_ADD_LIBRARY_DIALOG: Sandbox sandbox = Sandbox.getInstance(); - Entity item = notification.getBody(); + int item = notification.getBody(); Dialogs.showInputDialog(sandbox.getUIStage(), "New Library Item ", "Unique Name", new InputDialogListener() { @Override diff --git a/src/main/java/games/rednblack/editor/view/stage/input/EntityClickListener.java b/src/main/java/games/rednblack/editor/view/stage/input/EntityClickListener.java index 3509ce56..e0d42c9f 100644 --- a/src/main/java/games/rednblack/editor/view/stage/input/EntityClickListener.java +++ b/src/main/java/games/rednblack/editor/view/stage/input/EntityClickListener.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.stage.input; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Buttons; import com.badlogic.gdx.scenes.scene2d.Actor; @@ -27,8 +26,7 @@ public class EntityClickListener implements InputListener { private int tapCount; private long lastTapTime; - /** Create a listener where {@link #clicked(float, float)} is only called for left clicks. - * @see #ClickListener(int) */ + /** Create a listener where is only called for left clicks. */ public EntityClickListener () { } @@ -38,7 +36,7 @@ public class EntityClickListener implements InputListener { } @Override - public boolean touchDown (Entity entity, float x, float y, int pointer, int button) { + public boolean touchDown (int entity, float x, float y, int pointer, int button) { if (pressed) return false; if (pointer == 0 && this.button != -1 && button != this.button) return false; pressed = true; @@ -51,7 +49,7 @@ public class EntityClickListener implements InputListener { } @Override - public void touchDragged (Entity entity, float x, float y, int pointer) { + public void touchDragged (int entity, float x, float y, int pointer) { if (pointer != pressedPointer || cancelled) return; pressed = isOver(entity, x, y); if (pressed && pointer == 0 && button != -1 && !Gdx.input.isButtonPressed(button)) pressed = false; @@ -62,7 +60,7 @@ public class EntityClickListener implements InputListener { } @Override - public void touchUp (Entity entity, float x, float y, int pointer, int button) { + public void touchUp (int entity, float x, float y, int pointer, int button) { if (pointer == pressedPointer) { if (!cancelled) { boolean touchUpOver = isOver(entity, x, y); @@ -83,11 +81,11 @@ public class EntityClickListener implements InputListener { } } - public void enter (Entity entity, float x, float y, int pointer, Actor fromActor) { + public void enter (int entity, float x, float y, int pointer, Actor fromActor) { if (pointer == -1 && !cancelled) over = true; } - public void exit (Entity entity, float x, float y, int pointer, Actor toActor) { + public void exit (int entity, float x, float y, int pointer, Actor toActor) { if (pointer == -1 && !cancelled) over = false; } @@ -98,11 +96,11 @@ public class EntityClickListener implements InputListener { pressed = false; } - public void clicked (Entity entity, float x, float y) { + public void clicked (int entity, float x, float y) { } /** Returns true if the specified position is over the specified actor or within the tap square. */ - public boolean isOver (Entity entity, float x, float y) { + public boolean isOver (int entity, float x, float y) { //TODO this part // Actor hit = actor.hit(x, y, true); // if (hit == null || !hit.isDescendantOf(actor)) return inTapSquare(x, y); @@ -192,31 +190,31 @@ public class EntityClickListener implements InputListener { } @Override - public boolean keyDown(Entity entity, int keycode) { + public boolean keyDown(int entity, int keycode) { // TODO Auto-generated method stub return false; } @Override - public boolean keyUp(Entity entity, int keycode) { + public boolean keyUp(int entity, int keycode) { // TODO Auto-generated method stub return false; } @Override - public boolean keyTyped(Entity entity, char character) { + public boolean keyTyped(int entity, char character) { // TODO Auto-generated method stub return false; } @Override - public boolean mouseMoved(Entity entity, float screenX, float screenY) { + public boolean mouseMoved(int entity, float screenX, float screenY) { // TODO Auto-generated method stub return false; } @Override - public boolean scrolled(Entity entity, float amountX, float amountY) { + public boolean scrolled(int entity, float amountX, float amountY) { // TODO Auto-generated method stub return false; } diff --git a/src/main/java/games/rednblack/editor/view/stage/input/InputListener.java b/src/main/java/games/rednblack/editor/view/stage/input/InputListener.java index 196d726e..402a6160 100644 --- a/src/main/java/games/rednblack/editor/view/stage/input/InputListener.java +++ b/src/main/java/games/rednblack/editor/view/stage/input/InputListener.java @@ -1,23 +1,21 @@ package games.rednblack.editor.view.stage.input; -import com.badlogic.ashley.core.Entity; - public interface InputListener { - boolean keyDown(Entity entity, int keycode); + boolean keyDown(int entity, int keycode); - boolean keyUp(Entity entity, int keycode); + boolean keyUp(int entity, int keycode); - boolean keyTyped(Entity entity, char character); + boolean keyTyped(int entity, char character); - boolean touchDown(Entity entity, float screenX, float screenY, int pointer, int button); + boolean touchDown(int entity, float screenX, float screenY, int pointer, int button); - void touchUp(Entity entity, float screenX, float screenY, int pointer, int button); + void touchUp(int entity, float screenX, float screenY, int pointer, int button); - void touchDragged(Entity entity, float screenX, float screenY, int pointer); + void touchDragged(int entity, float screenX, float screenY, int pointer); - boolean mouseMoved(Entity entity, float screenX, float screenY); + boolean mouseMoved(int entity, float screenX, float screenY); - boolean scrolled(Entity entity, float amountX, float amountY); + boolean scrolled(int entity, float amountX, float amountY); } diff --git a/src/main/java/games/rednblack/editor/view/stage/input/InputListenerComponent.java b/src/main/java/games/rednblack/editor/view/stage/input/InputListenerComponent.java index 28601620..c0a76c45 100644 --- a/src/main/java/games/rednblack/editor/view/stage/input/InputListenerComponent.java +++ b/src/main/java/games/rednblack/editor/view/stage/input/InputListenerComponent.java @@ -1,9 +1,9 @@ package games.rednblack.editor.view.stage.input; -import com.badlogic.ashley.core.Component; +import com.artemis.Component; import com.badlogic.gdx.utils.Array; -public class InputListenerComponent implements Component { +public class InputListenerComponent extends Component { private Array listeners = new Array(1); public void addListener(InputListener listener){ diff --git a/src/main/java/games/rednblack/editor/view/stage/input/SandboxInputAdapter.java b/src/main/java/games/rednblack/editor/view/stage/input/SandboxInputAdapter.java index fa2b98f2..44c2f66e 100644 --- a/src/main/java/games/rednblack/editor/view/stage/input/SandboxInputAdapter.java +++ b/src/main/java/games/rednblack/editor/view/stage/input/SandboxInputAdapter.java @@ -1,6 +1,7 @@ package games.rednblack.editor.view.stage.input; -import com.badlogic.ashley.core.Entity; +import com.artemis.BaseComponentMapper; +import com.artemis.ComponentMapper; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.math.Intersector; @@ -12,6 +13,7 @@ import games.rednblack.editor.renderer.components.*; import games.rednblack.editor.renderer.data.LayerItemVO; import games.rednblack.editor.utils.EntityBounds; import games.rednblack.editor.utils.runtime.EntityUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.view.stage.SandboxMediator; @@ -21,9 +23,9 @@ import games.rednblack.editor.renderer.utils.ComponentRetriever; public class SandboxInputAdapter implements InputProcessor { private HyperLap2DFacade facade; - private Entity rootEntity; + private int rootEntity; private InputListenerComponent inpputListenerComponent; - private Entity target; + private int target; private Vector2 hitTargetLocalCoordinates = new Vector2(); private Sandbox sandbox; private final EntityBounds tempEntityBounds = new EntityBounds(); @@ -38,7 +40,7 @@ public class SandboxInputAdapter implements InputProcessor { public boolean keyDown(int keycode) { Array sandboxListeners = sandbox.getAllListeners(); for (int i = 0, s = sandboxListeners.size; i < s; i++) { - sandboxListeners.get(i).keyDown(null, keycode); + sandboxListeners.get(i).keyDown(-1, keycode); } return false; @@ -48,7 +50,7 @@ public class SandboxInputAdapter implements InputProcessor { public boolean keyUp(int keycode) { Array sandboxListeners = sandbox.getAllListeners(); for (int i = 0, s = sandboxListeners.size; i < s; i++) { - sandboxListeners.get(i).keyUp(null, keycode); + sandboxListeners.get(i).keyUp(-1, keycode); } return false; } @@ -57,7 +59,7 @@ public class SandboxInputAdapter implements InputProcessor { public boolean keyTyped(char character) { Array sandboxListeners = sandbox.getAllListeners(); for (int i = 0, s = sandboxListeners.size; i < s; i++) { - sandboxListeners.get(i).keyTyped(null, character); + sandboxListeners.get(i).keyTyped(-1, character); } return false; @@ -69,11 +71,11 @@ public class SandboxInputAdapter implements InputProcessor { //Handle Global Listeners than others rootEntity = sandbox.getCurrentViewingEntity(); - if(rootEntity == null){ + if(rootEntity == -1){ return false; } - Viewport viewPort = ComponentRetriever.get(rootEntity, ViewPortComponent.class).viewPort; + Viewport viewPort = SandboxComponentRetriever.get(rootEntity, ViewPortComponent.class).viewPort; if (screenX < viewPort.getScreenX() || screenX >= viewPort.getScreenX() + viewPort.getScreenWidth()) return false; if (Gdx.graphics.getHeight() - screenY < viewPort.getScreenY() || Gdx.graphics.getHeight() - screenY >= viewPort.getScreenY() + viewPort.getScreenHeight()) return false; @@ -82,13 +84,13 @@ public class SandboxInputAdapter implements InputProcessor { screenToSceneCoordinates(rootEntity, hitTargetLocalCoordinates); target = hit(rootEntity, hitTargetLocalCoordinates.x, hitTargetLocalCoordinates.y); - if(target == null){ + if(target == -1){ hitTargetLocalCoordinates.set(screenX, screenY); screenToSceneCoordinates(rootEntity, hitTargetLocalCoordinates); Array sandboxListeners = sandbox.getAllListeners(); for (int i = 0, s = sandboxListeners.size; i < s; i++) { - sandboxListeners.get(i).touchDown(null, hitTargetLocalCoordinates.x, hitTargetLocalCoordinates.y, pointer, button); + sandboxListeners.get(i).touchDown(-1, hitTargetLocalCoordinates.x, hitTargetLocalCoordinates.y, pointer, button); } return false; @@ -97,10 +99,11 @@ public class SandboxInputAdapter implements InputProcessor { hitTargetLocalCoordinates.set(screenX, screenY); screenToSceneCoordinates(rootEntity, hitTargetLocalCoordinates); - inpputListenerComponent = target.getComponent(InputListenerComponent.class); + BaseComponentMapper mapper = ComponentMapper.getFor(InputListenerComponent.class, sandbox.getEngine()); + inpputListenerComponent = mapper.get(target); if(inpputListenerComponent == null) return false; Array listeners = inpputListenerComponent.getAllListeners(); - TransformMathUtils.sceneToLocalCoordinates(target, hitTargetLocalCoordinates); + TransformMathUtils.sceneToLocalCoordinates(target, hitTargetLocalCoordinates, sandbox.getEngine()); for (int j = 0, s = listeners.size; j < s; j++) { if (listeners.get(j).touchDown(target, hitTargetLocalCoordinates.x, hitTargetLocalCoordinates.y, pointer, button)) { return true; @@ -114,28 +117,29 @@ public class SandboxInputAdapter implements InputProcessor { public boolean touchUp(int screenX, int screenY, int pointer, int button) { rootEntity = sandbox.getCurrentViewingEntity(); - if(rootEntity == null){ + if(rootEntity == -1){ return false; } - if(target == null){ + if(target == -1){ hitTargetLocalCoordinates.set(screenX, screenY); screenToSceneCoordinates(rootEntity, hitTargetLocalCoordinates); Array sandboxListeners = sandbox.getAllListeners(); for (int i = 0, s = sandboxListeners.size; i < s; i++) { - sandboxListeners.get(i).touchUp(null, hitTargetLocalCoordinates.x, hitTargetLocalCoordinates.y, pointer, button); + sandboxListeners.get(i).touchUp(-1, hitTargetLocalCoordinates.x, hitTargetLocalCoordinates.y, pointer, button); } return false; } - inpputListenerComponent = target.getComponent(InputListenerComponent.class); + BaseComponentMapper mapper = ComponentMapper.getFor(InputListenerComponent.class, sandbox.getEngine()); + inpputListenerComponent = mapper.get(target); if(inpputListenerComponent == null) return false; Array listeners = inpputListenerComponent.getAllListeners(); for (int j = 0, s = listeners.size; j < s; j++){ listeners.get(j).touchUp(target, screenX, screenY, pointer, button); } - target = null; + target = -1; return true; } @@ -143,22 +147,23 @@ public class SandboxInputAdapter implements InputProcessor { public boolean touchDragged(int screenX, int screenY, int pointer) { rootEntity = sandbox.getCurrentViewingEntity(); - if(rootEntity == null){ + if(rootEntity == -1){ return false; } - if(target == null){ + if(target == -1){ hitTargetLocalCoordinates.set(screenX, screenY); screenToSceneCoordinates(rootEntity, hitTargetLocalCoordinates); Array sandboxListeners = sandbox.getAllListeners(); for (int i = 0, s = sandboxListeners.size; i < s; i++) { - sandboxListeners.get(i).touchDragged(null, hitTargetLocalCoordinates.x, hitTargetLocalCoordinates.y, pointer); + sandboxListeners.get(i).touchDragged(-1, hitTargetLocalCoordinates.x, hitTargetLocalCoordinates.y, pointer); } return false; } - inpputListenerComponent = target.getComponent(InputListenerComponent.class); + BaseComponentMapper mapper = ComponentMapper.getFor(InputListenerComponent.class, sandbox.getEngine()); + inpputListenerComponent = mapper.get(target); if(inpputListenerComponent == null) return false; Array listeners = inpputListenerComponent.getAllListeners(); for (int j = 0, s = listeners.size; j < s; j++){ @@ -188,13 +193,13 @@ public class SandboxInputAdapter implements InputProcessor { public boolean scrolled(float amountX, float amountY) { rootEntity = sandbox.getCurrentViewingEntity(); - if(rootEntity == null){ + if(rootEntity == -1){ return false; } Array sandboxListeners = sandbox.getAllListeners(); for (int i = 0, s = sandboxListeners.size; i < s; i++) { - sandboxListeners.get(i).scrolled(null, amountX, amountY); + sandboxListeners.get(i).scrolled(-1, amountX, amountY); } //TODO scroll for other Entities don't know how deep tis should go all entities or only hit tested @@ -213,16 +218,16 @@ public class SandboxInputAdapter implements InputProcessor { Vector2 tmpVector2 = new Vector2(); - public Entity hit(Entity root, float x, float y){ + public int hit(int root, float x, float y){ Vector2 localCoordinates = tmpVector2.set(x, y); - TransformMathUtils.parentToLocalCoordinates(root, localCoordinates); + TransformMathUtils.parentToLocalCoordinates(root, localCoordinates, sandbox.getEngine()); - NodeComponent nodeComponent = ComponentRetriever.get(root, NodeComponent.class); - SnapshotArray childrenEntities = nodeComponent.children; + NodeComponent nodeComponent = SandboxComponentRetriever.get(root, NodeComponent.class); + SnapshotArray childrenEntities = nodeComponent.children; int n = childrenEntities.size-1; for (int i = n; i >= 0; i--){ - Entity childEntity = childrenEntities.get(i); + int childEntity = childrenEntities.get(i); // get layer locked or not LayerItemVO layerItemVO = EntityUtils.getEntityLayer(childEntity); @@ -234,11 +239,11 @@ public class SandboxInputAdapter implements InputProcessor { return childEntity; } } - return null; + return -1; } - public Vector2 screenToSceneCoordinates (Entity root, Vector2 screenCoords) { - ViewPortComponent viewPortComponent = ComponentRetriever.get(root, ViewPortComponent.class); + public Vector2 screenToSceneCoordinates (int root, Vector2 screenCoords) { + ViewPortComponent viewPortComponent = SandboxComponentRetriever.get(root, ViewPortComponent.class); viewPortComponent.viewPort.unproject(screenCoords); return screenCoords; } diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/ConeLightTool.java b/src/main/java/games/rednblack/editor/view/stage/tools/ConeLightTool.java index 34bd850f..29aaf664 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/ConeLightTool.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/ConeLightTool.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.stage.tools; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import games.rednblack.editor.factory.ItemFactory; import games.rednblack.editor.renderer.data.LightVO; @@ -47,7 +46,7 @@ public class ConeLightTool extends ItemDropTool { } @Override - public Entity putItem(float x, float y) { + public int putItem(float x, float y) { //LayerItemVO layer = Sandbox.getInstance().getItemFactory().getSelectedLayer(); LightVO vo = new LightVO(); vo.type = LightVO.LightType.CONE; diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/ItemDropTool.java b/src/main/java/games/rednblack/editor/view/stage/tools/ItemDropTool.java index 7fa5baf7..e05ebfbb 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/ItemDropTool.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/ItemDropTool.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.stage.tools; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.utils.runtime.EntityUtils; /** @@ -14,7 +13,7 @@ public abstract class ItemDropTool extends SelectionTool { @Override public boolean stageMouseDown(float x, float y) { - Entity entity = putItem(x, y); + int entity = putItem(x, y); return false; } @@ -25,7 +24,7 @@ public abstract class ItemDropTool extends SelectionTool { } @Override - public boolean itemMouseDown(Entity entity, float x, float y) { + public boolean itemMouseDown(int entity, float x, float y) { if(checkFilter(entity)) { return super.itemMouseDown(entity, x, y); } else { @@ -36,7 +35,7 @@ public abstract class ItemDropTool extends SelectionTool { } @Override - public void itemMouseDragged(Entity entity, float x, float y) { + public void itemMouseDragged(int entity, float x, float y) { if(checkFilter(entity)) { super.itemMouseDragged(entity, x, y); } @@ -44,13 +43,13 @@ public abstract class ItemDropTool extends SelectionTool { } @Override - public void itemMouseUp(Entity entity, float x, float y) { + public void itemMouseUp(int entity, float x, float y) { if(checkFilter(entity)) { super.itemMouseUp(entity, x, y); } } - protected boolean checkFilter(Entity entity) { + protected boolean checkFilter(int entity) { int[] itemTypes = listItemFilters(); for(int i = 0; i < itemTypes.length; i++) { if(itemTypes[i] == EntityUtils.getType(entity)) { @@ -61,7 +60,7 @@ public abstract class ItemDropTool extends SelectionTool { return false; } - public abstract Entity putItem(float x, float y); + public abstract int putItem(float x, float y); public abstract int[] listItemFilters(); } diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/PanTool.java b/src/main/java/games/rednblack/editor/view/stage/tools/PanTool.java index dfea2b3e..5b63d20f 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/PanTool.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/PanTool.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.stage.tools; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.math.Vector2; @@ -71,7 +70,7 @@ public class PanTool extends SimpleTool { } @Override - public boolean itemMouseDown(Entity entity, float x, float y) { + public boolean itemMouseDown(int entity, float x, float y) { lastCoordinates.set(Gdx.input.getX(), Gdx.input.getY()); currX = Sandbox.getInstance().getCamera().position.x; currY = Sandbox.getInstance().getCamera().position.y; @@ -79,17 +78,17 @@ public class PanTool extends SimpleTool { } @Override - public void itemMouseUp(Entity entity, float x, float y) { + public void itemMouseUp(int entity, float x, float y) { } @Override - public void itemMouseDragged(Entity entity, float x, float y) { + public void itemMouseDragged(int entity, float x, float y) { doPanning(x, y); } @Override - public void itemMouseDoubleClick(Entity entity, float x, float y) { + public void itemMouseDoubleClick(int entity, float x, float y) { } diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/PointLightTool.java b/src/main/java/games/rednblack/editor/view/stage/tools/PointLightTool.java index 62cfe399..2b1156c7 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/PointLightTool.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/PointLightTool.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.stage.tools; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import games.rednblack.editor.factory.ItemFactory; import games.rednblack.editor.renderer.data.LightVO; @@ -47,7 +46,7 @@ public class PointLightTool extends ItemDropTool { } @Override - public Entity putItem(float x, float y) { + public int putItem(float x, float y) { LightVO vo = new LightVO(); vo.type = LightVO.LightType.POINT; vo.distance = vo.distance / sandbox.getPixelPerWU(); diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/PolygonTool.java b/src/main/java/games/rednblack/editor/view/stage/tools/PolygonTool.java index c0c692e3..ca5cd5ba 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/PolygonTool.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/PolygonTool.java @@ -18,9 +18,9 @@ package games.rednblack.editor.view.stage.tools; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Input; import com.badlogic.gdx.math.Vector2; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.AddComponentToItemCommand; @@ -95,7 +95,7 @@ public class PolygonTool extends SelectionTool implements PolygonTransformationL } @Override - public boolean itemMouseDown(Entity entity, float x, float y) { + public boolean itemMouseDown(int entity, float x, float y) { lastSelectedMeshFollower = getMeshFollower(entity); return super.itemMouseDown(entity, x, y); } @@ -106,8 +106,8 @@ public class PolygonTool extends SelectionTool implements PolygonTransformationL private void updateSubFollowerList() { Sandbox sandbox = Sandbox.getInstance(); - Set selectedEntities = sandbox.getSelector().getSelectedItems(); - for(Entity entity: selectedEntities) { + Set selectedEntities = sandbox.getSelector().getSelectedItems(); + for(int entity: selectedEntities) { BasicFollower follower = followersUIMediator.getFollower(entity); follower.update(); follower.removeSubFollower(PolygonFollower.class); @@ -125,7 +125,7 @@ public class PolygonTool extends SelectionTool implements PolygonTransformationL @Override public void vertexDown(PolygonFollower follower, int vertexIndex, float x, float y) { - PolygonComponent polygonComponent = ComponentRetriever.get(follower.getEntity(), PolygonComponent.class); + PolygonComponent polygonComponent = SandboxComponentRetriever.get(follower.getEntity(), PolygonComponent.class); currentCommandPayload = UpdatePolygonDataCommand.payloadInitialState(follower.getEntity()); follower.getOriginalPoints().add(vertexIndex, new Vector2(x, y)); @@ -156,13 +156,13 @@ public class PolygonTool extends SelectionTool implements PolygonTransformationL follower.setSelectedAnchor(anchor); lastSelectedMeshFollower = follower; - PolygonComponent polygonComponent = ComponentRetriever.get(follower.getEntity(), PolygonComponent.class); + PolygonComponent polygonComponent = SandboxComponentRetriever.get(follower.getEntity(), PolygonComponent.class); polygonBackup = polygonComponent.vertices.clone(); } @Override public void anchorDragged(PolygonFollower follower, int anchor, float x, float y) { - PolygonComponent polygonComponent = ComponentRetriever.get(follower.getEntity(), PolygonComponent.class); + PolygonComponent polygonComponent = SandboxComponentRetriever.get(follower.getEntity(), PolygonComponent.class); Vector2[] points = follower.getOriginalPoints().toArray(new Vector2[0]); Vector2 diff = dragLastPoint.sub(x, y); @@ -192,7 +192,7 @@ public class PolygonTool extends SelectionTool implements PolygonTransformationL return; } - PolygonComponent polygonComponent = ComponentRetriever.get(follower.getEntity(), PolygonComponent.class); + PolygonComponent polygonComponent = SandboxComponentRetriever.get(follower.getEntity(), PolygonComponent.class); Vector2[] points = follower.getOriginalPoints().toArray(new Vector2[0]); @@ -219,7 +219,7 @@ public class PolygonTool extends SelectionTool implements PolygonTransformationL } @Override - public void keyDown(Entity entity, int keycode) { + public void keyDown(int entity, int keycode) { if(keycode == Input.Keys.DEL || keycode == Input.Keys.FORWARD_DEL) { if(!deleteSelectedAnchor()) { super.keyDown(entity, keycode); @@ -229,7 +229,7 @@ public class PolygonTool extends SelectionTool implements PolygonTransformationL } } - private PolygonFollower getMeshFollower(Entity entity) { + private PolygonFollower getMeshFollower(int entity) { FollowersUIMediator followersUIMediator = HyperLap2DFacade.getInstance().retrieveMediator(FollowersUIMediator.NAME); BasicFollower follower = followersUIMediator.getFollower(entity); @@ -239,7 +239,7 @@ public class PolygonTool extends SelectionTool implements PolygonTransformationL private boolean deleteSelectedAnchor() { PolygonFollower follower = lastSelectedMeshFollower; - PolygonComponent polygonComponent = ComponentRetriever.get(follower.getEntity(), PolygonComponent.class); + PolygonComponent polygonComponent = SandboxComponentRetriever.get(follower.getEntity(), PolygonComponent.class); if(follower != null) { if(polygonComponent == null || polygonComponent.vertices == null || polygonComponent.vertices.length == 0) return false; if(follower.getOriginalPoints().size() <= 3) return false; diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/SelectionTool.java b/src/main/java/games/rednblack/editor/view/stage/tools/SelectionTool.java index c5ec711c..ee6cad3c 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/SelectionTool.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/SelectionTool.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.stage.tools; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.OrthographicCamera; @@ -27,6 +26,7 @@ import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.viewport.Viewport; import com.kotcrab.vis.ui.util.OsUtils; import games.rednblack.editor.utils.KeyBindingsLayout; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.h2d.common.proxy.CursorManager; @@ -66,8 +66,8 @@ public class SelectionTool extends SimpleTool { private Vector2 directionVector = null; private Vector2 dragMouseStartPosition; - private HashMap dragStartPositions = new HashMap<>(); - private HashMap dragTouchDiff = new HashMap<>(); + private HashMap dragStartPositions = new HashMap<>(); + private HashMap dragTouchDiff = new HashMap<>(); private TransformComponent transformComponent; @@ -136,17 +136,17 @@ public class SelectionTool extends SimpleTool { @Override public void stageMouseDoubleClick(float x, float y) { - Entity currentView = sandbox.getCurrentViewingEntity(); - if (currentView == null) + int currentView = sandbox.getCurrentViewingEntity(); + if (currentView == -1) return; - ParentNodeComponent parentNodeComponent = ComponentRetriever.get(currentView, ParentNodeComponent.class); + ParentNodeComponent parentNodeComponent = SandboxComponentRetriever.get(currentView, ParentNodeComponent.class); if (parentNodeComponent != null) { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_CAMERA_CHANGE_COMPOSITE, parentNodeComponent.parentEntity); } } @Override - public boolean itemMouseDown(Entity entity, float x, float y) { + public boolean itemMouseDown(int entity, float x, float y) { isItemDown = true; sandbox = Sandbox.getInstance(); HyperLap2DFacade facade = HyperLap2DFacade.getInstance(); @@ -157,14 +157,14 @@ public class SelectionTool extends SimpleTool { if (isShiftPressed()) { if (!currentTouchedItemWasSelected) { // item was not selected, adding it to selection - Set items = new HashSet<>(); + Set items = new HashSet<>(); items.add(entity); facade.sendNotification(MsgAPI.ACTION_ADD_SELECTION, items); } } else { if (!currentTouchedItemWasSelected) { // get selection, add this item to selection - Set items = new HashSet<>(); + Set items = new HashSet<>(); items.add(entity); facade.sendNotification(MsgAPI.ACTION_SET_SELECTION, items); } @@ -173,8 +173,8 @@ public class SelectionTool extends SimpleTool { // remembering local touch position for each of selected boxes, if planning to drag dragStartPositions.clear(); dragTouchDiff.clear(); - for (Entity itemInstance : sandbox.getSelector().getCurrentSelection()) { - transformComponent = ComponentRetriever.get(itemInstance, TransformComponent.class); + for (int itemInstance : sandbox.getSelector().getCurrentSelection()) { + transformComponent = SandboxComponentRetriever.get(itemInstance, TransformComponent.class); if (transformComponent == null) continue; @@ -193,7 +193,7 @@ public class SelectionTool extends SimpleTool { private boolean isItemDown = false; @Override - public void itemMouseDragged(Entity entity, float x, float y) { + public void itemMouseDragged(int entity, float x, float y) { sandbox = Sandbox.getInstance(); if (!isDragging && (Gdx.input.isKeyPressed(Input.Keys.ALT_LEFT) || Gdx.input.isKeyPressed(Input.Keys.ALT_RIGHT))) { // first drag iteration and is copy mode @@ -203,8 +203,8 @@ public class SelectionTool extends SimpleTool { dragStartPositions.clear(); dragTouchDiff.clear(); - for (Entity itemInstance : sandbox.getSelector().getCurrentSelection()) { - transformComponent = ComponentRetriever.get(itemInstance, TransformComponent.class); + for (int itemInstance : sandbox.getSelector().getCurrentSelection()) { + transformComponent = SandboxComponentRetriever.get(itemInstance, TransformComponent.class); dragTouchDiff.put(itemInstance, new Vector2(x - transformComponent.x, y - transformComponent.y)); dragStartPositions.put(itemInstance, new Vector2(transformComponent.x, transformComponent.y)); @@ -246,8 +246,8 @@ public class SelectionTool extends SimpleTool { newY = MathUtils.floor(y / gridSize) * gridSize; // Selection rectangles should move and follow along - for (Entity itemInstance : sandbox.getSelector().getCurrentSelection()) { - transformComponent = ComponentRetriever.get(itemInstance, TransformComponent.class); + for (int itemInstance : sandbox.getSelector().getCurrentSelection()) { + transformComponent = SandboxComponentRetriever.get(itemInstance, TransformComponent.class); if (dragTouchDiff.get(itemInstance) == null) continue; @@ -277,8 +277,8 @@ public class SelectionTool extends SimpleTool { @Override public boolean stageMouseScrolled(float amountX, float amountY) { if (isItemDown) { - for (Entity itemInstance : sandbox.getSelector().getCurrentSelection()) { - transformComponent = ComponentRetriever.get(itemInstance, TransformComponent.class); + for (int itemInstance : sandbox.getSelector().getCurrentSelection()) { + transformComponent = SandboxComponentRetriever.get(itemInstance, TransformComponent.class); float degreeAmount = 3; if (amountX < 0 || amountY < 0) degreeAmount = -3; @@ -297,7 +297,7 @@ public class SelectionTool extends SimpleTool { } @Override - public void itemMouseUp(Entity entity, float x, float y) { + public void itemMouseUp(int entity, float x, float y) { isItemDown = false; sandbox = Sandbox.getInstance(); HyperLap2DFacade facade = HyperLap2DFacade.getInstance(); @@ -305,7 +305,7 @@ public class SelectionTool extends SimpleTool { if (currentTouchedItemWasSelected && !isDragging) { // item was selected (and no dragging was performed), so we need to release it if (isShiftPressed()) { - Set items = new HashSet<>(); + Set items = new HashSet<>(); items.add(entity); facade.sendNotification(MsgAPI.ACTION_RELEASE_SELECTION, items); } @@ -315,8 +315,8 @@ public class SelectionTool extends SimpleTool { if (isDragging) { // sets item position, and puts things into undo-redo que Array payloads = new Array<>(); - for (Entity itemInstance : sandbox.getSelector().getCurrentSelection()) { - transformComponent = ComponentRetriever.get(itemInstance, TransformComponent.class); + for (int itemInstance : sandbox.getSelector().getCurrentSelection()) { + transformComponent = SandboxComponentRetriever.get(itemInstance, TransformComponent.class); Vector2 newPosition = new Vector2(transformComponent.x, transformComponent.y); Vector2 oldPosition = dragStartPositions.get(itemInstance); @@ -335,7 +335,7 @@ public class SelectionTool extends SimpleTool { } @Override - public void itemMouseDoubleClick(Entity item, float x, float y) { + public void itemMouseDoubleClick(int item, float x, float y) { if (sandbox.getSelector().selectionIsComposite()) { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_CAMERA_CHANGE_COMPOSITE, item); } @@ -355,14 +355,14 @@ public class SelectionTool extends SimpleTool { Viewport viewport = Sandbox.getInstance().getViewport(); - HashSet freeItems = sandbox.getSelector().getAllFreeItems(); + HashSet freeItems = sandbox.getSelector().getAllFreeItems(); // when touch is up, selection process stops, and if any items got "caught" in they should be selected. // hiding selection rectangle sandbox.selectionRec.setOpacity(0.0f); //ArrayList curr = new ArrayList(); - Set curr = new HashSet<>(); + Set curr = new HashSet<>(); Rectangle sR = sandbox.screenToWorld(sandbox.selectionRec.getRect()); draggedRectanglePoints[0] = sR.x; @@ -374,9 +374,9 @@ public class SelectionTool extends SimpleTool { draggedRectanglePoints[6] = sR.x; draggedRectanglePoints[7] = sR.y + sR.height; - for (Entity entity : freeItems) { - transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + for (int entity : freeItems) { + transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); //if (!freeItems.get(i).isLockedByLayer() && Intersector.overlaps(sR, new Rectangle(entity.getX(), entity.getY(), entity.getWidth(), entity.getHeight()))) { @@ -399,14 +399,14 @@ public class SelectionTool extends SimpleTool { facade.sendNotification(MsgAPI.ACTION_SET_SELECTION, curr); } - private boolean isEntityVisible(Entity e) { + private boolean isEntityVisible(int e) { LayerItemVO layer = EntityUtils.getEntityLayer(e); return (layer == null || layer.isVisible); } @Override - public void keyDown(Entity entity, int keycode) { + public void keyDown(int entity, int keycode) { boolean isControlPressed = isControlPressed(); // the amount of pixels by which to move item if moving @@ -427,8 +427,8 @@ public class SelectionTool extends SimpleTool { if (!isControlPressed) { dragStartPositions.clear(); - for (Entity itemInstance : sandbox.getSelector().getCurrentSelection()) { - transformComponent = ComponentRetriever.get(itemInstance, TransformComponent.class); + for (int itemInstance : sandbox.getSelector().getCurrentSelection()) { + transformComponent = SandboxComponentRetriever.get(itemInstance, TransformComponent.class); if (transformComponent != null) dragStartPositions.put(itemInstance, new Vector2(transformComponent.x, transformComponent.y)); } @@ -452,8 +452,8 @@ public class SelectionTool extends SimpleTool { // sets item position, and puts things into undo-redo que Array payloads = new Array<>(); - for (Entity itemInstance : sandbox.getSelector().getCurrentSelection()) { - transformComponent = ComponentRetriever.get(itemInstance, TransformComponent.class); + for (int itemInstance : sandbox.getSelector().getCurrentSelection()) { + transformComponent = SandboxComponentRetriever.get(itemInstance, TransformComponent.class); if (transformComponent == null) continue; Vector2 newPosition = new Vector2(transformComponent.x, transformComponent.y); @@ -480,7 +480,7 @@ public class SelectionTool extends SimpleTool { } @Override - public void keyUp(Entity entity, int keycode) { + public void keyUp(int entity, int keycode) { } diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/SimpleTool.java b/src/main/java/games/rednblack/editor/view/stage/tools/SimpleTool.java index 1b40550a..607c2aba 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/SimpleTool.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/SimpleTool.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.stage.tools; -import com.badlogic.ashley.core.Entity; import games.rednblack.h2d.common.view.tools.Tool; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.view.stage.Sandbox; @@ -19,9 +18,9 @@ public abstract class SimpleTool implements Tool { @Override public void initTool() { Sandbox sandbox = Sandbox.getInstance(); - Set currSelection = sandbox.getSelector().getCurrentSelection(); + Set currSelection = sandbox.getSelector().getCurrentSelection(); FollowersUIMediator followersUIMediator = HyperLap2DFacade.getInstance().retrieveMediator(FollowersUIMediator.NAME); - for(Entity entity: currSelection) { + for(int entity: currSelection) { BasicFollower follower = followersUIMediator.getFollower(entity); if(follower instanceof NormalSelectionFollower) { NormalSelectionFollower selectionFollower = (NormalSelectionFollower) follower; @@ -56,22 +55,22 @@ public abstract class SimpleTool implements Tool { } @Override - public boolean itemMouseDown(Entity entity, float x, float y) { + public boolean itemMouseDown(int entity, float x, float y) { return false; } @Override - public void itemMouseUp(Entity entity, float x, float y) { + public void itemMouseUp(int entity, float x, float y) { } @Override - public void itemMouseDragged(Entity entity, float x, float y) { + public void itemMouseDragged(int entity, float x, float y) { } @Override - public void itemMouseDoubleClick(Entity entity, float x, float y) { + public void itemMouseDoubleClick(int entity, float x, float y) { } @@ -81,12 +80,12 @@ public abstract class SimpleTool implements Tool { } @Override - public void keyDown(Entity entity, int keycode) { + public void keyDown(int entity, int keycode) { } @Override - public void keyUp(Entity entity, int keycode) { + public void keyUp(int entity, int keycode) { } } diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/TextTool.java b/src/main/java/games/rednblack/editor/view/stage/tools/TextTool.java index 5015df16..18833265 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/TextTool.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/TextTool.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.stage.tools; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Align; @@ -78,12 +77,12 @@ public class TextTool extends ItemDropTool { } @Override - public Entity putItem(float x, float y) { + public int putItem(float x, float y) { if (getFontFamily() == null || getFontFamily().equals("")) { NativeDialogs.showError("No Font detected on your System.\n" + SystemUtils.OS_NAME + " " + SystemUtils.OS_VERSION + " (HyperLap2D v" + AppConfig.getInstance().versionString + ")"); - return null; + return -1; } return ItemFactory.get().createLabel(this, new Vector2(x, y)); } diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/TransformTool.java b/src/main/java/games/rednblack/editor/view/stage/tools/TransformTool.java index ddd54074..8138a154 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/TransformTool.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/TransformTool.java @@ -18,11 +18,11 @@ package games.rednblack.editor.view.stage.tools; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Input; import com.badlogic.gdx.math.Vector2; import com.kotcrab.vis.ui.util.OsUtils; import games.rednblack.editor.utils.KeyBindingsLayout; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.tools.transformStrategy.*; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; @@ -66,7 +66,7 @@ public class TransformTool extends SelectionTool implements FollowerTransformati private boolean fixCursor = false; - public void execute(Vector2 mouseInitialCoordinates, Vector2 mousePointStage, int anchor, Entity entity) { + public void execute(Vector2 mouseInitialCoordinates, Vector2 mousePointStage, int anchor, int entity) { float mouseDx = mousePointStage.x - mouseInitialCoordinates.x; float mouseDy = mousePointStage.y - mouseInitialCoordinates.y; @@ -107,7 +107,7 @@ public class TransformTool extends SelectionTool implements FollowerTransformati public void handleNotification(INotification notification) { switch (notification.getName()) { case MsgAPI.NEW_ITEM_ADDED: - updateListeners((Entity) notification.getBody()); + updateListeners((int) notification.getBody()); break; } } @@ -119,28 +119,28 @@ public class TransformTool extends SelectionTool implements FollowerTransformati } @Override - public void itemMouseUp(Entity entity, float x, float y) { + public void itemMouseUp(int entity, float x, float y) { super.itemMouseUp(entity, x, y); updateListeners(); } private void updateListeners() { Sandbox sandbox = Sandbox.getInstance(); - Set selectedEntities = sandbox.getSelector().getSelectedItems(); + Set selectedEntities = sandbox.getSelector().getSelectedItems(); updateListeners(selectedEntities); } - private void updateListeners(Entity entity) { - Set entities = new HashSet<>(); + private void updateListeners(int entity) { + Set entities = new HashSet<>(); entities.add(entity); updateListeners(entities); } - private void updateListeners(Set entities) { + private void updateListeners(Set entities) { FollowersUIMediator followersUIMediator = HyperLap2DFacade.getInstance().retrieveMediator(FollowersUIMediator.NAME); followersUIMediator.clearAllListeners(); - for (Entity entity : entities) { + for (int entity : entities) { if (followersUIMediator.getFollower(entity) != null) followersUIMediator.getFollower(entity).setFollowerListener(this); } @@ -152,9 +152,9 @@ public class TransformTool extends SelectionTool implements FollowerTransformati Sandbox sandbox = Sandbox.getInstance(); - commandBuilder.begin(follower.getEntity()); + commandBuilder.begin(follower.getEntity(), Sandbox.getInstance().getEngine()); - TransformComponent transformComponent = ComponentRetriever.get(follower.getEntity(), TransformComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(follower.getEntity(), TransformComponent.class); Vector2 mousePoint = sandbox.screenToWorld(x, y); mouseInitialCoordinates.set(mousePoint.x, mousePoint.y); @@ -177,7 +177,7 @@ public class TransformTool extends SelectionTool implements FollowerTransformati break; } - commandBuilder.begin(follower.getEntity()); + commandBuilder.begin(follower.getEntity(), sandbox.getEngine()); if (anchor == NormalSelectionFollower.ROTATION_LT || anchor == NormalSelectionFollower.ROTATION_RT || diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/AbstractTransformStrategy.java b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/AbstractTransformStrategy.java index 8670cb53..6e0be7b6 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/AbstractTransformStrategy.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/AbstractTransformStrategy.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.stage.tools.transformStrategy; - import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import games.rednblack.editor.renderer.components.TransformComponent; diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/BasicStrategy.java b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/BasicStrategy.java index a413d1a0..00502a94 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/BasicStrategy.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/BasicStrategy.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.stage.tools.transformStrategy; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.math.Vector2; @@ -9,6 +8,7 @@ import games.rednblack.editor.renderer.components.DimensionsComponent; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.RoundUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.ui.properties.panels.UIBasicItemPropertiesMediator; import games.rednblack.h2d.common.command.TransformCommandBuilder; import games.rednblack.editor.utils.runtime.EntityUtils; @@ -29,9 +29,9 @@ public class BasicStrategy extends AbstractTransformStrategy { private final Facade facade = HyperLap2DFacade.getInstance(); @Override - public void calculate(float mouseDx, float mouseDy, int anchor, Entity entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePointStage, float lastTransformAngle, float lastEntityAngle) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + public void calculate(float mouseDx, float mouseDy, int anchor, int entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePointStage, float lastTransformAngle, float lastEntityAngle) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); float scaleX = transformComponent.scaleX * (transformComponent.flipX ? -1 : 1); float scaleY = transformComponent.scaleY * (transformComponent.flipY ? -1 : 1); diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/ColorPrimitiveStrategy.java b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/ColorPrimitiveStrategy.java index ae929b3f..cc26d9a7 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/ColorPrimitiveStrategy.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/ColorPrimitiveStrategy.java @@ -1,18 +1,18 @@ package games.rednblack.editor.view.stage.tools.transformStrategy; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import games.rednblack.editor.renderer.components.DimensionsComponent; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.command.TransformCommandBuilder; import games.rednblack.editor.view.ui.followers.NormalSelectionFollower; public class ColorPrimitiveStrategy extends AbstractTransformStrategy { @Override - public void calculate(float mouseDx, float mouseDy, int anchor, Entity entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePoint, float lastTransformAngle, float lastEntityAngle) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + public void calculate(float mouseDx, float mouseDy, int anchor, int entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePoint, float lastTransformAngle, float lastEntityAngle) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); float newX = transformComponent.x; float newY = transformComponent.y; diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/CompositeStrategy.java b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/CompositeStrategy.java index 6851215d..32ae095b 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/CompositeStrategy.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/CompositeStrategy.java @@ -1,12 +1,11 @@ package games.rednblack.editor.view.stage.tools.transformStrategy; -import com.badlogic.ashley.core.ComponentMapper; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.SnapshotArray; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.ui.properties.panels.UIBasicItemPropertiesMediator; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; @@ -27,7 +26,6 @@ import java.util.*; */ public class CompositeStrategy extends AbstractTransformStrategy { - private ComponentMapper nodeMapper = ComponentMapper.getFor(NodeComponent.class); private HashMap childrenInitialPositions = new HashMap<>(); private HashMap childrenFinalPositions = new HashMap<>(); private final Array payloads = new Array<>(); @@ -43,13 +41,13 @@ public class CompositeStrategy extends AbstractTransformStrategy { private final Facade facade = HyperLap2DFacade.getInstance(); - public void getInitialPositions(Entity entity) { + public void getInitialPositions(int entity) { getParentState(entity, parentInitialPosition, parentInitialSize); childrenInitialPositions.clear(); getChildrenPositions(entity, childrenInitialPositions); } - public void swapItemFinalAndInitialStates(Entity entity) { + public void swapItemFinalAndInitialStates(int entity) { childrenFinalPositions.clear(); getChildrenPositions(entity, childrenFinalPositions); getParentState(entity, parentFinalPosition, parentFinalSize); @@ -60,7 +58,7 @@ public class CompositeStrategy extends AbstractTransformStrategy { sendResizePositionNotification(entity); } - private void sendResizePositionNotification(Entity entity) { + private void sendResizePositionNotification(int entity) { payloads.clear(); payloads.add(parentEntity(entity)); for (Map.Entry entrySet : childrenFinalPositions.entrySet()) { @@ -73,17 +71,17 @@ public class CompositeStrategy extends AbstractTransformStrategy { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_ITEM_AND_CHILDREN_TO, payloads); } - private void setParentState(Entity entity, Vector2 position, Vector2 size) { + private void setParentState(int entity, Vector2 position, Vector2 size) { EntityUtils.setPosition(entity, position); EntityUtils.setSize(entity, size); } - private void getParentState(Entity entity, Vector2 position, Vector2 size) { + private void getParentState(int entity, Vector2 position, Vector2 size) { EntityUtils.getPosition(entity, position); EntityUtils.getSize(entity, size); } - private Object[] parentEntity(Entity entity) { + private Object[] parentEntity(int entity) { Object[] obj = new Object[3]; obj[0] = entity; obj[1] = new Vector2(parentFinalPosition); @@ -91,11 +89,11 @@ public class CompositeStrategy extends AbstractTransformStrategy { return obj; } - private void getChildrenPositions(Entity parentEntity, HashMap entityPos) { - NodeComponent nodeComponent = nodeMapper.get(parentEntity); + private void getChildrenPositions(int parentEntity, HashMap entityPos) { + NodeComponent nodeComponent = SandboxComponentRetriever.get(parentEntity, NodeComponent.class); if (nodeComponent != null) { - for (Entity entity : nodeComponent.children) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + for (int entity : nodeComponent.children) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); Vector2 currentEntityPos = new Vector2(transformComponent.x, transformComponent.y); entityPos.put(EntityUtils.getEntityId(entity), currentEntityPos); } @@ -106,15 +104,15 @@ public class CompositeStrategy extends AbstractTransformStrategy { for (Map.Entry entrySet : posMap.entrySet()) { Integer id = entrySet.getKey(); Vector2 position = entrySet.getValue(); - Entity entity = EntityUtils.getByUniqueId(id); + int entity = EntityUtils.getByUniqueId(id); EntityUtils.setPosition(entity, position); } } @Override - public void calculate(float mouseDx, float mouseDy, int anchor, Entity entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePointStage, float lastTransformAngle, float lastEntityAngle) { - CompositeTransformComponent component = entity.getComponent(CompositeTransformComponent.class); - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + public void calculate(float mouseDx, float mouseDy, int anchor, int entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePointStage, float lastTransformAngle, float lastEntityAngle) { + CompositeTransformComponent component = SandboxComponentRetriever.get(entity, CompositeTransformComponent.class); + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); float[] horizontal = calculateSizeAndXyAmount(mouseDx, mouseDy, transformComponent.rotation, tmp1); float[] vertical = calculateSizeAndXyAmount(mouseDx, mouseDy, transformComponent.rotation + 90, tmp2); @@ -122,7 +120,7 @@ public class CompositeStrategy extends AbstractTransformStrategy { float deltaH = vertical[0] / transformComponent.scaleY; if (!component.automaticResize) { - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); float newWidth = dimensionsComponent.width; float newHeight = dimensionsComponent.height; @@ -246,11 +244,10 @@ public class CompositeStrategy extends AbstractTransformStrategy { || (mediator != null && mediator.isXYScaleLinked()); } - private void move(Entity node, float x, float y) { - ComponentMapper transMapper = ComponentMapper.getFor(TransformComponent.class); - SnapshotArray nodeEntity = node.getComponent(NodeComponent.class).children; - for (Entity child : nodeEntity) { - TransformComponent transformComponent = transMapper.get(child); + private void move(int node, float x, float y) { + SnapshotArray nodeEntity = SandboxComponentRetriever.get(node, NodeComponent.class).children; + for (int child : nodeEntity) { + TransformComponent transformComponent = SandboxComponentRetriever.get(child, TransformComponent.class); transformComponent.x += x; transformComponent.y += y; } diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/ITransformStrategy.java b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/ITransformStrategy.java index 30dea9eb..bac47c8b 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/ITransformStrategy.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/ITransformStrategy.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.stage.tools.transformStrategy; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import games.rednblack.h2d.common.command.TransformCommandBuilder; @@ -8,5 +7,5 @@ import games.rednblack.h2d.common.command.TransformCommandBuilder; * Created by Sasun Poghosyan on 4/13/2016. */ public interface ITransformStrategy { - void calculate(float mouseDx, float mouseDy, int anchor, Entity entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePoint, float lastTransformAngle, float lastEntityAngle); + void calculate(float mouseDx, float mouseDy, int anchor, int entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePoint, float lastTransformAngle, float lastEntityAngle); } diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/LabelStrategy.java b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/LabelStrategy.java index c500c369..6e0397c0 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/LabelStrategy.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/LabelStrategy.java @@ -1,19 +1,19 @@ package games.rednblack.editor.view.stage.tools.transformStrategy; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import games.rednblack.editor.renderer.components.DimensionsComponent; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.command.TransformCommandBuilder; import games.rednblack.editor.view.ui.followers.NormalSelectionFollower; public class LabelStrategy extends AbstractTransformStrategy { @Override - public void calculate(float mouseDx, float mouseDy, int anchor, Entity entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePoint, float lastTransformAngle, float lastEntityAngle) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + public void calculate(float mouseDx, float mouseDy, int anchor, int entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePoint, float lastTransformAngle, float lastEntityAngle) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); float newX = transformComponent.x; float newY = transformComponent.y; diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/NinePatchStrategy.java b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/NinePatchStrategy.java index 5ce34faa..a65753a5 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/NinePatchStrategy.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/transformStrategy/NinePatchStrategy.java @@ -1,11 +1,11 @@ package games.rednblack.editor.view.stage.tools.transformStrategy; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import games.rednblack.editor.renderer.components.DimensionsComponent; import games.rednblack.editor.renderer.components.NinePatchComponent; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.command.TransformCommandBuilder; import games.rednblack.editor.view.ui.followers.NormalSelectionFollower; @@ -15,16 +15,16 @@ import games.rednblack.editor.view.ui.followers.NormalSelectionFollower; public class NinePatchStrategy extends AbstractTransformStrategy { @Override - public void calculate(float mouseDx, float mouseDy, int anchor, Entity entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePointStage, float lastTransformAngle, float lastEntityAngle) { - TransformComponent transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - DimensionsComponent dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + public void calculate(float mouseDx, float mouseDy, int anchor, int entity, TransformCommandBuilder transformCommandBuilder, Vector2 mousePointStage, float lastTransformAngle, float lastEntityAngle) { + TransformComponent transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); float newX = transformComponent.x; float newY = transformComponent.y; float newWidth = dimensionsComponent.width; float newHeight = dimensionsComponent.height; - NinePatchComponent ninePatchComponent = ComponentRetriever.get(entity, NinePatchComponent.class); + NinePatchComponent ninePatchComponent = SandboxComponentRetriever.get(entity, NinePatchComponent.class); float minWidth = ninePatchComponent.ninePatch.getTotalWidth(); float minHeight = ninePatchComponent.ninePatch.getTotalHeight(); diff --git a/src/main/java/games/rednblack/editor/view/ui/FollowersUIMediator.java b/src/main/java/games/rednblack/editor/view/ui/FollowersUIMediator.java index 321bc9d4..c75fd626 100644 --- a/src/main/java/games/rednblack/editor/view/ui/FollowersUIMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/FollowersUIMediator.java @@ -18,7 +18,7 @@ package games.rednblack.editor.view.ui; -import com.badlogic.ashley.core.Entity; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.CompositeCameraChangeCommand; @@ -45,7 +45,7 @@ public class FollowersUIMediator extends Mediator { private static final String TAG = FollowersUIMediator.class.getCanonicalName(); public static final String NAME = TAG; - private final HashMap followers = new HashMap<>(); + private final HashMap followers = new HashMap<>(); public FollowersUIMediator() { super(NAME, new FollowersUI()); @@ -130,7 +130,7 @@ public class FollowersUIMediator extends Mediator { } } - private void clearAllSubFollowersExceptNew(Set items) { + private void clearAllSubFollowersExceptNew(Set items) { for (BasicFollower follower : followers.values()) { if(!items.contains(follower)) { if(follower instanceof NormalSelectionFollower) { @@ -140,9 +140,9 @@ public class FollowersUIMediator extends Mediator { } } - private void setNewSelectionConfiguration(Set items) { + private void setNewSelectionConfiguration(Set items) { followers.values().forEach(games.rednblack.editor.view.ui.followers.BasicFollower::hide); - for (Entity item : items) { + for (int item : items) { if (followers.get(item) != null) followers.get(item).show(); } @@ -151,9 +151,9 @@ public class FollowersUIMediator extends Mediator { private void createFollowersForAllVisible() { removeAllfollowers(); Sandbox sandbox = Sandbox.getInstance(); - NodeComponent nodeComponent = ComponentRetriever.get(sandbox.getCurrentViewingEntity(), NodeComponent.class); + NodeComponent nodeComponent = SandboxComponentRetriever.get(sandbox.getCurrentViewingEntity(), NodeComponent.class); - for (Entity entity: nodeComponent.children) { + for (int entity: nodeComponent.children) { createFollower(entity); } } @@ -163,17 +163,17 @@ public class FollowersUIMediator extends Mediator { followers.clear(); } - private void hideAllFollowers(Set items) { + private void hideAllFollowers(Set items) { if (followers != null) { - for (Entity item : items) { + for (int item : items) { followers.get(item).hide(); } } } - private void showAllFollowers(Set items) { + private void showAllFollowers(Set items) { if (followers != null) { - for (Entity item : items) { + for (int item : items) { if (followers.get(item) != null) followers.get(item).show(); } @@ -184,7 +184,7 @@ public class FollowersUIMediator extends Mediator { followers.values().forEach(games.rednblack.editor.view.ui.followers.BasicFollower::update); } - public void createFollower(Entity entity) { + public void createFollower(int entity) { BasicFollower follower = FollowerFactory.createFollower(entity); viewComponent.addActor(follower); followers.put(entity, follower); @@ -193,7 +193,7 @@ public class FollowersUIMediator extends Mediator { follower.handleNotification(new Notification(MsgAPI.TOOL_SELECTED, sandboxMediator.getCurrentSelectedToolName())); } - public void removeFollower(Entity entity) { + public void removeFollower(int entity) { BasicFollower follower = followers.remove(entity); if (follower != null) follower.remove(); @@ -203,7 +203,7 @@ public class FollowersUIMediator extends Mediator { followers.values().forEach(games.rednblack.editor.view.ui.followers.BasicFollower::clearFollowerListener); } - public BasicFollower getFollower(Entity entity) { + public BasicFollower getFollower(int entity) { return followers.get(entity); } } diff --git a/src/main/java/games/rednblack/editor/view/ui/box/UICompositeHierarchyMediator.java b/src/main/java/games/rednblack/editor/view/ui/box/UICompositeHierarchyMediator.java index 9f3ad27a..533c935d 100644 --- a/src/main/java/games/rednblack/editor/view/ui/box/UICompositeHierarchyMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/box/UICompositeHierarchyMediator.java @@ -1,7 +1,7 @@ package games.rednblack.editor.view.ui.box; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.Array; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.CompositeCameraChangeCommand; @@ -58,25 +58,25 @@ public class UICompositeHierarchyMediator extends Mediator } } - private void buildCompositeTree(Entity entity) { + private void buildCompositeTree(int entity) { viewComponent.clearItems(); Array items = new Array<>(); ParentNodeComponent parentNodeComponent; - Entity currEntity = entity; + int currEntity = entity; do { CompositeHierarchyItem item = new CompositeHierarchyItem(EntityUtils.getItemName(currEntity), EntityUtils.getEntityId(currEntity)); - parentNodeComponent = ComponentRetriever.get(currEntity, ParentNodeComponent.class); + parentNodeComponent = SandboxComponentRetriever.get(currEntity, ParentNodeComponent.class); if (parentNodeComponent != null) { currEntity = parentNodeComponent.parentEntity; item.isRoot = true; } items.add(item); - } while (parentNodeComponent != null); + } while (parentNodeComponent != null && currEntity != -1); items.reverse(); @@ -105,7 +105,7 @@ public class UICompositeHierarchyMediator extends Mediator //updateOriginalItem(scenes.get(scenes.size() - 1), commands.sceneControl.getCurrentScene()); } - private void updateOriginalItem(CompositeItemVO updatableVo, Entity currItem) { + private void updateOriginalItem(CompositeItemVO updatableVo, int currItem) { //TODO fix and uncomment // updatableVo.update(new CompositeItemVO(currItem.getDataVO().composite)); // diff --git a/src/main/java/games/rednblack/editor/view/ui/box/UIItemsTreeBox.java b/src/main/java/games/rednblack/editor/view/ui/box/UIItemsTreeBox.java index b56477a2..90129bc4 100644 --- a/src/main/java/games/rednblack/editor/view/ui/box/UIItemsTreeBox.java +++ b/src/main/java/games/rednblack/editor/view/ui/box/UIItemsTreeBox.java @@ -21,13 +21,11 @@ package games.rednblack.editor.view.ui.box; import java.util.Comparator; import java.util.Set; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.ui.Cell; import com.badlogic.gdx.scenes.scene2d.ui.Tree; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.Selection; -import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Array; import com.kotcrab.vis.ui.widget.*; import games.rednblack.editor.HyperLap2DFacade; @@ -37,6 +35,7 @@ import games.rednblack.editor.renderer.components.ParentNodeComponent; import games.rednblack.editor.renderer.components.ZIndexComponent; import games.rednblack.editor.renderer.factory.EntityFactory; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory; import games.rednblack.editor.utils.runtime.EntityUtils; @@ -49,7 +48,7 @@ public class UIItemsTreeBox extends UICollapsibleBox { private Tree tree; private UIItemsTreeNode rootNode; - private Set lastSelection; + private Set lastSelection; private final VisImageButton zUp, zDown; @@ -90,7 +89,7 @@ public class UIItemsTreeBox extends UICollapsibleBox { UIItemsTreeNode rootTreeNode; - public void init(Entity rootScene) { + public void init(int rootScene) { sandbox = Sandbox.getInstance(); treeTable.clear(); @@ -121,14 +120,14 @@ public class UIItemsTreeBox extends UICollapsibleBox { tree.updateRootNodes(); } - private UIItemsTreeNode addTreeRoot(Entity entity, UIItemsTreeNode parentNode) { // was like this addTreeRoot(CompositeItem compoiteItem, Node parentNode) + private UIItemsTreeNode addTreeRoot(int entity, UIItemsTreeNode parentNode) { // was like this addTreeRoot(CompositeItem compoiteItem, Node parentNode) UIItemsTreeNode node = addTreeNode(entity, parentNode); if (parentNode == null) rootNode = node; - NodeComponent nodeComponent = ComponentRetriever.get(entity, NodeComponent.class); + NodeComponent nodeComponent = SandboxComponentRetriever.get(entity, NodeComponent.class); if(nodeComponent != null) { - for (Entity item : nodeComponent.children) { + for (int item : nodeComponent.children) { if (EntityUtils.getType(entity) == EntityFactory.COMPOSITE_TYPE) { addTreeRoot(item, node); } else { @@ -139,10 +138,10 @@ public class UIItemsTreeBox extends UICollapsibleBox { return node; } - private UIItemsTreeNode addTreeNode(Entity item, UIItemsTreeNode parentNode) { + private UIItemsTreeNode addTreeNode(int item, UIItemsTreeNode parentNode) { String name, style; - ParentNodeComponent parentNodeComponent = ComponentRetriever.get(item, ParentNodeComponent.class); - MainItemComponent mainItemComponent = ComponentRetriever.get(item, MainItemComponent.class); + ParentNodeComponent parentNodeComponent = SandboxComponentRetriever.get(item, ParentNodeComponent.class); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(item, MainItemComponent.class); if (parentNodeComponent == null) { name = Sandbox.getInstance().sceneControl.getCurrentSceneVO().sceneName; @@ -161,7 +160,7 @@ public class UIItemsTreeBox extends UICollapsibleBox { VisTable label = new VisTable(); Cell lblCell = label.add(new VisLabel(name, style)); UIItemsTreeNode node = new UIItemsTreeNode(label); - ZIndexComponent zIndexComponent = ComponentRetriever.get(item, ZIndexComponent.class); + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(item, ZIndexComponent.class); node.setValue(new UIItemsTreeValue(mainItemComponent.uniqueId, zIndexComponent.getGlobalZIndex())); if (mainItemComponent.entityType != EntityFactory.COMPOSITE_TYPE) @@ -180,7 +179,7 @@ public class UIItemsTreeBox extends UICollapsibleBox { return node; } - public void setSelection(Set selection) { + public void setSelection(Set selection) { lastSelection = selection; if (tree == null) return; @@ -189,7 +188,7 @@ public class UIItemsTreeBox extends UICollapsibleBox { addToSelection(selection); } - public void addToSelection(Set selection) { + public void addToSelection(Set selection) { if (lastSelection != null && selection != null) lastSelection.addAll(selection); @@ -206,7 +205,7 @@ public class UIItemsTreeBox extends UICollapsibleBox { } } - public void removeFromSelection(Set selection) { + public void removeFromSelection(Set selection) { if (lastSelection != null && selection != null) lastSelection.removeAll(selection); @@ -231,7 +230,7 @@ public class UIItemsTreeBox extends UICollapsibleBox { facade.sendNotification(ITEMS_SELECTED, selection); if (selection.size() == 1 && getTapCount() == 2) { UIItemsTreeValue selected = selection.first().getValue(); - Entity item = EntityUtils.getByUniqueId(selected.entityId); + int item = EntityUtils.getByUniqueId(selected.entityId); if (EntityUtils.getType(item) == EntityFactory.COMPOSITE_TYPE) { HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_CAMERA_CHANGE_COMPOSITE, item); } diff --git a/src/main/java/games/rednblack/editor/view/ui/box/UIItemsTreeBoxMediator.java b/src/main/java/games/rednblack/editor/view/ui/box/UIItemsTreeBoxMediator.java index 61a47509..e2d1ee91 100644 --- a/src/main/java/games/rednblack/editor/view/ui/box/UIItemsTreeBoxMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/box/UIItemsTreeBoxMediator.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.ui.box; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.scenes.scene2d.utils.Selection; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.controller.commands.resource.DeleteResourceCommand; @@ -53,7 +52,7 @@ public class UIItemsTreeBoxMediator extends PanelMediator { Sandbox sandbox = Sandbox.getInstance(); switch (notification.getName()) { case MsgAPI.SCENE_LOADED: - Entity rootEntity = sandbox.getCurrentViewingEntity(); + int rootEntity = sandbox.getCurrentViewingEntity(); viewComponent.init(rootEntity); break; case MsgAPI.ACTION_CAMERA_CHANGE_COMPOSITE: @@ -71,17 +70,17 @@ public class UIItemsTreeBoxMediator extends PanelMediator { case UIItemsTreeBox.ITEMS_SELECTED: Selection selection = notification.getBody(); Array nodes = selection.toArray(); - Set items = new HashSet<>(); + Set items = new HashSet<>(); for (UIItemsTreeNode node : nodes) { Integer entityId = node.getValue().entityId; - Entity item = EntityUtils.getByUniqueId(entityId); + int item = EntityUtils.getByUniqueId(entityId); //layer lock thing LayerItemVO layerItemVO = EntityUtils.getEntityLayer(item); if(layerItemVO != null && layerItemVO.isLocked) { continue; } - if (item != null) { + if (item != -1) { items.add(item); } } @@ -97,8 +96,8 @@ public class UIItemsTreeBoxMediator extends PanelMediator { } } - private void sendSelectionNotification(Set items) { - Set ntfItems = (items.isEmpty())? null : items; + private void sendSelectionNotification(Set items) { + Set ntfItems = (items.isEmpty())? null : items; HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_SET_SELECTION, ntfItems); } } \ No newline at end of file diff --git a/src/main/java/games/rednblack/editor/view/ui/box/UILayerBoxMediator.java b/src/main/java/games/rednblack/editor/view/ui/box/UILayerBoxMediator.java index d5fabba6..fc60911c 100644 --- a/src/main/java/games/rednblack/editor/view/ui/box/UILayerBoxMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/box/UILayerBoxMediator.java @@ -18,7 +18,7 @@ package games.rednblack.editor.view.ui.box; -import com.badlogic.ashley.core.Entity; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import com.kotcrab.vis.ui.util.dialog.Dialogs; import com.kotcrab.vis.ui.util.dialog.InputDialogListener; @@ -174,9 +174,9 @@ public class UILayerBoxMediator extends PanelMediator { setEntityVisibilityByLayer(layerItem, true); break; case MsgAPI.ITEM_SELECTION_CHANGED: - Set selection = notification.getBody(); + Set selection = notification.getBody(); if(selection.size() == 1) { - ZIndexComponent zIndexComponent = ComponentRetriever.get(selection.iterator().next(), ZIndexComponent.class); + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(selection.iterator().next(), ZIndexComponent.class); index = findLayerByName(zIndexComponent.layerName); if(index == -1) { // handle this somehow @@ -190,8 +190,8 @@ public class UILayerBoxMediator extends PanelMediator { break; case MsgAPI.NEW_ITEM_ADDED: index = viewComponent.getCurrentSelectedLayerIndex(); - Entity item = notification.getBody(); - ZIndexComponent zIndexComponent = ComponentRetriever.get(item, ZIndexComponent.class); + int item = notification.getBody(); + ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(item, ZIndexComponent.class); if(zIndexComponent.layerName == null) zIndexComponent.layerName = layers.get(index).layerName; break; case UILayerBox.CHANGE_LAYER_NAME: @@ -238,7 +238,7 @@ public class UILayerBoxMediator extends PanelMediator { }*/ private void addNewLayerToItemComposite(LayerItemVO layerVo) { - LayerMapComponent layerMapComponent = ComponentRetriever.get(Sandbox.getInstance().getCurrentViewingEntity(), LayerMapComponent.class); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(Sandbox.getInstance().getCurrentViewingEntity(), LayerMapComponent.class); layerMapComponent.addLayer(layerVo); } @@ -247,8 +247,8 @@ public class UILayerBoxMediator extends PanelMediator { if(setLocked){ Sandbox.getInstance().getSelector().clearSelections(); } - Entity viewEntity = Sandbox.getInstance().getCurrentViewingEntity(); - LayerMapComponent layerMapComponent = ComponentRetriever.get(viewEntity, LayerMapComponent.class); + int viewEntity = Sandbox.getInstance().getCurrentViewingEntity(); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewEntity, LayerMapComponent.class); layerMapComponent.getLayer(layerName).isLocked = setLocked; } @@ -260,13 +260,13 @@ public class UILayerBoxMediator extends PanelMediator { return; } String layerName = layerItem.getLayerName(); - Entity viewEntity = Sandbox.getInstance().getCurrentViewingEntity(); + int viewEntity = Sandbox.getInstance().getCurrentViewingEntity(); - NodeComponent nodeComponent = ComponentRetriever.get(viewEntity, NodeComponent.class); - Set items = new HashSet<>(); + NodeComponent nodeComponent = SandboxComponentRetriever.get(viewEntity, NodeComponent.class); + Set items = new HashSet<>(); for(int i=0; i { private void setEntityVisibilityByLayer(UILayerBox.UILayerItem layerItem, boolean setVisible) { String layerName = layerItem.getLayerName(); - Entity viewEntity = Sandbox.getInstance().getCurrentViewingEntity(); + int viewEntity = Sandbox.getInstance().getCurrentViewingEntity(); - NodeComponent nodeComponent = ComponentRetriever.get(viewEntity, NodeComponent.class); + NodeComponent nodeComponent = SandboxComponentRetriever.get(viewEntity, NodeComponent.class); for(int i=0; i { } private void initLayerData() { - - Entity viewEntity = Sandbox.getInstance().getCurrentViewingEntity(); - LayerMapComponent layerMapComponent = ComponentRetriever.get(viewEntity, LayerMapComponent.class); + int viewEntity = Sandbox.getInstance().getCurrentViewingEntity(); + LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewEntity, LayerMapComponent.class); layers = layerMapComponent.getLayers(); viewComponent.clearItems(); diff --git a/src/main/java/games/rednblack/editor/view/ui/box/UIMultiPropertyBoxMediator.java b/src/main/java/games/rednblack/editor/view/ui/box/UIMultiPropertyBoxMediator.java index 4f259e16..73c98a15 100644 --- a/src/main/java/games/rednblack/editor/view/ui/box/UIMultiPropertyBoxMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/box/UIMultiPropertyBoxMediator.java @@ -23,10 +23,11 @@ import java.util.HashMap; import java.util.Set; import java.util.stream.Stream; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; +import games.rednblack.editor.view.ui.properties.UIAbstractPropertiesMediator; import org.puremvc.java.interfaces.IMediator; import org.puremvc.java.interfaces.INotification; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.reflect.ClassReflection; import com.badlogic.gdx.utils.reflect.ReflectionException; @@ -47,7 +48,6 @@ import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.editor.view.stage.SandboxMediator; import games.rednblack.editor.view.stage.tools.TextTool; import games.rednblack.editor.view.ui.properties.UIAbstractProperties; -import games.rednblack.editor.view.ui.properties.UIAbstractPropertiesMediator; import games.rednblack.editor.view.ui.properties.panels.UIBasicItemPropertiesMediator; import games.rednblack.editor.view.ui.properties.panels.UICompositeItemPropertiesMediator; import games.rednblack.editor.view.ui.properties.panels.UIImageItemPropertiesMediator; @@ -90,9 +90,8 @@ public class UIMultiPropertyBoxMediator extends PanelMediator(); - //TODO this is very bad, but PooledEngine$PooledEntity is private :( - classToMediatorMap.put("com.badlogic.ashley.core.PooledEngine$PooledEntity", new ArrayList<>()); - classToMediatorMap.get("com.badlogic.ashley.core.PooledEngine$PooledEntity").add(UIBasicItemPropertiesMediator.NAME); + classToMediatorMap.put(Integer.class.getName(), new ArrayList<>()); + classToMediatorMap.get(Integer.class.getName()).add(UIBasicItemPropertiesMediator.NAME); classToMediatorMap.put(SceneVO.class.getName(), new ArrayList<>()); classToMediatorMap.get(SceneVO.class.getName()).add(UIScenePropertiesMediator.NAME); @@ -126,7 +125,7 @@ public class UIMultiPropertyBoxMediator extends PanelMediator selection = notification.getBody(); + Set selection = notification.getBody(); if (selection.size() == 1) { initAllPropertyBoxes(selection.iterator().next()); } else if (selection.size() > 1) { @@ -157,8 +156,8 @@ public class UIMultiPropertyBoxMediator extends PanelMediator mediatorNames = new ArrayList<>(classToMediatorMap.get(mapName)); // TODO: this is not uber cool, gotta think a new way to make this class know nothing about entities - if (observable instanceof Entity) { - initEntityProperties(mediatorNames, (Entity) observable); + if (observable instanceof Integer) { + initEntityProperties(mediatorNames, (int) observable); } clearPropertyBoxes(); @@ -177,7 +176,7 @@ public class UIMultiPropertyBoxMediator extends PanelMediator mediatorNames, Entity entity) { + private void initEntityProperties(ArrayList mediatorNames, int entity) { int entityType = EntityUtils.getType(entity); if (entityType == EntityFactory.IMAGE_TYPE) { @@ -207,12 +206,12 @@ public class UIMultiPropertyBoxMediator extends PanelMediator selection) { + private void initMultipleSelectionPropertyBox(Set selection) { clearPropertyBoxes(); UIMultipleSelectPropertiesMediator mediator = new UIMultipleSelectPropertiesMediator(); facade.registerMediator(mediator); diff --git a/src/main/java/games/rednblack/editor/view/ui/dialog/AutoTraceDialogMediator.java b/src/main/java/games/rednblack/editor/view/ui/dialog/AutoTraceDialogMediator.java index 952dc254..040fa7a0 100644 --- a/src/main/java/games/rednblack/editor/view/ui/dialog/AutoTraceDialogMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/dialog/AutoTraceDialogMediator.java @@ -1,13 +1,14 @@ package games.rednblack.editor.view.ui.dialog; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import com.kotcrab.vis.ui.util.dialog.Dialogs; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.renderer.components.PolygonComponent; import games.rednblack.editor.renderer.components.TextureRegionComponent; +import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.utils.poly.PolygonUtils; import games.rednblack.editor.utils.poly.tracer.Tracer; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.editor.view.stage.UIStage; import games.rednblack.h2d.common.MsgAPI; @@ -21,7 +22,7 @@ public class AutoTraceDialogMediator extends Mediator { private static final String TAG = AutoTraceDialogMediator.class.getCanonicalName(); private static final String NAME = TAG; - private Entity entity; + private int entity; public AutoTraceDialogMediator() { super(NAME, new AutoTraceDialog()); @@ -59,10 +60,10 @@ public class AutoTraceDialogMediator extends Mediator { } private void addAutoTraceMesh() { - PolygonComponent polygonComponent = entity.getComponent(PolygonComponent.class); + PolygonComponent polygonComponent = SandboxComponentRetriever.get(entity, PolygonComponent.class); if (polygonComponent != null) { - TextureRegionComponent textureRegionComponent = entity.getComponent(TextureRegionComponent.class); + TextureRegionComponent textureRegionComponent = SandboxComponentRetriever.get(entity, TextureRegionComponent.class); if (textureRegionComponent != null && textureRegionComponent.region != null && !textureRegionComponent.regionName.equals("")) { polygonComponent.vertices = Tracer.trace(textureRegionComponent.region, viewComponent.getHullTolerance(), diff --git a/src/main/java/games/rednblack/editor/view/ui/followers/BasicFollower.java b/src/main/java/games/rednblack/editor/view/ui/followers/BasicFollower.java index f583d6ed..e001ec3e 100644 --- a/src/main/java/games/rednblack/editor/view/ui/followers/BasicFollower.java +++ b/src/main/java/games/rednblack/editor/view/ui/followers/BasicFollower.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.ui.followers; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; @@ -27,6 +26,7 @@ import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Pools; import games.rednblack.editor.renderer.components.MainItemComponent; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.editor.renderer.components.DimensionsComponent; import games.rednblack.editor.renderer.components.TransformComponent; @@ -41,7 +41,7 @@ public abstract class BasicFollower extends Group { protected TransformComponent transformComponent; protected DimensionsComponent dimensionsComponent; - protected Entity entity; + protected int entity; protected float pointOriginX; protected float pointOriginY; @@ -51,20 +51,20 @@ public abstract class BasicFollower extends Group { private final Array subFollowers = new Array<>(); - public BasicFollower(Entity entity) { + public BasicFollower(int entity) { setItem(entity); create(); update(); } - private void setItem(Entity entity) { - transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + private void setItem(int entity) { + transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); this.entity = entity; } public void update() { - if (ComponentRetriever.get(entity, MainItemComponent.class) == null) + if (SandboxComponentRetriever.get(entity, MainItemComponent.class) == null) return; Sandbox sandbox = Sandbox.getInstance(); @@ -77,7 +77,7 @@ public abstract class BasicFollower extends Group { position.x = 0; position.y = 0; - TransformMathUtils.localToAscendantCoordinates(sandbox.getCurrentViewingEntity(), entity, position); + TransformMathUtils.localToAscendantCoordinates(sandbox.getCurrentViewingEntity(), entity, position, sandbox.getEngine()); position = Sandbox.getInstance().worldToScreen(position); setX( ( int ) ( position.x ) ); @@ -164,7 +164,7 @@ public abstract class BasicFollower extends Group { } } - public Entity getEntity() { + public int getEntity() { return entity; } diff --git a/src/main/java/games/rednblack/editor/view/ui/followers/FollowerFactory.java b/src/main/java/games/rednblack/editor/view/ui/followers/FollowerFactory.java index 3c402daf..2e21508a 100644 --- a/src/main/java/games/rednblack/editor/view/ui/followers/FollowerFactory.java +++ b/src/main/java/games/rednblack/editor/view/ui/followers/FollowerFactory.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.ui.followers; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.factory.EntityFactory; import games.rednblack.editor.utils.runtime.EntityUtils; @@ -27,7 +26,7 @@ import games.rednblack.editor.utils.runtime.EntityUtils; */ public class FollowerFactory { - public static BasicFollower createFollower(Entity entity) { + public static BasicFollower createFollower(int entity) { switch (EntityUtils.getType(entity)) { case EntityFactory.IMAGE_TYPE: return new ImageFollower(entity); diff --git a/src/main/java/games/rednblack/editor/view/ui/followers/ImageFollower.java b/src/main/java/games/rednblack/editor/view/ui/followers/ImageFollower.java index e5cf2467..c96fd623 100644 --- a/src/main/java/games/rednblack/editor/view/ui/followers/ImageFollower.java +++ b/src/main/java/games/rednblack/editor/view/ui/followers/ImageFollower.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.ui.followers; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.renderer.components.TextureRegionComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; @@ -9,7 +8,7 @@ import games.rednblack.editor.renderer.utils.ComponentRetriever; */ public class ImageFollower extends NormalSelectionFollower { - public ImageFollower(Entity entity) { + public ImageFollower(int entity) { super(entity); } diff --git a/src/main/java/games/rednblack/editor/view/ui/followers/LightFollower.java b/src/main/java/games/rednblack/editor/view/ui/followers/LightFollower.java index be9048b1..74de451d 100644 --- a/src/main/java/games/rednblack/editor/view/ui/followers/LightFollower.java +++ b/src/main/java/games/rednblack/editor/view/ui/followers/LightFollower.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.ui.followers; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Color; @@ -35,7 +34,7 @@ public class LightFollower extends BasicFollower { private Image icon; - public LightFollower(Entity entity) { + public LightFollower(int entity) { super(entity); } diff --git a/src/main/java/games/rednblack/editor/view/ui/followers/NormalSelectionFollower.java b/src/main/java/games/rednblack/editor/view/ui/followers/NormalSelectionFollower.java index b24cf42b..940bab3a 100644 --- a/src/main/java/games/rednblack/editor/view/ui/followers/NormalSelectionFollower.java +++ b/src/main/java/games/rednblack/editor/view/ui/followers/NormalSelectionFollower.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.ui.followers; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.InputEvent; @@ -62,7 +61,7 @@ public class NormalSelectionFollower extends BasicFollower { } protected SelectionMode mode = SelectionMode.normal; - public NormalSelectionFollower(Entity entity) { + public NormalSelectionFollower(int entity) { super(entity); } diff --git a/src/main/java/games/rednblack/editor/view/ui/followers/ParticleFollower.java b/src/main/java/games/rednblack/editor/view/ui/followers/ParticleFollower.java index 33c19bb9..52328d4f 100644 --- a/src/main/java/games/rednblack/editor/view/ui/followers/ParticleFollower.java +++ b/src/main/java/games/rednblack/editor/view/ui/followers/ParticleFollower.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.ui.followers; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.scenes.scene2d.Touchable; import com.badlogic.gdx.scenes.scene2d.ui.Image; @@ -32,7 +31,7 @@ public class ParticleFollower extends BasicFollower { private Image icon; - public ParticleFollower(Entity entity) { + public ParticleFollower(int entity) { super(entity); setTransform(false); } diff --git a/src/main/java/games/rednblack/editor/view/ui/followers/PolygonFollower.java b/src/main/java/games/rednblack/editor/view/ui/followers/PolygonFollower.java index aac1058d..1435d03b 100644 --- a/src/main/java/games/rednblack/editor/view/ui/followers/PolygonFollower.java +++ b/src/main/java/games/rednblack/editor/view/ui/followers/PolygonFollower.java @@ -18,7 +18,6 @@ package games.rednblack.editor.view.ui.followers; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Color; @@ -36,6 +35,7 @@ import games.rednblack.editor.renderer.components.PolygonComponent; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.utils.PolygonUtils; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import java.util.ArrayList; @@ -72,7 +72,7 @@ public class PolygonFollower extends SubFollower { private final int pixelsPerWU; private final OrthographicCamera runtimeCamera = Sandbox.getInstance().getCamera(); - public PolygonFollower(Entity entity) { + public PolygonFollower(int entity) { super(entity); pixelsPerWU = Sandbox.getInstance().getPixelPerWU(); setTouchable(Touchable.enabled); @@ -80,8 +80,8 @@ public class PolygonFollower extends SubFollower { } public void create() { - polygonComponent = ComponentRetriever.get(entity, PolygonComponent.class); - transformComponent = ComponentRetriever.get(entity, TransformComponent.class); + polygonComponent = SandboxComponentRetriever.get(entity, PolygonComponent.class); + transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); shapeRenderer = new ShapeRenderer(); } @@ -366,7 +366,7 @@ public class PolygonFollower extends SubFollower { return -1; } - public Entity getEntity() { + public int getEntity() { return entity; } diff --git a/src/main/java/games/rednblack/editor/view/ui/followers/PolygonFollower2.java b/src/main/java/games/rednblack/editor/view/ui/followers/PolygonFollower2.java index 00ca12b3..2e72d052 100644 --- a/src/main/java/games/rednblack/editor/view/ui/followers/PolygonFollower2.java +++ b/src/main/java/games/rednblack/editor/view/ui/followers/PolygonFollower2.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.ui.followers; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.OrthographicCamera; @@ -18,6 +17,7 @@ import games.rednblack.editor.renderer.components.PolygonComponent; import games.rednblack.editor.renderer.components.TransformComponent; import games.rednblack.editor.renderer.utils.ComponentRetriever; import games.rednblack.editor.renderer.utils.PolygonUtils; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.editor.view.ui.widget.actors.basic.WhitePixel; import games.rednblack.editor.view.ui.widget.actors.polygon.PolyLine; @@ -64,7 +64,7 @@ public class PolygonFollower2 extends SubFollower { } }; - public PolygonFollower2(Entity entity) { + public PolygonFollower2(int entity) { super(entity); setTouchable(Touchable.enabled); pixelsPerWU = Sandbox.getInstance().getPixelPerWU(); @@ -72,9 +72,9 @@ public class PolygonFollower2 extends SubFollower { @Override public void create() { - polygonComponent = ComponentRetriever.get(entity, PolygonComponent.class); - transformComponent = ComponentRetriever.get(entity, TransformComponent.class); - dimensionsComponent = ComponentRetriever.get(entity, DimensionsComponent.class); + polygonComponent = SandboxComponentRetriever.get(entity, PolygonComponent.class); + transformComponent = SandboxComponentRetriever.get(entity, TransformComponent.class); + dimensionsComponent = SandboxComponentRetriever.get(entity, DimensionsComponent.class); } @Override @@ -204,7 +204,7 @@ public class PolygonFollower2 extends SubFollower { }); } - public Entity getEntity() { + public int getEntity() { return entity; } diff --git a/src/main/java/games/rednblack/editor/view/ui/followers/SpineFollower.java b/src/main/java/games/rednblack/editor/view/ui/followers/SpineFollower.java index 637fde36..0cbef8ec 100644 --- a/src/main/java/games/rednblack/editor/view/ui/followers/SpineFollower.java +++ b/src/main/java/games/rednblack/editor/view/ui/followers/SpineFollower.java @@ -1,12 +1,12 @@ package games.rednblack.editor.view.ui.followers; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.math.Matrix4; import com.esotericsoftware.spine.SkeletonRendererDebug; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.h2d.extention.spine.SpineObjectComponent; @@ -16,9 +16,9 @@ public class SpineFollower extends NormalSelectionFollower { private final Matrix4 matrix = new Matrix4(); - public SpineFollower(Entity entity) { + public SpineFollower(int entity) { super(entity); - spineObjectComponent = ComponentRetriever.get(entity, SpineObjectComponent.class); + spineObjectComponent = SandboxComponentRetriever.get(entity, SpineObjectComponent.class); skeletonRendererDebug = new SkeletonRendererDebug(); skeletonRendererDebug.setScale(2f); skeletonRendererDebug.setBoundingBoxes(false); diff --git a/src/main/java/games/rednblack/editor/view/ui/followers/SubFollower.java b/src/main/java/games/rednblack/editor/view/ui/followers/SubFollower.java index ff5f50ba..4e4ecdf6 100644 --- a/src/main/java/games/rednblack/editor/view/ui/followers/SubFollower.java +++ b/src/main/java/games/rednblack/editor/view/ui/followers/SubFollower.java @@ -1,6 +1,5 @@ package games.rednblack.editor.view.ui.followers; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.scenes.scene2d.Group; import org.puremvc.java.interfaces.INotification; @@ -9,15 +8,15 @@ import org.puremvc.java.interfaces.INotification; */ public abstract class SubFollower extends Group { - protected Entity entity; + protected int entity; protected BasicFollower parentFollower; - public SubFollower(Entity entity) { + public SubFollower(int entity) { setItem(entity); create(); } - private void setItem(Entity entity) { + private void setItem(int entity) { this.entity = entity; } diff --git a/src/main/java/games/rednblack/editor/view/ui/panel/CustomVariablesPanelMediator.java b/src/main/java/games/rednblack/editor/view/ui/panel/CustomVariablesPanelMediator.java index 69b3bee5..9a272d9a 100644 --- a/src/main/java/games/rednblack/editor/view/ui/panel/CustomVariablesPanelMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/panel/CustomVariablesPanelMediator.java @@ -18,7 +18,7 @@ package games.rednblack.editor.view.ui.panel; -import com.badlogic.ashley.core.Entity; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.menu.WindowMenu; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; @@ -40,7 +40,7 @@ public class CustomVariablesPanelMediator extends Mediator private static final String TAG = CustomVariablesPanelMediator.class.getCanonicalName(); private static final String NAME = TAG; - private Entity observable = null; + private int observable = -1; public CustomVariablesPanelMediator() { super(NAME, new CustomVariablesPanel()); @@ -79,7 +79,7 @@ public class CustomVariablesPanelMediator extends Mediator viewComponent.show(uiStage); break; case MsgAPI.ITEM_SELECTION_CHANGED: - Set selection = notification.getBody(); + Set selection = notification.getBody(); if (selection.size() == 1) { setObservable(selection.iterator().next()); } else { @@ -87,7 +87,7 @@ public class CustomVariablesPanelMediator extends Mediator } break; case MsgAPI.EMPTY_SPACE_CLICKED: - setObservable(null); + setObservable(-1); break; case CustomVariablesPanel.ADD_BUTTON_PRESSED: setVariable(); @@ -112,7 +112,7 @@ public class CustomVariablesPanelMediator extends Mediator sendNotification(MsgAPI.CUSTOM_VARIABLE_MODIFY, CustomVariableModifyCommand.removeCustomVariable(observable, key)); } - private void setObservable(Entity item) { + private void setObservable(int item) { observable = item; updateView(); viewComponent.setKeyFieldValue(""); @@ -120,10 +120,10 @@ public class CustomVariablesPanelMediator extends Mediator } private void updateView() { - if (observable == null) { + if (observable == -1) { viewComponent.setEmptyMsg("No item selected."); } else { - MainItemComponent mainItemComponent = ComponentRetriever.get(observable, MainItemComponent.class); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(observable, MainItemComponent.class); viewComponent.updateView(mainItemComponent.customVariables); } } diff --git a/src/main/java/games/rednblack/editor/view/ui/panel/EditSpriteAnimationPanelMediator.java b/src/main/java/games/rednblack/editor/view/ui/panel/EditSpriteAnimationPanelMediator.java index 9c7d353d..1b4f5a96 100644 --- a/src/main/java/games/rednblack/editor/view/ui/panel/EditSpriteAnimationPanelMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/panel/EditSpriteAnimationPanelMediator.java @@ -18,7 +18,7 @@ package games.rednblack.editor.view.ui.panel; -import com.badlogic.ashley.core.Entity; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.menu.WindowMenu; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; @@ -42,7 +42,7 @@ public class EditSpriteAnimationPanelMediator extends Mediator selection = notification.getBody(); + Set selection = notification.getBody(); if(selection.size() == 1) { - Entity entity = selection.iterator().next(); + int entity = selection.iterator().next(); if(EntityUtils.getType(entity) == EntityFactory.SPRITE_TYPE) { setObservable(entity); } else { - observable = null; + observable = -1; viewComponent.setEmpty("Selected item is not a sprite animation"); } } break; case MsgAPI.EMPTY_SPACE_CLICKED: - setObservable(null); + setObservable(-1); break; case EditSpriteAnimationPanel.ADD_BUTTON_PRESSED: addAnimation(); @@ -108,7 +108,7 @@ public class EditSpriteAnimationPanelMediator extends Mediator uniforms; - private HashMap customUniforms; + private ObjectMap uniforms; + private ObjectMap customUniforms; public ShaderUniformsPanel() { super("Shader Uniforms"); @@ -86,13 +84,13 @@ public class ShaderUniformsPanel extends UIDraggablePanel { pack(); } - public void updateView(HashMap uniforms, HashMap customUniforms) { + public void updateView(ObjectMap uniforms, ObjectMap customUniforms) { clearInputs(); getContentTable().clear(); this.uniforms = uniforms; this.customUniforms = customUniforms; - uniformName.setItems(uniforms.keySet().toArray(String[]::new)); + uniformName.setItems(uniforms.keys().toArray()); getContentTable().add(addUniformTable).growX().row(); hSeparator(getContentTable()); @@ -250,11 +248,11 @@ public class ShaderUniformsPanel extends UIDraggablePanel { uniformsTable.add(); uniformsTable.add().row(); - for (Map.Entry me : customUniforms.entrySet()) { - removeUniformFromList(me.getKey()); + for (String key : customUniforms.keys()) { + removeUniformFromList(key); - uniformsTable.add(new CellBody(me.getKey())); - ShaderUniformVO uniformVO = me.getValue(); + uniformsTable.add(new CellBody(key)); + ShaderUniformVO uniformVO = customUniforms.get(key); uniformsTable.add(new CellBody(uniformVO.getType())); @@ -285,8 +283,8 @@ public class ShaderUniformsPanel extends UIDraggablePanel { VisTable editTable = new VisTable(); LinkLabel editLabel = new LinkLabel("Edit"); editLabel.setListener(url -> { - addUniformFromList(me.getKey()); - uniformName.setSelected(me.getKey()); + addUniformFromList(key); + uniformName.setSelected(key); uniformName.setDisabled(true); editUniform(uniformVO); @@ -295,7 +293,7 @@ public class ShaderUniformsPanel extends UIDraggablePanel { editTable.add("/").padLeft(2).padRight(2); LinkLabel deleteLabel = new LinkLabel("Delete"); deleteLabel.setListener(url -> { - facade.sendNotification(REMOVE_BUTTON_CLICKED, me.getKey()); + facade.sendNotification(REMOVE_BUTTON_CLICKED, key); }); editTable.add(deleteLabel); uniformsTable.add(new CellBody(editTable)); diff --git a/src/main/java/games/rednblack/editor/view/ui/panel/ShaderUniformsPanelMediator.java b/src/main/java/games/rednblack/editor/view/ui/panel/ShaderUniformsPanelMediator.java index 72031dd3..bfe85f3d 100644 --- a/src/main/java/games/rednblack/editor/view/ui/panel/ShaderUniformsPanelMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/panel/ShaderUniformsPanelMediator.java @@ -1,10 +1,10 @@ package games.rednblack.editor.view.ui.panel; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.renderer.components.ShaderComponent; import games.rednblack.editor.renderer.data.ShaderUniformVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.menu.WindowMenu; import games.rednblack.editor.view.stage.Sandbox; import games.rednblack.editor.view.stage.UIStage; @@ -19,7 +19,7 @@ public class ShaderUniformsPanelMediator extends Mediator { private static final String TAG = ShaderUniformsPanelMediator.class.getCanonicalName(); private static final String NAME = TAG; - private Entity observable = null; + private int observable = -1; public ShaderUniformsPanelMediator() { super(NAME, new ShaderUniformsPanel()); @@ -58,16 +58,16 @@ public class ShaderUniformsPanelMediator extends Mediator { viewComponent.show(uiStage); break; case MsgAPI.ITEM_SELECTION_CHANGED: - Set selection = notification.getBody(); + Set selection = notification.getBody(); if (selection.size() == 1) { - Entity entity = selection.iterator().next(); + int entity = selection.iterator().next(); setObservable(entity); } else { - setObservable(null); + setObservable(-1); } break; case MsgAPI.EMPTY_SPACE_CLICKED: - setObservable(null); + setObservable(-1); break; case ShaderUniformsPanel.ADD_BUTTON_CLICKED: addNewUniform(notification.getBody()); @@ -78,18 +78,18 @@ public class ShaderUniformsPanelMediator extends Mediator { } } - private void setObservable(Entity item) { + private void setObservable(int item) { observable = item; updateView(); } private void updateView() { - if (observable == null) { + if (observable == -1) { viewComponent.setEmpty(); return; } - ShaderComponent shaderComponent = ComponentRetriever.get(observable, ShaderComponent.class); + ShaderComponent shaderComponent = SandboxComponentRetriever.get(observable, ShaderComponent.class); if (shaderComponent != null) viewComponent.updateView(shaderComponent.uniforms, shaderComponent.customUniforms); else @@ -117,14 +117,14 @@ public class ShaderUniformsPanelMediator extends Mediator { break; } - ShaderComponent shaderComponent = ComponentRetriever.get(observable, ShaderComponent.class); + ShaderComponent shaderComponent = SandboxComponentRetriever.get(observable, ShaderComponent.class); shaderComponent.customUniforms.put(name, vo); updateView(); } private void removeUniform(String uniform) { - ShaderComponent shaderComponent = ComponentRetriever.get(observable, ShaderComponent.class); + ShaderComponent shaderComponent = SandboxComponentRetriever.get(observable, ShaderComponent.class); shaderComponent.customUniforms.remove(uniform); updateView(); diff --git a/src/main/java/games/rednblack/editor/view/ui/panel/TagsPanelMediator.java b/src/main/java/games/rednblack/editor/view/ui/panel/TagsPanelMediator.java index 9d1645cb..6fc88f81 100644 --- a/src/main/java/games/rednblack/editor/view/ui/panel/TagsPanelMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/panel/TagsPanelMediator.java @@ -1,6 +1,6 @@ package games.rednblack.editor.view.ui.panel; -import com.badlogic.ashley.core.Entity; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.menu.WindowMenu; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; @@ -24,7 +24,7 @@ public class TagsPanelMediator extends Mediator { private static final String TAG = TagsPanelMediator.class.getCanonicalName(); private static final String NAME = TAG; - private final Set observables = new HashSet<>(); + private final Set observables = new HashSet<>(); public TagsPanelMediator() { super(NAME, new TagsPanel()); @@ -62,7 +62,7 @@ public class TagsPanelMediator extends Mediator { viewComponent.show(uiStage); break; case MsgAPI.ITEM_SELECTION_CHANGED: - Set selection = notification.getBody(); + Set selection = notification.getBody(); setObservable(selection); break; case MsgAPI.EMPTY_SPACE_CLICKED: @@ -71,23 +71,23 @@ public class TagsPanelMediator extends Mediator { case TagsPanel.ITEM_REMOVED: viewComponent.updateView(); String tagToRemove = notification.getBody(); - for (Entity observable : observables) { - MainItemComponent mainItemComponent = observable.getComponent(MainItemComponent.class); + for (int observable : observables) { + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(observable, MainItemComponent.class); mainItemComponent.tags.remove(tagToRemove); } break; case TagsPanel.ITEM_ADD: viewComponent.updateView(); String tagToAdd = notification.getBody(); - for (Entity observable : observables) { - MainItemComponent mainItemComponent = observable.getComponent(MainItemComponent.class); + for (int observable : observables) { + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(observable, MainItemComponent.class); mainItemComponent.tags.add(tagToAdd); } break; } } - private void setObservable(Set items) { + private void setObservable(Set items) { observables.clear(); if (items != null) observables.addAll(items); @@ -98,10 +98,10 @@ public class TagsPanelMediator extends Mediator { if(observables.size() == 0) { viewComponent.setEmpty(); } else { - Iterator iterator = observables.iterator(); + Iterator iterator = observables.iterator(); - Entity entity = iterator.next(); - MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + int entity = iterator.next(); + MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); if (mainItemComponent == null) return; Set common = new LinkedHashSet<>(); @@ -112,7 +112,7 @@ public class TagsPanelMediator extends Mediator { while (iterator.hasNext()) { entity = iterator.next(); - mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class); + mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class); toRetain.clear(); for (String tag : mainItemComponent.tags) toRetain.add(tag); diff --git a/src/main/java/games/rednblack/editor/view/ui/properties/UIAbstractEntityPropertiesMediator.java b/src/main/java/games/rednblack/editor/view/ui/properties/UIAbstractEntityPropertiesMediator.java new file mode 100644 index 00000000..ee73d041 --- /dev/null +++ b/src/main/java/games/rednblack/editor/view/ui/properties/UIAbstractEntityPropertiesMediator.java @@ -0,0 +1,104 @@ +/* + * ****************************************************************************** + * * Copyright 2015 See AUTHORS file. + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * ***************************************************************************** + */ + +package games.rednblack.editor.view.ui.properties; + +import games.rednblack.h2d.common.MsgAPI; +import games.rednblack.editor.HyperLap2DFacade; +import games.rednblack.editor.view.stage.Sandbox; +import org.puremvc.java.interfaces.INotification; +import org.puremvc.java.patterns.mediator.Mediator; + +/** + * Created by azakhary on 4/15/2015. + */ +public abstract class UIAbstractEntityPropertiesMediator extends UIAbstractPropertiesMediator { + protected Sandbox sandbox; + + protected int observableReference; + + protected boolean lockUpdates = true; + + public UIAbstractEntityPropertiesMediator(String mediatorName, V viewComponent) { + super(mediatorName, viewComponent); + + sandbox = Sandbox.getInstance(); + facade = HyperLap2DFacade.getInstance(); + } + + @Override + public void onRegister() { + facade = HyperLap2DFacade.getInstance(); + } + + + @Override + public String[] listNotificationInterests() { + return new String[]{ + MsgAPI.ITEM_DATA_UPDATED, + viewComponent.getUpdateEventName() + }; + } + + @Override + public void handleNotification(INotification notification) { + super.handleNotification(notification); + + + if(notification.getName().equals(viewComponent.getUpdateEventName())) { + if(!lockUpdates) { + translateViewToItemData(); + } + } + + switch (notification.getName()) { + case MsgAPI.ITEM_DATA_UPDATED: + onItemDataUpdate(); + break; + default: + break; + } + } + + @Override + public void setItem(Integer item) { + setItem((int) item); + } + + public void setItem(int item) { + observableReference = item; + lockUpdates = true; + translateObservableDataToView(observableReference); + lockUpdates = false; + } + + public void onItemDataUpdate() { + lockUpdates = true; + translateObservableDataToView(observableReference); + lockUpdates = false; + } + + @Override + protected void translateObservableDataToView(Integer item) { + translateObservableDataToView((int) item); + } + + protected abstract void translateObservableDataToView(int item); + + protected abstract void translateViewToItemData(); +} diff --git a/src/main/java/games/rednblack/editor/view/ui/properties/UIAbstractPropertiesMediator.java b/src/main/java/games/rednblack/editor/view/ui/properties/UIAbstractPropertiesMediator.java index 041b27c4..6958d839 100644 --- a/src/main/java/games/rednblack/editor/view/ui/properties/UIAbstractPropertiesMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/properties/UIAbstractPropertiesMediator.java @@ -1,32 +1,11 @@ -/* - * ****************************************************************************** - * * Copyright 2015 See AUTHORS file. - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * ***************************************************************************** - */ - package games.rednblack.editor.view.ui.properties; -import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.view.stage.Sandbox; +import games.rednblack.h2d.common.MsgAPI; import org.puremvc.java.interfaces.INotification; import org.puremvc.java.patterns.mediator.Mediator; -/** - * Created by azakhary on 4/15/2015. - */ public abstract class UIAbstractPropertiesMediator extends Mediator { private Sandbox sandbox; @@ -91,4 +70,4 @@ public abstract class UIAbstractPropertiesMediator extends UIAbstractPropertiesMediator { +public abstract class UIItemPropertiesMediator extends UIAbstractEntityPropertiesMediator { public UIItemPropertiesMediator(String mediatorName, V viewComponent) { super(mediatorName, viewComponent); @@ -48,7 +47,7 @@ public abstract class UIItemPropertiesMediator { +public class UIBasicItemPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UIBasicItemPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -114,7 +114,7 @@ public class UIBasicItemPropertiesMediator extends UIItemPropertiesMediator componentClass = componentClassMap.get(viewComponent.getSelectedComponent()); - if(componentClass == null) break; - Component component = ClassReflection.newInstance(componentClass); - facade.sendNotification(MsgAPI.ACTION_ADD_COMPONENT, AddComponentToItemCommand.payload(observableReference, component)); - } catch (ReflectionException ignored) {} + Class componentClass = componentClassMap.get(viewComponent.getSelectedComponent()); + if(componentClass == null) break; + facade.sendNotification(MsgAPI.ACTION_ADD_COMPONENT, AddComponentToItemCommand.payload(observableReference, componentClass)); break; default: break; @@ -161,7 +158,7 @@ public class UIBasicItemPropertiesMediator extends UIItemPropertiesMediator> entry : componentClassMap.entrySet()) { String componentName = entry.getKey(); Class componentClass = entry.getValue(); - Component component = entity.getComponent(componentClass); + Component component = SandboxComponentRetriever.get(entity, componentClass); if(component == null) { componentsToAddList.add(componentName); } @@ -230,12 +227,12 @@ public class UIBasicItemPropertiesMediator extends UIItemPropertiesMediator { +public class UICompositeItemPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UICompositeItemPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -45,16 +45,17 @@ public class UICompositeItemPropertiesMediator extends UIItemPropertiesMediator< } @Override - protected void translateObservableDataToView(Entity item) { - viewComponent.setAutomaticResize(item.getComponent(CompositeTransformComponent.class).automaticResize); - viewComponent.setScissorsEnabled(item.getComponent(CompositeTransformComponent.class).scissorsEnabled); - viewComponent.setRenderToFBOEnabled(item.getComponent(CompositeTransformComponent.class).renderToFBO); + protected void translateObservableDataToView(int item) { + CompositeTransformComponent transformComponent = SandboxComponentRetriever.get(item, CompositeTransformComponent.class); + viewComponent.setAutomaticResize(transformComponent.automaticResize); + viewComponent.setScissorsEnabled(transformComponent.scissorsEnabled); + viewComponent.setRenderToFBOEnabled(transformComponent.renderToFBO); } @Override protected void translateViewToItemData() { CompositeItemVO payloadVo = new CompositeItemVO(); - payloadVo.loadFromEntity(observableReference); + payloadVo.loadFromEntity(observableReference, sandbox.getEngine()); payloadVo.automaticResize = viewComponent.isAutomaticResizeIsEnabled(); payloadVo.scissorsEnabled = viewComponent.isScissorsEnabled(); @@ -65,10 +66,10 @@ public class UICompositeItemPropertiesMediator extends UIItemPropertiesMediator< CompositeSystem compositeSystem = Sandbox.getInstance().getEngine().getSystem(CompositeSystem.class); if (compositeSystem != null) { - compositeSystem.processEntity(observableReference, Gdx.graphics.getDeltaTime()); + compositeSystem.process(observableReference); } - Set entityHashSet = new HashSet<>(); + Set entityHashSet = new HashSet<>(); entityHashSet.add(observableReference); HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ITEM_SELECTION_CHANGED, entityHashSet); } diff --git a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIImageItemPropertiesMediator.java b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIImageItemPropertiesMediator.java index c3b2fe22..05f042f4 100644 --- a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIImageItemPropertiesMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIImageItemPropertiesMediator.java @@ -1,14 +1,14 @@ package games.rednblack.editor.view.ui.properties.panels; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.controller.commands.component.UpdateImageItemDataCommand; import games.rednblack.editor.renderer.components.TextureRegionComponent; import games.rednblack.editor.renderer.data.SimpleImageVO; import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.ui.properties.UIItemPropertiesMediator; import games.rednblack.h2d.common.MsgAPI; -public class UIImageItemPropertiesMediator extends UIItemPropertiesMediator { +public class UIImageItemPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UIImageItemPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -19,8 +19,8 @@ public class UIImageItemPropertiesMediator extends UIItemPropertiesMediator { +public class UILabelItemPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UILabelItemPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -59,13 +59,13 @@ public class UILabelItemPropertiesMediator extends UIItemPropertiesMediator { +public class UILightBodyPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UILightBodyPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -53,7 +55,7 @@ public class UILightBodyPropertiesMediator extends UIItemPropertiesMediator { +public class UILightItemPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UILightItemPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -40,8 +40,8 @@ public class UILightItemPropertiesMediator extends UIItemPropertiesMediator, UIMultipleSelectProperties> { +public class UIMultipleSelectPropertiesMediator extends UIAbstractPropertiesMediator, UIMultipleSelectProperties> { private static final String TAG = UIMultipleSelectPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -30,7 +29,7 @@ public class UIMultipleSelectPropertiesMediator extends UIAbstractPropertiesMedi } @Override - protected void translateObservableDataToView(Set selection) { + protected void translateObservableDataToView(Set selection) { viewComponent.setSelectionCount(selection.size()); } diff --git a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIParticlePropertiesMediator.java b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIParticlePropertiesMediator.java index c7e167a1..9c8de1d4 100644 --- a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIParticlePropertiesMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIParticlePropertiesMediator.java @@ -1,13 +1,14 @@ package games.rednblack.editor.view.ui.properties.panels; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.controller.commands.component.UpdateParticleDataCommand; import games.rednblack.editor.renderer.components.particle.ParticleComponent; import games.rednblack.editor.renderer.data.ParticleEffectVO; +import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.ui.properties.UIItemPropertiesMediator; import games.rednblack.h2d.common.MsgAPI; -public class UIParticlePropertiesMediator extends UIItemPropertiesMediator { +public class UIParticlePropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UIParticlePropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -17,8 +18,8 @@ public class UIParticlePropertiesMediator extends UIItemPropertiesMediator { +public class UIPhysicsPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UIPhysicsPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -45,8 +46,8 @@ public class UIPhysicsPropertiesMediator extends UIItemPropertiesMediator { +public class UIPolygonComponentPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UIPolygonComponentPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -87,8 +87,8 @@ public class UIPolygonComponentPropertiesMediator extends UIItemPropertiesMediat } @Override - protected void translateObservableDataToView(Entity item) { - polygonComponent = item.getComponent(PolygonComponent.class); + protected void translateObservableDataToView(int item) { + polygonComponent = SandboxComponentRetriever.get(item, PolygonComponent.class); if(polygonComponent.vertices != null) { viewComponent.initView(); int verticesCount = 0; @@ -110,7 +110,7 @@ public class UIPolygonComponentPropertiesMediator extends UIItemPropertiesMediat } private void addDefaultMesh() { - DimensionsComponent dimensionsComponent = ComponentRetriever.get(observableReference, DimensionsComponent.class); + DimensionsComponent dimensionsComponent = SandboxComponentRetriever.get(observableReference, DimensionsComponent.class); if(dimensionsComponent.boundBox != null) { // If the bound box is not null we have a Composite Item! polygonComponent.makeRectangle( dimensionsComponent.boundBox.x, dimensionsComponent.boundBox.y, dimensionsComponent.boundBox.width, dimensionsComponent.boundBox.height); } @@ -127,7 +127,7 @@ public class UIPolygonComponentPropertiesMediator extends UIItemPropertiesMediat } private void copyMesh() { - polygonComponent = observableReference.getComponent(PolygonComponent.class); + polygonComponent = SandboxComponentRetriever.get(observableReference, PolygonComponent.class); Sandbox.getInstance().copyToLocalClipboard("meshData", polygonComponent.vertices); } diff --git a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIScenePropertiesMediator.java b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIScenePropertiesMediator.java index 8b916dd2..77fd547c 100644 --- a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIScenePropertiesMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UIScenePropertiesMediator.java @@ -24,6 +24,7 @@ import games.rednblack.editor.controller.commands.UpdateSceneDataCommand; import games.rednblack.editor.proxy.ResolutionManager; import games.rednblack.editor.renderer.data.LightsPropertiesVO; import games.rednblack.editor.renderer.data.ResolutionEntryVO; +import games.rednblack.editor.view.ui.properties.UIAbstractPropertiesMediator; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.h2d.common.view.ui.widget.HyperLapColorPicker; import org.apache.commons.lang3.ArrayUtils; @@ -31,7 +32,6 @@ import org.apache.commons.lang3.math.NumberUtils; import com.badlogic.gdx.graphics.Color; import games.rednblack.editor.view.stage.Sandbox; -import games.rednblack.editor.view.ui.properties.UIAbstractPropertiesMediator; import games.rednblack.editor.renderer.data.PhysicsPropertiesVO; import games.rednblack.editor.renderer.data.SceneVO; import org.puremvc.java.interfaces.INotification; diff --git a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorPropertiesMediator.java b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorPropertiesMediator.java index da4f2f74..34bea7a2 100644 --- a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorPropertiesMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISensorPropertiesMediator.java @@ -1,11 +1,11 @@ package games.rednblack.editor.view.ui.properties.panels; +import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.math.NumberUtils; import org.puremvc.java.interfaces.INotification; -import com.badlogic.ashley.core.Entity; - import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.controller.commands.RemoveComponentFromItemCommand; import games.rednblack.editor.controller.commands.component.UpdateSensorDataCommand; @@ -19,7 +19,7 @@ import games.rednblack.h2d.common.MsgAPI; * * @author Jan-Thierry Wegener */ -public class UISensorPropertiesMediator extends UIItemPropertiesMediator { +public class UISensorPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UISensorPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -52,8 +52,8 @@ public class UISensorPropertiesMediator extends UIItemPropertiesMediator { +public class UIShaderPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UIShaderPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -101,8 +101,8 @@ public class UIShaderPropertiesMediator extends UIItemPropertiesMediator { +public class UISpineAnimationItemPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UISpineAnimationItemPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -41,9 +41,9 @@ public class UISpineAnimationItemPropertiesMediator extends UIItemPropertiesMedi } @Override - protected void translateObservableDataToView(Entity entity) { - spineObjectComponent = ComponentRetriever.get(entity, SpineObjectComponent.class); - spineDataComponent = ComponentRetriever.get(entity, SpineDataComponent.class); + protected void translateObservableDataToView(int entity) { + spineObjectComponent = SandboxComponentRetriever.get(entity, SpineObjectComponent.class); + spineDataComponent = SandboxComponentRetriever.get(entity, SpineDataComponent.class); Array animations = new Array<>(); for (Animation animation : spineObjectComponent.getAnimations()) { diff --git a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISpriteAnimationItemPropertiesMediator.java b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISpriteAnimationItemPropertiesMediator.java index 932daeb0..a6d46063 100644 --- a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISpriteAnimationItemPropertiesMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UISpriteAnimationItemPropertiesMediator.java @@ -18,9 +18,9 @@ package games.rednblack.editor.view.ui.properties.panels; -import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.utils.Array; import games.rednblack.editor.renderer.components.MainItemComponent; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.h2d.common.MsgAPI; import games.rednblack.editor.controller.commands.component.UpdateSpriteAnimationDataCommand; import games.rednblack.editor.renderer.components.sprite.SpriteAnimationComponent; @@ -32,7 +32,7 @@ import org.puremvc.java.interfaces.INotification; /** * Created by azakhary on 4/16/2015. */ -public class UISpriteAnimationItemPropertiesMediator extends UIItemPropertiesMediator { +public class UISpriteAnimationItemPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UISpriteAnimationItemPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -66,9 +66,9 @@ public class UISpriteAnimationItemPropertiesMediator extends UIItemPropertiesMed } @Override - protected void translateObservableDataToView(Entity entity) { + protected void translateObservableDataToView(int entity) { - spriteAnimationComponent = ComponentRetriever.get(entity, SpriteAnimationComponent.class); + spriteAnimationComponent = SandboxComponentRetriever.get(entity, SpriteAnimationComponent.class); Array animations = new Array<>(); spriteAnimationComponent.frameRangeMap.keySet().forEach(animations::add); diff --git a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UITalosPropertiesMediator.java b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UITalosPropertiesMediator.java index 3d0f88b7..d0c60072 100644 --- a/src/main/java/games/rednblack/editor/view/ui/properties/panels/UITalosPropertiesMediator.java +++ b/src/main/java/games/rednblack/editor/view/ui/properties/panels/UITalosPropertiesMediator.java @@ -1,13 +1,14 @@ package games.rednblack.editor.view.ui.properties.panels; -import com.badlogic.ashley.core.Entity; import games.rednblack.editor.controller.commands.component.UpdateTalosDataCommand; import games.rednblack.editor.renderer.components.particle.TalosDataComponent; import games.rednblack.editor.renderer.data.TalosVO; +import games.rednblack.editor.renderer.utils.ComponentRetriever; +import games.rednblack.editor.utils.runtime.SandboxComponentRetriever; import games.rednblack.editor.view.ui.properties.UIItemPropertiesMediator; import games.rednblack.h2d.common.MsgAPI; -public class UITalosPropertiesMediator extends UIItemPropertiesMediator { +public class UITalosPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UITalosPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -17,8 +18,8 @@ public class UITalosPropertiesMediator extends UIItemPropertiesMediator { +public class UITypingLabelPropertiesMediator extends UIItemPropertiesMediator { private static final String TAG = UITypingLabelPropertiesMediator.class.getCanonicalName(); public static final String NAME = TAG; @@ -44,12 +44,12 @@ public class UITypingLabelPropertiesMediator extends UIItemPropertiesMediator