Skip to content

Commit

Permalink
Switch to using uint for TIled IDs and throw an error if a tileID can…
Browse files Browse the repository at this point in the history
…'t be resolved.
  • Loading branch information
QuillInkwell committed Jan 28, 2025
1 parent c350118 commit 843e316
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion TMJ To Mapgen/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace TMJ_To_Mapgen
{
class Layer
{
public int[] data;
public uint[] data;
public int height;
public int id;
public bool locked;
Expand Down
21 changes: 12 additions & 9 deletions TMJ To Mapgen/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class MainWindow : Window
public static string SYMBOLS = "!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~€ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèé";
public static int CDDA_OVERMAP_TILE_WIDTH = 24;

private Dictionary<int, string> CDDAConversionKey;
private Dictionary<uint, string> CDDAConversionKey;

private ManualPaletteDesigner paletteDesigner;

Expand Down Expand Up @@ -144,7 +144,7 @@ private List<TerrainFurnitureCombo> GetAllCombosFromMap(Map map)

for (int ii = 0; ii < map.layers[i].data.Length; ii++)
{
int[] combo = GetTerrainAndFurnitureFromMapPoint(i, ii, map);
uint[] combo = GetTerrainAndFurnitureFromMapPoint(i, ii, map);

TerrainFurnitureCombo point = new TerrainFurnitureCombo(combo[0], combo[1]);
newLayer.mapPoints.Add(point);
Expand All @@ -160,10 +160,10 @@ private List<TerrainFurnitureCombo> GetAllCombosFromMap(Map map)
return uniqueCombos;
}

private int[] GetTerrainAndFurnitureFromMapPoint(int i, int ii, Map map)
private uint[] GetTerrainAndFurnitureFromMapPoint(int i, int ii, Map map)
{
//Loop through all points in layer
int terrainID = 0;
uint terrainID = 0;
if (map.layers[i + 1].data[ii] != 0)
{
// If Terrain has a value use that
Expand All @@ -175,9 +175,9 @@ private int[] GetTerrainAndFurnitureFromMapPoint(int i, int ii, Map map)
terrainID = map.layers[i].data[ii];
}
// Set Furniture to whatever is in the array, even if that's a 0 as in nothing
int furnitureID = map.layers[i + 2].data[ii];
uint furnitureID = map.layers[i + 2].data[ii];

int[] combo = new int[2];
uint[] combo = new uint[2];
combo[0] = terrainID;
combo[1] = furnitureID;

Expand All @@ -197,7 +197,7 @@ private bool IsUniqueCombo(List<TerrainFurnitureCombo> combos, TerrainFurnitureC

private void CreateConversionKey(Map map)
{
CDDAConversionKey = new Dictionary<int, string>();
CDDAConversionKey = new Dictionary<uint, string>();
CDDAConversionKey.Add(0, "t_open_air");

foreach (Tileset tileset in map.tilesets)
Expand All @@ -217,17 +217,20 @@ private void CreateConversionKey(Map map)

private void AssignCDDAIds(List<TerrainFurnitureCombo> combos)
{
bool found = false;
foreach (TerrainFurnitureCombo combo in combos)
{
if (combo.furnitureID != 0)
{
string furniture = "";
CDDAConversionKey.TryGetValue(combo.furnitureID, out furniture);
found = CDDAConversionKey.TryGetValue(combo.furnitureID, out furniture);
if (!found) throw new Exception("Error: Furniture Tile ID has no defined CDDA ID. Do you have tiles without ID properties or are any of your tiles rotated?");
combo.CDDAFurnitureID = furniture;
}

string terrain = "";
CDDAConversionKey.TryGetValue(combo.terrainID, out terrain);
found = CDDAConversionKey.TryGetValue(combo.terrainID, out terrain);
if (!found) throw new Exception("Error: Tile ID has no defined CDDA ID. Do you have tiles without ID properties or are any of your tiles rotated?");
combo.CDDATerrainID = terrain;
}
}
Expand Down
6 changes: 3 additions & 3 deletions TMJ To Mapgen/TerrainFurnitureCombo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace TMJ_To_Mapgen
{
public class TerrainFurnitureCombo
{
public int terrainID = 0;
public int furnitureID= 0;
public uint terrainID = 0;
public uint furnitureID= 0;

public string CDDATerrainID = "";
public string CDDAFurnitureID = "";

public char mapSymbol = 'a';

public TerrainFurnitureCombo(int terrainID, int furnitureID)
public TerrainFurnitureCombo(uint terrainID, uint furnitureID)
{
this.terrainID = terrainID;
this.furnitureID = furnitureID;
Expand Down
4 changes: 2 additions & 2 deletions TMJ To Mapgen/Tileset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class TileProperty

class Tile
{
public int id;
public uint id;
public TileProperty[] properties;
}

class Tileset
{
public Tile[] tiles;
public int firstgid;
public uint firstgid;
}
}

0 comments on commit 843e316

Please sign in to comment.