-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport.bas
225 lines (184 loc) · 7.12 KB
/
export.bas
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
Attribute VB_Name = "export"
Sub indicate_export_progress(file As String)
set_status "Saving... " & file
End Sub
Sub export_simple(file As String)
indicate_export_progress file
Dim root_name As String
Dim elem_name As String
If file = "strings.xml" Then
root_name = "strings"
elem_name = "string"
ElseIf file = "numbers.xml" Then
root_name = "numbers"
elem_name = "number"
ElseIf file = "roomnames.xml" Then
root_name = "roomnames"
elem_name = "roomname"
ElseIf file = "roomnames_special.xml" Then
root_name = "roomnames_special"
elem_name = "roomname"
Else
MsgBox "Can't export " & file & ", name not recognized!", vbExclamation
Exit Sub
End If
Dim XDoc As Object, root As Object, elem As Object
Set XDoc = CreateObject("MSXML2.DOMDocument")
Set root = XDoc.createElement(root_name)
XDoc.appendChild root
Dim attr As Object
If file = "strings.xml" And Worksheets("Controls").Range("B18").value <> "" Then
Set attr = XDoc.createAttribute("max_local_for")
attr.NodeValue = Worksheets("Controls").Range("B18").value
root.setAttributeNode attr
End If
Dim tbl As ListObject
On Error Resume Next
Set tbl = Worksheets(file).ListObjects("nice_table")
On Error GoTo 0
If tbl Is Nothing Then
MsgBox "No table for " & file, vbExclamation
Exit Sub
End If
Dim row As ListRow
For Each row In tbl.ListRows
If file = "roomnames_special.xml" And ListRow_get(row, "english") = "" Then
Set elem = XDoc.createComment(" - ")
root.appendChild elem
Else
Set elem = XDoc.createElement(elem_name)
root.appendChild elem
For Each col In row.Parent.ListColumns
key = col.name
value = ListRow_get(row, col.name)
If (file = "strings.xml" And (key = "case" Or key = "max" Or key = "max_local") And value = "") _
Or (file = "numbers.xml" And (key = "english" Or key = "translation" Or key = "translation2") And ListRow_get(row, "english") = "") Then
' Don't include this attribute
Else
Set attr = XDoc.createAttribute(key)
attr.NodeValue = value
elem.setAttributeNode attr
End If
Next
End If
Next row
' Save the XML file
Dim filename As String
filename = get_cell_path() & "\" & file
XDoc.Save (filename)
sanitize_xml file, filename
End Sub
Sub export_strings_plural()
Dim file As String
file = "strings_plural.xml"
indicate_export_progress file
Dim XDoc As Object, root As Object, elem As Object, subElem As Object
Set XDoc = CreateObject("MSXML2.DOMDocument")
Set root = XDoc.createElement("strings_plural")
XDoc.appendChild root
Dim attr As Object
If Worksheets("Controls").Range("B18").value <> "" Then
Set attr = XDoc.createAttribute("max_local_for")
attr.NodeValue = Worksheets("Controls").Range("B18").value
root.setAttributeNode attr
End If
Dim tbl As ListObject
On Error Resume Next
Set tbl = Worksheets(file).ListObjects("nice_table")
On Error GoTo 0
If tbl Is Nothing Then
MsgBox "No table for " & file, vbExclamation
Exit Sub
End If
Dim row As ListRow
For Each row In tbl.ListRows
Set elem = XDoc.createElement("string")
root.appendChild elem
For Each col In Array("english_plural", "english_singular", "explanation", "max", "var", "expect", "max_local")
Dim key As String
key = col
value = ListRow_get(row, key)
If Not ((key = "max" Or key = "var" Or key = "expect" Or key = "max_local") And value = "") Then
Set attr = XDoc.createAttribute(key)
attr.NodeValue = value
elem.setAttributeNode attr
End If
Next
' Now find each plural form column
For Each col In row.Parent.ListColumns
If col.name Like "form *" Then
parts = Split(col.name, " ", 3)
Set subElem = XDoc.createElement("translation")
elem.appendChild subElem
Set attr = XDoc.createAttribute("form")
attr.NodeValue = parts(1)
subElem.setAttributeNode attr
Set attr = XDoc.createAttribute("translation")
attr.NodeValue = ListRow_get(row, col.name)
subElem.setAttributeNode attr
End If
Next
Next row
' Save the XML file
Dim filename As String
filename = get_cell_path() & "\" & file
XDoc.Save (filename)
sanitize_xml file, filename
End Sub
Sub export_cutscenes()
Dim file As String
file = "cutscenes.xml"
indicate_export_progress file
Dim XDoc As Object, root As Object, elem As Object, subElem As Object
Set XDoc = CreateObject("MSXML2.DOMDocument")
Set root = XDoc.createElement("cutscenes")
XDoc.appendChild root
Dim attr As Object
last_sid = "none yet"
Dim tbl As ListObject
On Error Resume Next
Set tbl = Worksheets(file).ListObjects("nice_table")
On Error GoTo 0
If tbl Is Nothing Then
MsgBox "No table for " & file, vbExclamation
Exit Sub
End If
Dim row As ListRow
For Each row In tbl.ListRows
sid = ListRow_get(row, "id")
If sid <> last_sid Then
' New cutscene
Set elem = XDoc.createElement("cutscene")
root.appendChild elem
Set attr = XDoc.createAttribute("id")
attr.NodeValue = sid
elem.setAttributeNode attr
Set attr = XDoc.createAttribute("explanation")
attr.NodeValue = ListRow_get(row, "explanation")
elem.setAttributeNode attr
last_sid = sid
End If
Set subElem = XDoc.createElement("dialogue")
elem.appendChild subElem
For Each col In Array( _
"speaker", "english", "translation", _
"case", "tt", "wraplimit", "centertext", _
"pad", "pad_left", "pad_right", "padtowidth", _
"buttons" _
)
Dim key As String
key = col
value = ListRow_get(row, key)
If key = "translation" Or value <> "" Then
Set attr = XDoc.createAttribute(key)
attr.NodeValue = value
subElem.setAttributeNode attr
End If
Next
Next row
' Save the XML file
Dim filename As String
filename = get_cell_path() & "\" & file
XDoc.Save (filename)
sanitize_xml file, filename
End Sub