forked from BitcoderCZ/BuildPlate_Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildPlate.cs
82 lines (71 loc) · 2.35 KB
/
BuildPlate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using BuildPlate_Editor.Maths;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BuildPlate_Editor
{
[Serializable]
public class BuildPlate
{
public List<Entity> entities;
public int format_version;
public List<SubChunk> sub_chunks;
public class SubChunk
{
public List<PaletteBlock> block_palette;
public List<int> blocks;
public PositionInt position;
}
public class PaletteBlock
{
public int data;
public string name;
}
public class Entity
{
public int changeColor;
public int multiplicitiveTintChangeColor;
public string name;
public PositionDouble position;
public PositionDouble rotation;
public PositionDouble shadowPosition;
public double shadowSize;
}
public class PositionDouble
{
public double x;
public double y;
public double z;
}
public class PositionInt
{
public int x;
public int y;
public int z;
public PositionInt(int _x, int _y, int _z)
{
x = _x;
y = _y;
z = _z;
}
public static implicit operator Vector3i(PositionInt p) => new Vector3i(p.x, p.y, p.z);
public static implicit operator PositionInt(Vector3i p) => new PositionInt(p.X, p.Y, p.Z);
public override string ToString() => $"X: {x}, Y: {y}, Z: {z}";
}
public static BuildPlate Load(string path)
{
JsonBuildPlate jsonBuildPlate = Util.JsonDeserialize<JsonBuildPlate>(File.ReadAllText(path));
string model = Util.Base64Decode(jsonBuildPlate.model);
return Util.JsonDeserialize<BuildPlate>(model);
}
public static void Save(BuildPlate bp, string path, string originalPath)
{
JsonBuildPlate jsonBuildPlate = Util.JsonDeserialize<JsonBuildPlate>(File.ReadAllText(originalPath));
jsonBuildPlate.model = Util.Base64Encode(Util.JsonSerialize(bp));
File.WriteAllText(path, Util.JsonSerialize(jsonBuildPlate));
}
}
}