Skip to content

Commit

Permalink
Refactoring classes' privileges
Browse files Browse the repository at this point in the history
  • Loading branch information
iconstudio committed Oct 6, 2023
1 parent 44dc56a commit 122d32e
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
8 changes: 4 additions & 4 deletions Editor/TestEditor/Contents/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace TestEditor.Contents
{
[Serializable]
internal class Map : IMapEntity<SerializedMap>
public class Map : IMapEntity<SerializedMap>
{
internal Tileset myTileset;
internal Rectangle myResolution;
public static Map EmptyMap { get; }
private Tileset myTileset;
private Rectangle myResolution;

public static Map EmptyMap { get; }
public Tileset Tileset
{
get => myTileset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace TestEditor.Contents
{
[Serializable]
internal struct SerializedMap : IMapAsyncSerial<Map>
public struct SerializedMap : IMapAsyncSerial<Map>
{
[JsonInclude] public SerializedTileset Tileset { get; set; }
[JsonInclude] public string Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace TestEditor.Contents
{
[Serializable]
internal readonly struct SerializedTileImage
public readonly struct SerializedTileImage
: IEquatable<SerializedTileImage>, IMapSerial<TileImage?>
{
[JsonInclude]
Expand Down
29 changes: 14 additions & 15 deletions Editor/TestEditor/Contents/Serialized Objects/SerializedTileset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,32 @@
namespace TestEditor.Contents
{
[Serializable]
internal readonly struct SerializedTileset : IMapAsyncSerial<Tileset>
public readonly struct SerializedTileset : IMapAsyncSerial<Tileset>
{
[JsonInclude]
public readonly string tilesetName;
public readonly string Name { get; }
[JsonInclude]
public readonly IReadOnlyList<SerializedTileImage> tileData;
public readonly IReadOnlyList<SerializedTileImage> ImageData { get; }
[JsonInclude]
public readonly int tileWidth;
public readonly int TileWidth { get; }
[JsonInclude]
public readonly int tileHeight;

public bool IsDeserializable => false;
public readonly int TileHeight { get; }
public readonly bool IsDeserializable => false;

[JsonConstructor]
public SerializedTileset(string name, in IEnumerable<SerializedTileImage> data, int w, int h)
{
tilesetName = name;
tileData = data.ToImmutableArray();
tileWidth = w;
tileHeight = h;
Name = name;
ImageData = data.ToImmutableArray();
TileWidth = w;
TileHeight = h;
}

[Pure]
public readonly async Task<Tileset> Deserialize()
{
Tileset tileset = new(tilesetName, tileWidth, tileHeight);
foreach (var serialized_tile in tileData)
Tileset tileset = new(Name, TileWidth, TileHeight);
foreach (var serialized_tile in ImageData)
{
var tile = await TileResourceManager.LoadTile(serialized_tile);
Debug.Print("TileImage Loaded: " + tile.ToString());
Expand All @@ -46,12 +45,12 @@ public readonly async Task<Tileset> Deserialize()
[Pure]
public readonly IEnumerable<SerializedTileImage> GetData()
{
return tileData;
return ImageData;
}
[Pure]
public readonly IEnumerator<SerializedTileImage> GetEnumerator()
{
return tileData.GetEnumerator();
return ImageData.GetEnumerator();
}
}
}
20 changes: 10 additions & 10 deletions Editor/TestEditor/Contents/Tile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
namespace TestEditor.Contents
{
[Serializable]
internal struct Tile
public struct Tile
{
[JsonInclude] public int id;
[JsonInclude] public int x;
[JsonInclude] public int y;
[JsonInclude] public int Id { get; set; }
[JsonInclude] public int X { get; set; }
[JsonInclude] public int Y { get; set; }

public Tile() : this(0, 0, 0)
{ }
[JsonConstructor]
public Tile(int tid, int tx, int ty)
{
id = tid;
x = tx;
y = ty;
Id = tid;
X = tx;
Y = ty;
}

[Pure]
public static Tile Create(int tid, int tx, int ty)
{
return new Tile()
{
id = tid,
x = tx,
y = ty
Id = tid,
X = tx,
Y = ty
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion Editor/TestEditor/Contents/TileImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace TestEditor.Contents
{
[Serializable]
internal readonly struct TileImage
public readonly struct TileImage
: IMapEntity<SerializedTileImage, int>, IEquatable<TileImage>
{
public readonly string ImageFile { get; }
Expand Down
4 changes: 2 additions & 2 deletions Editor/TestEditor/Contents/Tileset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
namespace TestEditor.Contents
{
[Serializable]
internal class Tileset : IMapEntity<SerializedTileset>
public class Tileset : IMapEntity<SerializedTileset>
{
public string Name { [Pure] get; }
private Dictionary<int, TileImage> TileMap { [Pure] get; }
public Dictionary<int, TileImage> TileMap { [Pure] get; }
public int TileWidth { [Pure] get; }
public int TileHeight { [Pure] get; }
public bool IsDeserializable => false;
Expand Down
3 changes: 3 additions & 0 deletions Editor/TestEditor/Infrastructures/EditorCanvas.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Microsoft.Graphics.Canvas.UI;
using Microsoft.Graphics.Canvas.UI.Xaml;

using TestEditor.Contents;

using Windows.Foundation;

namespace TestEditor
{
public sealed partial class EditorCanvas : UserControl
{
public Map CurrentMap { get; set; }
public event TypedEventHandler<CanvasControl, CanvasDrawEventArgs> Draw
{
add => Canvas.Draw += value;
Expand Down

0 comments on commit 122d32e

Please sign in to comment.