forked from Stridemann/PoeHUD_FullRareSetManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StashData.cs
98 lines (87 loc) · 2.71 KB
/
StashData.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
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace FullRareSetManager
{
public class StashData
{
private const string STASH_DATA_FILE = "StashData.json";
public StashTabData PlayerInventory = new StashTabData();
public Dictionary<string, StashTabData> StashTabs = new Dictionary<string, StashTabData>();
public static StashData Load(FullRareSetManagerCore plugin)
{
StashData result;
var dataFileFullPath = plugin.DirectoryFullName + "\\" + STASH_DATA_FILE;
if (File.Exists(dataFileFullPath))
{
var json = File.ReadAllText(dataFileFullPath);
try
{
result = JsonConvert.DeserializeObject<StashData>(json);
}
catch (Exception e)
{
return null;
}
}
else
{
result = new StashData();
Save(plugin, result);
}
return result;
}
public static void Save(FullRareSetManagerCore plugin, StashData data)
{
try
{
if (data == null) return;
var dataFileFullPath = plugin.DirectoryFullName + "\\" + STASH_DATA_FILE;
var settingsDirName = Path.GetDirectoryName(dataFileFullPath);
if (!Directory.Exists(settingsDirName))
Directory.CreateDirectory(settingsDirName);
using (var stream = new StreamWriter(File.Create(dataFileFullPath)))
{
var json = JsonConvert.SerializeObject(data, Formatting.Indented);
stream.Write(json);
}
}
catch
{
//PoeHUD.Plugins.BasePlugin.LogError($"Plugin {plugin.PluginName} error save settings!", 3);
}
}
}
public class StashTabData
{
public int ItemsCount;
public List<StashItem> StashTabItems = new List<StashItem>();
}
public class StashItem
{
public bool BIdentified;
public int InventPosX;
public int InventPosY;
public string ItemClass;
public string ItemName;
public StashItemType ItemType;
public bool LowLvl;
public string StashName;
public bool BInPlayerInventory { get; set; }
}
public enum StashItemType
{
Undefined = -1,
Weapon = 0,
Helmet = 1,
Body = 2,
Gloves = 3,
Boots = 4,
Belt = 5,
Amulet = 6,
Ring = 7,
TwoHanded = 8,
OneHanded = 9
}
}