Proper custom variable format
This commit is contained in:
Binary file not shown.
Submodule hyperlap2d-runtime-libgdx updated: c24d541c98...6fd267ee6f
@@ -26,6 +26,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.kotcrab.vis.ui.VisUI;
|
||||
import com.kotcrab.vis.ui.widget.VisImageButton;
|
||||
|
||||
@@ -45,7 +46,6 @@ import games.rednblack.editor.renderer.components.TextureRegionComponent;
|
||||
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.renderer.utils.CustomVariables;
|
||||
import games.rednblack.h2d.common.MenuAPI;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.h2d.common.plugins.H2DPluginAdapter;
|
||||
@@ -104,7 +104,7 @@ public class TiledPlugin extends H2DPluginAdapter {
|
||||
|
||||
private TileVO selectedTileVO;
|
||||
private AutoTileVO selectedAutoTileVO;
|
||||
private CustomVariables currentEntityCustomVariables;
|
||||
private ObjectMap<String, String> currentEntityCustomVariables;
|
||||
private MainItemComponent currentEntityMainItemComponent;
|
||||
private TransformComponent currentEntityTransformComponent;
|
||||
|
||||
@@ -114,7 +114,7 @@ public class TiledPlugin extends H2DPluginAdapter {
|
||||
super(CLASS_NAME);
|
||||
selectedTileVO = new TileVO();
|
||||
selectedAutoTileVO = new AutoTileVO();
|
||||
currentEntityCustomVariables = new CustomVariables();
|
||||
currentEntityCustomVariables = new ObjectMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,8 +179,8 @@ public class TiledPlugin extends H2DPluginAdapter {
|
||||
|
||||
currentEntityMainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class, getAPI().getEngine());
|
||||
currentEntityCustomVariables = currentEntityMainItemComponent.customVariables;
|
||||
if (currentEntityCustomVariables.getIntegerVariable(ROW) == row
|
||||
&& currentEntityCustomVariables.getIntegerVariable(COLUMN) == column) {
|
||||
if (Integer.parseInt(currentEntityCustomVariables.get(ROW)) == row
|
||||
&& Integer.parseInt(currentEntityCustomVariables.get(COLUMN)) == column) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -30,8 +30,8 @@ public class AutoGridTileManager {
|
||||
if (!mainItemComponent.tags.contains(TiledPlugin.AUTO_TILE_TAG)) {
|
||||
continue;
|
||||
}
|
||||
int col = mainItemComponent.customVariables.getIntegerVariable(TiledPlugin.COLUMN);
|
||||
int row = mainItemComponent.customVariables.getIntegerVariable(TiledPlugin.ROW);
|
||||
int col = Integer.parseInt(mainItemComponent.customVariables.get(TiledPlugin.COLUMN));
|
||||
int row = Integer.parseInt(mainItemComponent.customVariables.get(TiledPlugin.ROW));
|
||||
|
||||
int c = 0;
|
||||
int val = 0;
|
||||
@@ -78,7 +78,7 @@ public class AutoGridTileManager {
|
||||
|
||||
int index = getIndex(c, val);
|
||||
|
||||
String region = mainItemComponent.customVariables.getStringVariable(TiledPlugin.REGION) + index;
|
||||
String region = mainItemComponent.customVariables.get(TiledPlugin.REGION) + index;
|
||||
replaceRegionCommandBuilder.begin(entity);
|
||||
replaceRegionCommandBuilder.setRegion(tiledPlugin.getAPI().getSceneLoader().getRm().getTextureRegion(region));
|
||||
replaceRegionCommandBuilder.setRegionName(region);
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public class AutoTileDrawStrategy extends BasicDrawStrategy {
|
||||
if (!checkValidTile(entity)) return;
|
||||
|
||||
MainItemComponent mainItemComponent = ComponentRetriever.get(entity, MainItemComponent.class, tiledPlugin.getAPI().getEngine());
|
||||
if (tiledPlugin.getSelectedAutoTileName().equals(mainItemComponent.customVariables.getStringVariable(TiledPlugin.ORIG_AUTO_TILE))) {
|
||||
if (tiledPlugin.getSelectedAutoTileName().equals(mainItemComponent.customVariables.get(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
|
||||
// secondly, when dragging it constantly reselects between the alternative, making rare tiles even rarer
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class CustomVariableModifyCommand extends EntityModifyRevertibleCommand {
|
||||
private void removeVariable(String key) {
|
||||
int entity = EntityUtils.getByUniqueId(entityId);
|
||||
MainItemComponent mainItemComponent = SandboxComponentRetriever.get(entity, MainItemComponent.class);
|
||||
value = mainItemComponent.customVariables.getStringVariable(key); //storing the backup
|
||||
value = mainItemComponent.customVariables.get(key); //storing the backup
|
||||
mainItemComponent.removeCustomVars(key);
|
||||
}
|
||||
|
||||
|
||||
+29
-1
@@ -6,6 +6,7 @@ import com.badlogic.gdx.math.Circle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.JsonWriter;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import games.rednblack.editor.data.migrations.IVersionMigrator;
|
||||
import games.rednblack.editor.data.migrations.data020.CompositeVO;
|
||||
import games.rednblack.editor.renderer.data.*;
|
||||
@@ -17,6 +18,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class VersionMigTo100 implements IVersionMigrator {
|
||||
private final Json json = new Json();
|
||||
@@ -25,6 +28,8 @@ public class VersionMigTo100 implements IVersionMigrator {
|
||||
private ProjectVO projectVO;
|
||||
private games.rednblack.editor.data.migrations.data020.ProjectInfoVO projectInfoVO;
|
||||
|
||||
final Pattern customVarsPattern = Pattern.compile("\"customVars\":\"(.*?)\"", Pattern.MULTILINE);
|
||||
|
||||
@Override
|
||||
public void setProject(String path, ProjectVO vo, ProjectInfoVO projectInfoVO) {
|
||||
projectPath = path;
|
||||
@@ -40,6 +45,7 @@ public class VersionMigTo100 implements IVersionMigrator {
|
||||
e.printStackTrace();
|
||||
}
|
||||
projectInfoContents = projectInfoContents.replaceAll("\"polygons\"", "\"polygonizedVertices\"");
|
||||
projectInfoContents = migrateCustomVariableFormat(projectInfoContents);
|
||||
this.projectInfoVO = json.fromJson(games.rednblack.editor.data.migrations.data020.ProjectInfoVO.class, projectInfoContents);
|
||||
}
|
||||
|
||||
@@ -50,7 +56,10 @@ public class VersionMigTo100 implements IVersionMigrator {
|
||||
try {
|
||||
for (File scene : scenesDirectoryHandle.file().listFiles()) {
|
||||
String sceneString = FileUtils.readFileToString(scene, "utf-8");
|
||||
//Migrate polygon vertices
|
||||
sceneString = sceneString.replaceAll("\"polygons\"", "\"polygonizedVertices\"");
|
||||
sceneString = migrateCustomVariableFormat(sceneString);
|
||||
|
||||
games.rednblack.editor.data.migrations.data020.SceneVO sceneToExport = json.fromJson(games.rednblack.editor.data.migrations.data020.SceneVO.class, sceneString);
|
||||
|
||||
SceneVO newVO = new SceneVO();
|
||||
@@ -169,7 +178,6 @@ public class VersionMigTo100 implements IVersionMigrator {
|
||||
target.itemIdentifier = vo.itemIdentifier;
|
||||
target.itemName = vo.itemName;
|
||||
if(vo.tags != null) target.tags = Arrays.copyOf(vo.tags, vo.tags.length);
|
||||
target.customVars = vo.customVars;
|
||||
target.x = vo.x;
|
||||
target.y = vo.y;
|
||||
target.rotation = vo.rotation;
|
||||
@@ -211,4 +219,24 @@ public class VersionMigTo100 implements IVersionMigrator {
|
||||
|
||||
target.renderingLayer = vo.renderingLayer;
|
||||
}
|
||||
|
||||
private String migrateCustomVariableFormat(String jsonSource) {
|
||||
//Migrate old custom variable format
|
||||
Matcher matcher = customVarsPattern.matcher(jsonSource);
|
||||
while (matcher.find()) {
|
||||
String fullMatch = matcher.group(0);
|
||||
String varString = matcher.group(1);
|
||||
ObjectMap<String, String> newVars = new ObjectMap<>();
|
||||
String[] vars = varString.split(";");
|
||||
for (String var : vars) {
|
||||
String[] tmp = var.split(":");
|
||||
if (tmp.length > 1) {
|
||||
newVars.put(tmp[0], tmp[1]);
|
||||
}
|
||||
}
|
||||
String newVarsString = "\"customVariables\":" + json.toJson(newVars);
|
||||
jsonSource = jsonSource.replaceAll(fullMatch, newVarsString);
|
||||
}
|
||||
return jsonSource;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ package games.rednblack.editor.view.ui.panel;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.kotcrab.vis.ui.VisUI;
|
||||
import com.kotcrab.vis.ui.widget.*;
|
||||
import games.rednblack.editor.HyperLap2DFacade;
|
||||
import games.rednblack.editor.renderer.utils.CustomVariables;
|
||||
import games.rednblack.h2d.common.UIDraggablePanel;
|
||||
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
|
||||
|
||||
@@ -87,7 +87,7 @@ public class CustomVariablesPanel extends UIDraggablePanel {
|
||||
invalidateHeight();
|
||||
}
|
||||
|
||||
public void updateView(CustomVariables vars) {
|
||||
public void updateView(ObjectMap<String, String> vars) {
|
||||
variablesList.clear();
|
||||
createAddVariableTable();
|
||||
|
||||
@@ -96,9 +96,9 @@ public class CustomVariablesPanel extends UIDraggablePanel {
|
||||
variablesList.row();
|
||||
variablesList.addSeparator().colspan(3).expandX().fillX().row();
|
||||
|
||||
for (Map.Entry<String, String> entry : vars.getHashMap().entrySet()) {
|
||||
final String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
for (ObjectMap.Entry<String, String> entry : vars) {
|
||||
String key = entry.key;
|
||||
String value = entry.value;
|
||||
|
||||
VisTable keyTbl = new VisTable();
|
||||
keyTbl.setBackground(VisUI.getSkin().getDrawable("layer-bg"));
|
||||
|
||||
Reference in New Issue
Block a user