import
flatbuffers
import
MX.Data.Excel.ScenarioScriptExcel as ScenarioScriptExcel
import
json
import
sqlite3
conn
=
sqlite3.connect(
'../ExcelDB.db'
)
cursor
=
conn.cursor()
d
=
cursor.execute(
"select * from ScenarioScriptDBSchema"
)
l
=
list
(d)
datas
=
[]
def
read_bin_file(file_path):
with
open
(file_path,
'rb'
) as f:
return
f.read()
def
parse_scenario_script(
buffer
):
buf
=
bytearray(
buffer
)
fb
=
flatbuffers.Builder(
0
)
fb.Bytes
=
buf
scenario
=
ScenarioScriptExcel.ScenarioScriptExcel.GetRootAsScenarioScriptExcel(buf,
0
)
return
scenario
def
process(
buffer
):
global
datas
scenario
=
parse_scenario_script(
buffer
)
datas.append({
"GroupId"
: scenario.GroupId(),
"SelectionGroup"
: scenario.SelectionGroup(),
"BGMId"
: scenario.Bgmid(),
"Transition"
: scenario.Transition(),
"BGName"
: scenario.Bgname(),
"BGEffect"
: scenario.Bgeffect(),
"ScriptKr"
: scenario.ScriptKr().decode(
'utf-8'
),
"TextJp"
: scenario.TextJp().decode(
'utf-8'
),
"TextTh"
: scenario.TextTh().decode(
'utf-8'
),
"TextTw"
: scenario.TextTw().decode(
'utf-8'
),
"TextEn"
: scenario.TextEn().decode(
'utf-8'
),
"VoiceId"
: scenario.VoiceId(),
"TeenMode"
: scenario.TeenMode()
})
for
i
in
l:
process(i[
1
])
with
open
(
"scenario_script.json"
,
"w"
, encoding
=
"utf-8"
) as f:
json.dump(datas, f, ensure_ascii
=
False
, indent
=
4
)