-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplitsfile.go
More file actions
231 lines (220 loc) · 6.34 KB
/
splitsfile.go
File metadata and controls
231 lines (220 loc) · 6.34 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//go:build windows
package main
import (
"encoding/xml"
"os"
"path/filepath"
"regexp"
"strings"
"github.com/CuteReimu/sssplitmaker/translate"
"github.com/lxn/walk"
"github.com/lxn/win"
)
var fileRunData = &xmlRun{}
func onClickLoadSplitFile() {
dlg := new(walk.FileDialog)
dlg.Title = "打开Splits文件"
dlg.Filter = "Splits文件(*.lss)|*.lss"
dlg.Flags = win.OFN_FILEMUSTEXIST
if ok, err := dlg.ShowOpen(mainWindow); err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
} else if ok {
file := dlg.FilePath
if filepath.Ext(file) != ".lss" {
return
}
buf, err := os.ReadFile(file)
if err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
return
}
loadSplitFile(buf)
}
}
func loadSplitFile(buf []byte) {
run := &xmlRun{}
err := xml.Unmarshal(buf, run)
if err != nil {
walk.MsgBox(mainWindow, "解析文件失败", err.Error(), walk.MsgBoxIconError)
return
}
if len(run.Segments) >= 50 {
result := walk.MsgBox(mainWindow, "确认操作", "此lss文件的分段非常多,可能需要加载一段时间,是否继续?", walk.MsgBoxYesNo|walk.MsgBoxIconQuestion)
if result != walk.DlgCmdYes {
return
}
}
resetLines(len(run.Segments))
for i, segment := range run.Segments {
err = lines[i].name.SetText(segment.Name)
if err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
return
}
lines[i].xmlSegmentOther = segment.Other
}
for _, setting := range run.AutoSplitterSettings.CustomSettings {
if setting.Id == "splits" {
if setting.Type != "list" {
walk.MsgBox(mainWindow, "解析Settings失败", "splits字段类型错误", walk.MsgBoxIconError)
return
} else {
resetLines(max(len(lines), len(setting.Setting)-1))
for i, s := range setting.Setting {
if s.Type != "string" {
walk.MsgBox(mainWindow, "解析Settings失败", "splits子字段类型错误", walk.MsgBoxIconError)
return
} else {
index := translate.GetIndexByID(s.Value)
if index < 0 {
walk.MsgBox(mainWindow, "解析Settings失败", "无法识别的分割点ID:"+s.Value, walk.MsgBoxIconError)
return
}
if i == 0 {
err = startTriggerComboBox.SetCurrentIndex(index)
} else {
err = lines[i-1].splitId.SetCurrentIndex(index)
}
if err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
return
}
}
}
}
break
}
}
fileRunData = run
}
var currentSplitmakerFileName string
func loadLayoutFileFromSplitmaker(fileName string) {
if currentSplitmakerFileName == fileName {
return
}
currentSplitmakerFileName = fileName
categoryName, splitIds, err := GetSplitIds(fileName)
if err != nil {
walk.MsgBox(mainWindow, "获取splitmaker失败", err.Error(), walk.MsgBoxIconError)
return
}
if len(splitIds) >= 50 {
result := walk.MsgBox(mainWindow, "确认操作", "此模板的分段非常多,可能需要加载一段时间,是否继续?", walk.MsgBoxYesNo|walk.MsgBoxIconQuestion)
if result != walk.DlgCmdYes {
return
}
}
resetLines(len(splitIds) - 1)
for i, id := range splitIds {
isSubSplit := strings.HasPrefix(id, "-")
id = strings.TrimLeft(id, "-")
id = regexp.MustCompile(`\{.*?}`).ReplaceAllString(id, "")
index := translate.GetIndexByID(id)
if index < 0 {
walk.MsgBox(mainWindow, "解析Settings失败", "无法识别的分割点ID:"+id, walk.MsgBoxIconError)
return
}
if i == 0 {
err = startTriggerComboBox.SetCurrentIndex(index)
if err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
return
}
} else {
name := translate.GetSplitDescriptionByID(id)
splitIndex := strings.LastIndex(name, "(")
if splitIndex > 0 {
name = name[:splitIndex]
}
if isSubSplit {
name = "-" + name
}
err = lines[i-1].name.SetText(name)
if err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
return
}
err = lines[i-1].splitId.SetCurrentIndex(index)
if err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
return
}
}
}
fileRunData = &xmlRun{CategoryName: categoryName}
}
func onSaveSplitsFile() {
if !includeTimeRecordsCheckBox.Checked() {
fileRunData.Other = nil
}
if fileRunData.Version == "" {
fileRunData.Version = "1.7.0"
}
if fileRunData.AutoSplitterSettings.Version == "" {
fileRunData.AutoSplitterSettings.Version = "1.0"
}
if fileRunData.GameName == "" {
fileRunData.GameName = "Hollow Knight: Silksong"
}
fileRunData.Offset = "00:00:00"
splits := &xmlWasmSetting{
Id: "splits",
Type: "list",
Setting: []*xmlWasmSetting{{
Type: "string",
Value: translate.GetIDByDescription(startTriggerComboBox.Text()),
}},
}
if splits.Setting[0].Value == "Act1Start" {
fileRunData.Offset = "00:00:21.7600000"
}
fileRunData.AutoSplitterSettings.CustomSettings = []*xmlWasmSetting{{
Id: "script_name",
Type: "string",
Value: "silksong_autosplit_wasm",
}, splits}
fileRunData.Segments = nil
for _, line := range lines {
splitId := translate.GetIDByDescription(line.splitId.Text())
splits.Setting = append(splits.Setting, &xmlWasmSetting{
Type: "string",
Value: splitId,
})
icon := line.icon
if icon == "" {
icon = getIcon(splitId)
}
var other []*xmlElement
if includeTimeRecordsCheckBox.Checked() {
other = line.xmlSegmentOther
}
fileRunData.Segments = append(fileRunData.Segments, &xmlSegment{
Name: line.name.Text(),
Other: other,
Icon: xmlIcon{icon},
})
}
buf, err := xml.MarshalIndent(fileRunData, "", " ")
if err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
return
}
buf = append([]byte(`<?xml version="1.0" encoding="UTF-8"?>`+"\n"), buf...)
dlg := new(walk.FileDialog)
dlg.Title = "保存分段文件"
dlg.Filter = "分段文件(*.lss)|*.lss"
dlg.Flags = win.OFN_OVERWRITEPROMPT | win.OFN_NOREADONLYRETURN
if ok, err := dlg.ShowSave(mainWindow); err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
} else if ok {
file := dlg.FilePath
if filepath.Ext(file) != ".lss" {
file += ".lss"
}
err = os.WriteFile(file, buf, 0644)
if err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
return
}
}
}