forked from fattard/FlagsEditorEXPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlagsGen8BDSP.cs
152 lines (127 loc) · 5.14 KB
/
FlagsGen8BDSP.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
namespace FlagsEditorEXPlugin
{
internal class FlagsGen8BDSP : FlagsOrganizer
{
static string? s_flagsList_res = null;
BattleTrainerStatus8b? m_battleTrainerStatus;
FlagWork8b? m_flagWork;
const int Src_EventFlags = 0;
const int Src_SysFlags = 1;
const int Src_TrainerFlags = 2;
bool[] GetEventFlags(FlagWork8b source)
{
var result = new bool[source.CountFlag];
for (int i = 0; i < result.Length; i++)
{
result[i] = source.GetFlag(i);
}
return result;
}
protected override void InitFlagsData(SaveFile savFile, string? resData)
{
m_savFile = savFile;
m_battleTrainerStatus = ((SAV8BS)m_savFile).BattleTrainer;
m_flagWork = ((SAV8BS)m_savFile).FlagWork;
#if DEBUG
// Force refresh
s_flagsList_res = null;
#endif
s_flagsList_res = resData ?? s_flagsList_res ?? ReadFlagsResFile("flags_gen8bdsp");
int idxEventFlagsSection = s_flagsList_res.IndexOf("//\tEvent Flags");
int idxSysFlagsSection = s_flagsList_res.IndexOf("//\tSys Flags");
int idxTrainerFlagsSection = s_flagsList_res.IndexOf("//\tTrainer Flags");
int idxEventWorkSection = s_flagsList_res.IndexOf("//\tEvent Work");
var sysFlagsVals = new bool[m_flagWork.CountSystem];
for (int i = 0; i < sysFlagsVals.Length; i++)
{
sysFlagsVals[i] = m_flagWork.GetSystemFlag(i);
}
var battleTrainerVals = new bool[707];
for (int i = 0; i < battleTrainerVals.Length; i++)
{
battleTrainerVals[i] = m_battleTrainerStatus.GetIsWin(i);
}
bool[] eventFlags = GetEventFlags(m_flagWork);
AssembleList(s_flagsList_res[idxEventFlagsSection..], Src_EventFlags, "Event Flags", eventFlags);
AssembleList(s_flagsList_res[idxSysFlagsSection..], Src_SysFlags, "Sys Flags", sysFlagsVals);
AssembleList(s_flagsList_res[idxTrainerFlagsSection..], Src_TrainerFlags, "Trainer Flags", battleTrainerVals);
AssembleWorkList(s_flagsList_res[idxEventWorkSection..], ((IEventWorkArray<int>)m_savFile).GetAllEventWork());
}
public override bool SupportsBulkEditingFlags(EventFlagType flagType) => flagType switch
{
#if DEBUG
EventFlagType.FieldItem or
EventFlagType.HiddenItem or
EventFlagType.TrainerBattle
=> true,
#endif
_ => false
};
public override void BulkMarkFlags(EventFlagType flagType)
{
ChangeFlagsVal(flagType, value: true);
}
public override void BulkUnmarkFlags(EventFlagType flagType)
{
ChangeFlagsVal(flagType, value: false);
}
void ChangeFlagsVal(EventFlagType flagType, bool value)
{
if (SupportsBulkEditingFlags(flagType))
{
foreach (var f in m_flagsGroupsList[0].Flags)
{
if (f.FlagTypeVal == flagType)
{
int idx = (int)f.FlagIdx;
f.IsSet = value;
switch (f.SourceIdx)
{
case Src_EventFlags:
m_flagWork!.SetFlag(idx, value);
break;
case Src_SysFlags:
m_flagWork!.SetSystemFlag(idx, value);
break;
case Src_TrainerFlags:
m_battleTrainerStatus!.SetIsWin(idx, value);
break;
}
}
}
}
}
public override void SyncEditedFlags(FlagsGroup fGroup)
{
switch (fGroup.SourceIdx)
{
case Src_EventFlags:
foreach (var f in fGroup.Flags)
{
m_flagWork!.SetFlag((int)f.FlagIdx, f.IsSet);
}
break;
case Src_SysFlags:
foreach (var f in fGroup.Flags)
{
m_flagWork!.SetSystemFlag((int)f.FlagIdx, f.IsSet);
}
break;
case Src_TrainerFlags:
foreach (var f in fGroup.Flags)
{
m_battleTrainerStatus!.SetIsWin((int)f.FlagIdx, f.IsSet);
}
break;
}
}
public override void SyncEditedEventWork()
{
var eventWorkHelper = (IEventWorkArray<int>)m_savFile!;
foreach (var w in m_eventWorkList)
{
eventWorkHelper.SetWork((int)w.WorkIdx, (int)w.Value);
}
}
}
}