forked from BitcoderCZ/ProjectEarth_Data_Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
106 lines (86 loc) · 3.15 KB
/
Player.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using static ProjectEarth_Data_Editor.Util;
namespace ProjectEarth_Data_Editor
{
public class Player
{
public string Path;
public string Id;
public BuildPlate buildPlate;
public Player(string _path)
{
if (_path[_path.Length - 1] != '\\' && _path[_path.Length - 1] != '/')
Path = _path + '\\';
else
Path = _path;
string __path = Path.Substring(0, Path.Length - 1);
Id = __path.Substring(__path.LastIndexOf('\\') + 1);
Load();
}
public static Player CreateAsk(string apiDir)
{
string playersPath = apiDir + "data\\players\\";
if (File.Exists(playersPath + ".gitkeep"))
File.Delete(playersPath + ".gitkeep");
string[] _players = Directory.GetDirectories(playersPath);
Player[] players = _players.For(playerPath => new Player(playerPath));
string[] ids = players.For(p => p.Id);
ids = ids.Add("Cancel");
int selected = 0;
ShowMenu("Select player:", ids, ref selected);
if (selected == ids.Length - 1)
return null;
else
return players[selected];
}
public void AddBuildPlates(string[] buildPlates)
{
Load();
for (int i = 0; i < buildPlates.Length; i++) {
if (buildPlate.LockedBuildplates.Contains(buildPlates[i]))
buildPlate.LockedBuildplates.Remove(buildPlates[i]);
if (!buildPlate.UnlockedBuildplates.Contains(buildPlates[i]))
buildPlate.UnlockedBuildplates.Add(buildPlates[i]);
}
Save();
}
public void RemoveBuildPlates(string[] buildPlates, bool lockPlates = false)
{
Load();
for (int i = 0; i < buildPlates.Length; i++) {
if (buildPlate.UnlockedBuildplates.Contains(buildPlates[i]))
buildPlate.UnlockedBuildplates.Remove(buildPlates[i]);
if (lockPlates && !buildPlate.LockedBuildplates.Contains(buildPlates[i]))
buildPlate.LockedBuildplates.Add(buildPlates[i]);
}
Save();
}
public void Load()
{
if (!File.Exists(Path + "buildplates.json"))
SaveJson(Path + "buildplates.json", new BuildPlate());
buildPlate = LoadJson<BuildPlate>(Path + "buildplates.json");
}
public void Save()
{
SaveJson(Path + "buildplates.json", buildPlate);
}
[Serializable]
public class BuildPlate
{
public List<string> UnlockedBuildplates { get; set; }
public List<string> LockedBuildplates { get; set; }
public BuildPlate()
{
UnlockedBuildplates = new List<string>();
LockedBuildplates = new List<string>();
}
}
}
}