Skip to content

Commit

Permalink
updated all samples, now supports automatically changing the line to …
Browse files Browse the repository at this point in the history
…have the tileset-generate command
  • Loading branch information
Cammin committed Aug 14, 2023
1 parent a70febb commit 372871a
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Assets/LDtkUnity/Samples~/Samples/AutoLayers_1_basic.ldtk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "IntGrid layers can paint tiles automatically using simple RULE SETS.\n\n - Press [SHIFT + R] to toggle auto-layer rendering\n - Click on the RULES button on the left to see/edit rules.",
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "Manual" }],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/LDtkUnity/Samples~/Samples/AutoLayers_2_stamps.ldtk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "\"STAMPS\" are groups of multiple tiles that are generated by RULES.\n\nClick on the RULES button on the left to see them.",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -341,4 +341,4 @@
],
"worlds": [],
"dummyWorldIid": "c9259b80-c640-11ed-ad34-65fb5dfe1c19"
}
}
4 changes: 2 additions & 2 deletions Assets/LDtkUnity/Samples~/Samples/AutoLayers_3_Mosaic.ldtk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "This example demonstrates the use of rules to create complex but dynamic mosaics.",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -1646,4 +1646,4 @@
],
"worlds": [],
"dummyWorldIid": "c9361640-c640-11ed-ad34-af90bc56df47"
}
}
4 changes: 2 additions & 2 deletions Assets/LDtkUnity/Samples~/Samples/AutoLayers_4_Assistant.ldtk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "In this example, the rules are automatically created and managed by the rule \"Assistant\".\n\nTo open it, click on the \"Rules\" button on the left, then \"Edit\" on the \"Walls\" group.",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -877,4 +877,4 @@
],
"worlds": [],
"dummyWorldIid": "c9449530-c640-11ed-ad34-138bedf36840"
}
}
4 changes: 2 additions & 2 deletions Assets/LDtkUnity/Samples~/Samples/AutoLayers_5_Advanced.ldtk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "Rules can be used to render various biome elements, such as Dirt, Water or Lava.\n\nPress [SHIFT + R] to toggle auto-layers rendering",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -2792,4 +2792,4 @@
],
"worlds": [],
"dummyWorldIid": "c9533b30-c640-11ed-ad34-4b074b658372"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"backupRelPath": null,
"levelNamePattern": "level_x%gx,y%gy",
"tutorialDesc": "This sample shows how to use OPTIONAL rules to create biomes and variations easily.\n\nClick the \"RULES\" button on the left to see all the rule groups. Some groups are BLUE: they are optional which means they are disabled by default, and can be enabled only in specific levels.",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -7759,4 +7759,4 @@
],
"worlds": [],
"dummyWorldIid": "7b3c9d60-c640-11ed-9217-5d5a1e1cd04a"
}
}
4 changes: 2 additions & 2 deletions Assets/LDtkUnity/Samples~/Samples/Entities.ldtk
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "Entities can be used to represent any gameplay element, such as player, enemies, items etc.\n\nThey can have many kind of customizable properties, including arrays, enums or coordinates.",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -4563,4 +4563,4 @@
],
"worlds": [],
"dummyWorldIid": "f310fef0-7820-11ed-9859-6530dfcbabd7"
}
}
4 changes: 2 additions & 2 deletions Assets/LDtkUnity/Samples~/Samples/SeparateLevelFiles.ldtk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "In this example, the levels are stored in separate files, in a subfolder. \n\nThis is fully transparent from the editor perspective.",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -143,4 +143,4 @@
],
"worlds": [],
"dummyWorldIid": "c9a37e10-c640-11ed-ad34-4391c8dfabdd"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "This file can be used to check if an API supports LDtk file format properly. \n\nIt uses most important LDtk features.",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -3204,4 +3204,4 @@
],
"worlds": [],
"dummyWorldIid": "c9b00130-c640-11ed-ad34-57d0f1a6d3a2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "This example uses a combination of Auto-Layers with a vertical offset of -16px on the \"Wall_tops\" layer. This trick allows rendering of a \"top-down\" level with a minimal amount of tiles (and work).\n\nPress [SHIFT + A] to toggle \"Single Layer Mode\", and see what each layer really contains.\n\nPress [SHIFT + R] to toggle rendering of rules based layers.",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -4621,4 +4621,4 @@
],
"worlds": [],
"dummyWorldIid": "c9ef2d10-c640-11ed-ad34-f553e1d803f9"
}
}
4 changes: 2 additions & 2 deletions Assets/LDtkUnity/Samples~/Samples/WorldMap_Free_layout.ldtk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "In \"Free\" world layout, levels are positionned freely in the 2D space.\n\nIn this example, some are even in different world layers (ie. above and behind). Use [PAGE UP] and [PAGE DOWN] to move between world layers.",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -14945,4 +14945,4 @@
],
"worlds": [],
"dummyWorldIid": "ca0e9bf0-c640-11ed-ad34-5d947c1a0a9f"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"backupRelPath": null,
"levelNamePattern": "%world_Level_%idx",
"tutorialDesc": "In Gridvania world layouts, levels are organized on a large grid.\nPress [W] to switch to World mode.\nIn this example, some are even in different world layers (ie. above and behind). Use [PAGE UP] and [PAGE DOWN] to move between world layers.",
"customCommands": [],
"customCommands": [{ "command": "../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe", "when": "AfterSave" }],
"flags": ["UseMultilinesType"],
"defs": { "layers": [
{
Expand Down Expand Up @@ -33243,4 +33243,4 @@
],
"worlds": [],
"dummyWorldIid": "ca3d7420-c640-11ed-ad34-5f1a115c4cf3"
}
}
32 changes: 31 additions & 1 deletion Assets/Tools/SampleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,39 @@ private static void CopyFilesRecursively(string sourcePath, string targetPath)
//ignore the thumbnails
continue;
}

string dest = newPath.Replace(sourcePath, targetPath);
File.Copy(newPath, dest, true);
ModifyCommandToWork(dest);
}
}

private static void ModifyCommandToWork(string newPath)
{
if (Path.GetExtension(newPath) != ".ldtk")
{
return;
}
Debug.Log(newPath);

const string before = @"""customCommands"": [],";
const string after = @"""customCommands"": [{ ""command"": ""../../../Library/LDtkTilesetExporter/ExportTilesetDefinition.exe"", ""when"": ""AfterSave"" }],";

File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true);
string[] lines = File.ReadAllLines(newPath);
Debug.Log(lines.Length);

for (int i = 0; i < lines.Length; i++)
{
string line = lines[i];

if (line.Contains(before))
{
Debug.Log("REPLACE");
lines[i] = line.Replace(before, after);
}
}

File.WriteAllLines(newPath, lines);
}
}
}

0 comments on commit 372871a

Please sign in to comment.