! ! ドラゴンクエストライバルズ戦績記録アプリ ! Subroutines: ! dqrbattlelog-edit.html生成 fn.def CreateEditHtml() buf$ = "\n\n
\n\n\nデッキ名: \n
\n\nリーダー: \n\n
\n\n 勝 敗 率: %\n
\n\n先: 回\n\n 後: 回\n\n
\n\nテリー:
\n勝\n\n敗\n\n率: %\n
\nゼシカ:
\n勝\n\n敗\n\n率: %\n
\nアリーナ:
\n勝\n\n敗\n\n率: %\n
\nククール:
\n勝\n\n敗\n\n率: %\n
\nトルネコ:
\n勝\n\n敗\n\n率: %\n
\nミネア:
\n勝\n\n敗\n\n率: %\n
\nピサロ:
\n勝\n\n敗\n\n率: %\n
\n \n
\n\n\n\n" text.open w, f, "dqrbattlelog-edit.html" text.writeln f, buf$ text.close f fn.end ! dqrbattlelog-edit.js生成 fn.def CreateEditJs() buf$ = "/*\n* メイン機能\n */\n\n// -/+ ボタン機能\nfunction decrIncr(id, action) {\n var e = document.getElementById(id);\n var v = e.value;\n var i = parseInt(v);\n\n if (action === 'decr') {\n if (i > 0) { i -= 1; }\n e.value = i;\n }\n else {\n i += 1;\n e.value = i;\n }\n if (id === 'tops') { return; }\n if (id === 'bottoms') { return; }\n updateRate(id.slice(-2));\n updateSum();\n}\n\nfunction deleteLog() {\n doDataLink(\"delete;\" + document.getElementById('deckname').value);\n}\n\nfunction resetLog() {\n document.getElementById('deckname').value = '冒険者の書';\n document.getElementById('leader').value = 'テリー';\n document.getElementById('wins_sum').value = 0;\n document.getElementById('loses_sum').value = 0;\n document.getElementById('rate_sum').value = 0;\n document.getElementById('tops').value = 0;\n document.getElementById('bottoms').value = 0;\n document.getElementById('wins_TE').value = 0;\n document.getElementById('loses_TE').value = 0;\n document.getElementById('rate_TE').value = 0;\n document.getElementById('wins_ZE').value = 0;\n document.getElementById('loses_ZE').value = 0;\n document.getElementById('rate_ZE').value = 0;\n document.getElementById('wins_AL').value = 0;\n document.getElementById('loses_AL').value = 0;\n document.getElementById('rate_AL').value = 0;\n document.getElementById('wins_KU').value = 0;\n document.getElementById('loses_KU').value = 0;\n document.getElementById('rate_KU').value = 0;\n document.getElementById('wins_TO').value = 0;\n document.getElementById('loses_TO').value = 0;\n document.getElementById('rate_TO').value = 0;\n document.getElementById('wins_ME').value = 0;\n document.getElementById('loses_ME').value = 0;\n document.getElementById('rate_ME').value = 0;\n document.getElementById('wins_PS').value = 0;\n document.getElementById('loses_PS').value = 0;\n document.getElementById('rate_PS').value = 0;\n}\n\nfunction openLog() {\n doDataLink(\"open;\");\n}\n\nfunction saveLog() {\n data = \"save;\";\n data += \"デッキ名:\" + document.getElementById('deckname').value + \"\\n\";\n data += \"リーダー:\" + document.getElementById('leader').value + \n \":\" + document.getElementById('wins_sum').value + \n \":\" + document.getElementById('loses_sum').value + \n \":\" + document.getElementById('rate_sum').value + \"\\n\";\n data += \"先攻:\" + document.getElementById('tops').value + \"\\n\";\n data += \"後攻:\" + document.getElementById('bottoms').value + \"\\n\";\n data += \"テリー:\" + document.getElementById('wins_TE').value;\n data += \":\" + document.getElementById('loses_TE').value;\n data += \":\" + document.getElementById('rate_TE').value + \"\\n\";\n data += \"ゼシカ:\" + document.getElementById('wins_ZE').value;\n data += \":\" + document.getElementById('loses_ZE').value;\n data += \":\" + document.getElementById('rate_ZE').value + \"\\n\";\n data += \"アリーナ:\" + document.getElementById('wins_AL').value;\n data += \":\" + document.getElementById('loses_AL').value;\n data += \":\" + document.getElementById('rate_AL').value + \"\\n\";\n data += \"ククール:\" + document.getElementById('wins_KU').value;\n data += \":\" + document.getElementById('loses_KU').value;\n data += \":\" + document.getElementById('rate_KU').value + \"\\n\";\n data += \"トルネコ:\" + document.getElementById('wins_TO').value;\n data += \":\" + document.getElementById('loses_TO').value;\n data += \":\" + document.getElementById('rate_TO').value + \"\\n\";\n data += \"ミネア:\" + document.getElementById('wins_ME').value;\n data += \":\" + document.getElementById('loses_ME').value;\n data += \":\" + document.getElementById('rate_ME').value + \"\\n\";\n data += \"ピサロ:\" + document.getElementById('wins_PS').value;\n data += \":\" + document.getElementById('loses_PS').value;\n data += \":\" + document.getElementById('rate_PS').value + \"\\n\";\n doDataLink(data);\n}\n\n/*\n* サブルーチン\n */\n\n// 対戦相手別の勝率を更新\nfunction updateRate(leader) {\n document.getElementById('rate_' + leader).value = \n calcRate(\n parseInt(document.getElementById('wins_' + leader).value), \n parseInt(document.getElementById('loses_' + leader).value));\n}\n\n// 合計勝敗、合計勝率を更新\nfunction updateSum() {\n var wins_sum = parseInt(document.getElementById('wins_TE').value) + \n parseInt(document.getElementById('wins_ZE').value) + \n parseInt(document.getElementById('wins_AL').value) + \n parseInt(document.getElementById('wins_KU').value) + \n parseInt(document.getElementById('wins_TO').value) + \n parseInt(document.getElementById('wins_ME').value) + \n parseInt(document.getElementById('wins_PS').value);\n document.getElementById('wins_sum').value = wins_sum;\n\n var loses_sum = parseInt(document.getElementById('loses_TE').value) + \n parseInt(document.getElementById('loses_ZE').value) + \n parseInt(document.getElementById('loses_AL').value) + \n parseInt(document.getElementById('loses_KU').value) + \n parseInt(document.getElementById('loses_TO').value) + \n parseInt(document.getElementById('loses_ME').value) + \n parseInt(document.getElementById('loses_PS').value);\n document.getElementById('loses_sum').value = loses_sum;\n\n document.getElementById('rate_sum').value = calcRate(parseInt(wins_sum), parseInt(loses_sum));\n}\n\n// 勝率計算\nfunction calcRate(wins, loses) {\n var rate = Math.round(wins / (wins + loses) * 100);\n if ( Number.isNaN(rate) ) { rate = 0; }\n return rate;\n}\n\n// データ連携\nfunction doDataLink(data) {\n Android.dataLink(data);\n}\n" text.open w, f, "dqrbattlelog-edit.js" text.writeln f, buf$ text.close f fn.end ! 入力画面HTMLテンプレ読み込み fn.def LoadEditHtml$() html_edit$ = "" text.open r, f, "dqrbattlelog-edit.html" while 1 text.readln f, line$ if line$ = "EOF" then w_r.break html_edit$ += line$ repeat text.close f fn.rtn html_edit$ fn.end ! ログ選択 fn.def SelectLog$() dir "", fnames$[] dialog.select tapped, fnames$[] if tapped = 0 file.exists result, "冒険者の書.dbl" if result = 0 fname$ = "dummy.txt" else fname$ = "冒険者の書.dbl" endif else fname$ = fnames$[tapped] endif fn.rtn fname$ fn.end ! 選択したログをHTMLに反映 fn.def SetupEditHtml$(html_edit$, fname$) ! フォーム初期値 log_deckname$ = "冒険者の書" log_leader$ = "テリー" log_wins_sum$ = "0" log_loses_sum$ = "0" log_rate_sum$ = "0" log_tops$ = "0" log_bottoms$ = "0" log_wins_TE$ = "0" log_loses_TE$ = "0" log_rate_TE$ = "0" log_wins_ZE$ = "0" log_loses_ZE$ = "0" log_rate_ZE$ = "0" log_wins_AL$ = "0" log_loses_AL$ = "0" log_rate_AL$ = "0" log_wins_KU$ = "0" log_loses_KU$ = "0" log_rate_KU$ = "0" log_wins_TO$ = "0" log_loses_TO$ = "0" log_rate_TO$ = "0" log_wins_ME$ = "0" log_loses_ME$ = "0" log_rate_ME$ = "0" log_wins_PS$ = "0" log_loses_PS$ = "0" log_rate_PS$ = "0" ext$ = word$(fname$, 2, "\\.") if ext$ = "dbl" ! ログ読み込み text.open r, f, fname$ while 1 text.readln f, line$ if line$ = "EOF" then w_r.break sw.begin word$(line$, 1, ":") sw.case "デッキ名" log_deckname$ = word$(line$, 2, ":") sw.break sw.case "リーダー" log_leader$ = word$(line$, 2, ":") log_wins_sum$ = word$(line$, 3, ":") log_loses_sum$ = word$(line$, 4, ":") log_rate_sum$ = word$(line$, 5, ":") sw.break sw.case "先攻" log_tops$ = word$(line$, 2, ":") sw.break sw.case "後攻" log_bottoms$ = word$(line$, 2, ":") sw.break sw.case "テリー" log_wins_TE$ = word$(line$, 2, ":") log_loses_TE$ = word$(line$, 3, ":") log_rate_TE$ = word$(line$, 4, ":") sw.break sw.case "ゼシカ" log_wins_ZE$ = word$(line$, 2, ":") log_loses_ZE$ = word$(line$, 3, ":") log_rate_ZE$ = word$(line$, 4, ":") sw.break sw.case "アリーナ" log_wins_AL$ = word$(line$, 2, ":") log_loses_AL$ = word$(line$, 3, ":") log_rate_AL$ = word$(line$, 4, ":") sw.break sw.case "ククール" log_wins_KU$ = word$(line$, 2, ":") log_loses_KU$ = word$(line$, 3, ":") log_rate_KU$ = word$(line$, 4, ":") sw.break sw.case "トルネコ" log_wins_TO$ = word$(line$, 2, ":") log_loses_TO$ = word$(line$, 3, ":") log_rate_TO$ = word$(line$, 4, ":") sw.break sw.case "ミネア" log_wins_ME$ = word$(line$, 2, ":") log_loses_ME$ = word$(line$, 3, ":") log_rate_ME$ = word$(line$, 4, ":") sw.break sw.case "ピサロ" log_wins_PS$ = word$(line$, 2, ":") log_loses_PS$ = word$(line$, 3, ":") log_rate_PS$ = word$(line$, 4, ":") sw.break sw.end repeat text.close f ! HTMLにログデータ反映 html_edit$ = replace$(html_edit$, "id=\"deckname\" value=\"冒険者の書\"", "id=\"deckname\" value=\"" + log_deckname$ + "\"") html_edit$ = replace$(html_edit$, "", "") html_edit$ = replace$(html_edit$, "id=\"wins_sum\" value=\"0\"", "id=\"wins_sum\" value=\"" + log_wins_sum$ + "\"") html_edit$ = replace$(html_edit$, "id=\"loses_sum\" value=\"0\"", "id=\"loses_sum\" value=\"" + log_loses_sum$ + "\"") html_edit$ = replace$(html_edit$, "id=\"rate_sum\" value=\"0\"", "id=\"rate_sum\" value=\"" + log_rate_sum$ + "\"") html_edit$ = replace$(html_edit$, "id=\"tops\" value=\"0\"", "id=\"tops\" value=\"" + log_tops$ + "\"") html_edit$ = replace$(html_edit$, "id=\"bottoms\" value=\"0\"", "id=\"bottoms\" value=\"" + log_bottoms$ + "\"") html_edit$ = replace$(html_edit$, "id=\"wins_TE\" value=\"0\"", "id=\"wins_TE\" value=\"" + log_wins_TE$ + "\"") html_edit$ = replace$(html_edit$, "id=\"loses_TE\" value=\"0\"", "id=\"loses_TE\" value=\"" + log_loses_TE$ + "\"") html_edit$ = replace$(html_edit$, "id=\"rate_TE\" value=\"0\"", "id=\"rate_TE\" value=\"" + log_rate_TE$ + "\"") html_edit$ = replace$(html_edit$, "id=\"wins_ZE\" value=\"0\"", "id=\"wins_ZE\" value=\"" + log_wins_ZE$ + "\"") html_edit$ = replace$(html_edit$, "id=\"loses_ZE\" value=\"0\"", "id=\"loses_ZE\" value=\"" + log_loses_ZE$ + "\"") html_edit$ = replace$(html_edit$, "id=\"rate_ZE\" value=\"0\"", "id=\"rate_ZE\" value=\"" + log_rate_ZE$ + "\"") html_edit$ = replace$(html_edit$, "id=\"wins_AL\" value=\"0\"", "id=\"wins_AL\" value=\"" + log_wins_AL$ + "\"") html_edit$ = replace$(html_edit$, "id=\"loses_AL\" value=\"0\"", "id=\"loses_AL\" value=\"" + log_loses_AL$ + "\"") html_edit$ = replace$(html_edit$, "id=\"rate_AL\" value=\"0\"", "id=\"rate_AL\" value=\"" + log_rate_AL$ + "\"") html_edit$ = replace$(html_edit$, "id=\"wins_KU\" value=\"0\"", "id=\"wins_KU\" value=\"" + log_wins_KU$ + "\"") html_edit$ = replace$(html_edit$, "id=\"loses_KU\" value=\"0\"", "id=\"loses_KU\" value=\"" + log_loses_KU$ + "\"") html_edit$ = replace$(html_edit$, "id=\"rate_KU\" value=\"0\"", "id=\"rate_KU\" value=\"" + log_rate_KU$ + "\"") html_edit$ = replace$(html_edit$, "id=\"wins_TO\" value=\"0\"", "id=\"wins_TO\" value=\"" + log_wins_TO$ + "\"") html_edit$ = replace$(html_edit$, "id=\"loses_TO\" value=\"0\"", "id=\"loses_TO\" value=\"" + log_loses_TO$ + "\"") html_edit$ = replace$(html_edit$, "id=\"rate_TO\" value=\"0\"", "id=\"rate_TO\" value=\"" + log_rate_TO$ + "\"") html_edit$ = replace$(html_edit$, "id=\"wins_ME\" value=\"0\"", "id=\"wins_ME\" value=\"" + log_wins_ME$ + "\"") html_edit$ = replace$(html_edit$, "id=\"loses_ME\" value=\"0\"", "id=\"loses_ME\" value=\"" + log_loses_ME$ + "\"") html_edit$ = replace$(html_edit$, "id=\"rate_ME\" value=\"0\"", "id=\"rate_ME\" value=\"" + log_rate_ME$ + "\"") html_edit$ = replace$(html_edit$, "id=\"wins_PS\" value=\"0\"", "id=\"wins_PS\" value=\"" + log_wins_PS$ + "\"") html_edit$ = replace$(html_edit$, "id=\"loses_PS\" value=\"0\"", "id=\"loses_PS\" value=\"" + log_loses_PS$ + "\"") html_edit$ = replace$(html_edit$, "id=\"rate_PS\" value=\"0\"", "id=\"rate_PS\" value=\"" + log_rate_PS$ + "\"") endif fn.rtn html_edit$ fn.end ! ログファイル削除 fn.def AppCmdDelete(logname$) file.exists result, logname$ + ".dbl" if result = 0 then fn.rtn 0 dialog.message "確認", "ファイル " + logname$ + ".dbl を削除しますか?", result, "はい", "いいえ" if result <> 1 then fn.rtn 0 file.delete result, logname$ + ".dbl" if result <> 0 popup "ファイル " + logname$ + ".dbl を削除しました" endif fn.rtn 1 fn.end ! ログファイルセーブ fn.def AppCmdSave(logdata$) fname$ = word$(logdata$, 1, "\n") fname$ = word$(fname$, 2, ":") text.open w, f, fname$ + ".dbl" text.writeln f, logdata$ text.close f popup "セーブしました" fn.end Init: call CreateEditHtml() call CreateEditJs() OpenLog: ! 入力画面セットアップ html_edit$ = LoadEditHtml$() fname$ = SelectLog$() html_edit$ = SetupEditHtml$(html_edit$, fname$) ! 入力画面オープン html.open html.load.string html_edit$ MainLoop: do html.get.datalink data$ until data$ <> "" datatype$ = left$(data$, 4) data$ = mid$(data$,5) sw.begin datatype$ sw.case "BAK:" end sw.break sw.case "ERR:" print "Error: " + data$ sw.break ! Android.dataLink()が実行された sw.case "DAT:" cmd$ = word$(data$, 1, ";") data$ = word$(data$, 2, ";") sw.begin cmd$ sw.case "delete" if AppCmdDelete(data$) then html.close : goto OpenLog sw.break sw.case "open" html.close goto OpenLog sw.break sw.case "save" AppCmdSave(data$) sw.break sw.end sw.break sw.default print "Unexpected data type:", datatype$ + data$ end sw.end goto MainLoop OnBackground: if background() else endif background.resume