};
+window.onbeforeunload = function(e) {
+ if(isModified)
+ {
+ e = e || window.event;
+ return e.returnValue = '変更が保存されていません。破棄されますが続行しますか?';
+ }
+};
+
function openFile()
{
if(isModified)
function editInGui()
{
if(_guiMode) return;
- textToGui();
- $('#guiWindow').fadeIn();
- $('#textWindow').fadeOut();
- _guiMode = true;
+ if(textToGui()) //gui移行に成功したら
+ {
+ $('#guiWindow').fadeIn();
+ $('#textWindow').fadeOut();
+ _guiMode = true;
+ }
}
var _guiStageInfo = null;
+var _guiTbl = null;
+var _guiElements = null;
var _guiMode = false;
function textToGui()
{
- //eval($("#textarea textarea").val());
- //_guiStageInfo = stgInfo;
- //$('#editorMessageBox').text("Stage Size : (" + stgInfo.width + ", " + stgInfo.height + ") ");
+ try{
+ var code = $("#textarea textarea").val();
+
+ // tblの取得
+ var tblStart = code.indexOf("with(stgObjects)") + 16;
+ if(tblStart == -1) return false;
+ var tblLength = exploreEndParen(code.slice(tblStart));
+ if(tblLength == -1) return false;
+ var tblCode = "with(stgObjects)" + code.slice(tblStart, tblStart + tblLength);
+
+ // evalのための定義
+ var stgObjects = {a:"a",b:"b",c:"c",d:"d",e:"e",f:"f",g:"g",h:"h",i:"i",j:"j",k:"k",l:"l",m:"m",n:"n",o:"o",p:"p",q:"q",r:"r",s:"s",t:"t",u:"u",v:"v",w:"w",x:"x",y:"y",z:"z",_:"_"};
+ eval(tblCode); //これでtblにテーブルデータが入る
+ if(!tbl) return false;
+ _guiTbl = tbl; //_guiTbl に代入
+
+ // stgInfoの取得
+ var infoStart = code.indexOf("var stgInfo");
+ if(infoStart == -1) return false;
+ var infoLength = exploreEndParen(code.slice(infoStart));
+ if(infoLength == -1) return false;
+ var infoCode = code.slice(infoStart, infoStart + infoLength);
+ eval(infoCode);
+ if(!stgInfo) return false;
+ _guiStageInfo = stgInfo;
+ if(!stgInfo.width) return false;
+ if(!stgInfo.height) return false;
+
+
+ //作業領域の描画
+ var area = document.getElementById("editorBox");
+ $('#editorBox > div').remove();
+ _guiElements = [];
+ for(var y = 0; y < stgInfo.height / 32; y++)
+ {
+ _guiElements[y] = [];
+ for(var x = 0; x < stgInfo.width / 32; x++)
+ {
+ var element = document.createElement('div');
+ element.style.position = "absolute";
+ element.style.top = (y * 32) + "px";
+ element.style.left = (x * 32) + "px";
+ element.style.width = element.style.height = "32px";
+ element.style.border = "1px white solid";
+ element.style.backgroundColor = "black";
+ element.style.color = "white";
+
+ _guiElements[y][x] = element;
+ area.appendChild(element);
+ eval("func = function(){guiElementClickEvent(" + x + ", " + y + ");};");
+ element.addEventListener("click", func);
+ }
+ }
+
+ for(var y = 0; y < _guiTbl.length; y++)
+ {
+ for(var x = 0; x < _guiTbl[y].length; x++)
+ {
+ if(_guiElements[y] && _guiElements[y][x])
+ {
+ $(_guiElements[y][x]).text(_guiTbl[y][x] != "_" ? _guiTbl[y][x] : "");
+ }else
+ {
+ window.alert("tbl[]のサイズがステージのサイズをオーバーしています");
+ return false;
+ }
+ }
+ }
+
+
+
+
+ return true;
+ }catch(e)
+ {
+ window.alert("error : " + e);
+ return false;
+ }
+}
+
+function guiElementClickEvent(x,y)
+{
+ var val = $('#stageBox input:radio:checked').val();
+ if(val == "addr")
+ {
+ window.alert("位置(" + x + ", " + y + ")\n座標(" + (x * 32) + ", " + (y * 32) + ")");
+ }else
+ {
+ $(_guiElements[y][x]).text(val);
+ _guiTbl[y][x] = val;
+ GuiToText();
+ }
+}
+
+function GuiToText()
+{
+ var code = $("#textarea textarea").val();
+ var tblCode = "with(stgObjects){\n\tvar tbl = [\n";
+ for(var y = 0; y < _guiStageInfo.height / 32; y++)
+ {
+ tblCode += "\t\t[";
+ if(_guiTbl[y])
+ {
+ for(var x = 0; x < _guiStageInfo.width / 32; x++)
+ {
+ if(_guiTbl[y][x])
+ {
+ tblCode += _guiTbl[y][x];
+ }else
+ {
+ tblCode += " ";
+ }
+ tblCode += ",";
+ }
+ if(tblCode.slice(tblCode.length - 1) == ",") tblCode = tblCode.slice(0, tblCode.length - 1);
+ }
+ tblCode += "],\n";
+ }
+ if(tblCode.slice(tblCode.length - 3) == "],\n") tblCode = tblCode.slice(0, tblCode.length - 2) + "\n";
+ tblCode += "\t];\n";
+ tblCode += "}";
+ var tblStart = code.indexOf("with(stgObjects)");
+ if(tblStart == -1) return false;
+ var tblLength = exploreEndParen(code.slice(tblStart + 16)) + 16;
+ if(tblLength == 15) return false;
+
+ code = code.slice(0, tblStart) + tblCode + code.slice(tblStart + tblLength);
+ $("#textarea textarea").val(code);
+
+ isModified = true;
+ return true;
}
+// 最後にカッコが閉じて最初と同じレベルに到達するまでのインデックスを返す。カッコが閉じられずに終わったら(もしくは急に閉じかっこが出てきたら)-1
+function exploreEndParen(text)
+{
+ var nest = 0;
+
+ for(var i = 0; i < text.length; i++)
+ {
+ if(text[i] == '{' || text[i] == '(' || text[i] == '[') nest++;
+ else if(text[i] == '}' || text[i] == ')' || text[i] == ']')
+ {
+ nest--;
+ if(nest < 0) //開始カッコがないのに急に終了カッコが出てきた
+ {
+ return -1;
+ }else if(nest == 0)
+ {
+ return i + 1; //カッコの後ろまで含める
+ }
+ }
+ }
+
+ return nest != 0 ? -1 : i;
+}
$(window).bind("resize", resize);
<a onclick="saveFile()">名前を付けて保存</a>
<a onclick="openFromBrowser()">ブラウザから開く</a>
<a onclick="saveToBrowser();">ブラウザに保存</a>
- <a onclick="editInGui();"><s>GUI編集</s></a>
+ <a onclick="editInGui();">GUI編集</a>
<a onclick="editInTextEditor()">テキスト編集</a>
<a onclick="run()">実行</a>
<a target="_blank" href="readme.txt">ヘルプ</a>
<strong>テンプレート</strong><br>
<div id="templeteBox" style="height: 300px; overflow: scroll; background-color: white; border: 1px black solid; margin: 10px;"></div>
<strong>ステージ</strong><br>
- <div id="stageBox" style="height: 300px; overflow: scroll; background-color: white; border: 1px black solid; margin: 10px;"></div>
+ <div id="stageBox" style="height: 300px; overflow: scroll; background-color: white; border: 1px black solid; margin: 10px;">
+ <input type="radio" name="stageChar" value="addr" checked>(座標の取得)<br>
+ <input type="radio" name="stageChar" value="_">_<br>
+ <input type="radio" name="stageChar" value="a">a<br>
+ <input type="radio" name="stageChar" value="b">b<br>
+ <input type="radio" name="stageChar" value="c">c<br>
+ <input type="radio" name="stageChar" value="d">d<br>
+ <input type="radio" name="stageChar" value="e">e<br>
+ <input type="radio" name="stageChar" value="f">f<br>
+ <input type="radio" name="stageChar" value="g">g<br>
+ <input type="radio" name="stageChar" value="h">h<br>
+ <input type="radio" name="stageChar" value="i">i<br>
+ <input type="radio" name="stageChar" value="j">j<br>
+ <input type="radio" name="stageChar" value="k">k<br>
+ <input type="radio" name="stageChar" value="l">l<br>
+ <input type="radio" name="stageChar" value="m">m<br>
+ <input type="radio" name="stageChar" value="n">n<br>
+ <input type="radio" name="stageChar" value="o">o<br>
+ <input type="radio" name="stageChar" value="p">p<br>
+ <input type="radio" name="stageChar" value="q">q<br>
+ <input type="radio" name="stageChar" value="r">r<br>
+ <input type="radio" name="stageChar" value="s">s<br>
+ <input type="radio" name="stageChar" value="t">t<br>
+ <input type="radio" name="stageChar" value="u">u<br>
+ <input type="radio" name="stageChar" value="v">v<br>
+ <input type="radio" name="stageChar" value="w">w<br>
+ <input type="radio" name="stageChar" value="x">x<br>
+ <input type="radio" name="stageChar" value="y">y<br>
+ <input type="radio" name="stageChar" value="z">z<br>
+ </div>
</div>
<div style="padding: 30px;">
<strong>エディット</strong>
- <div id="editorBox" style="height: 500px; overflow: scroll; background-color: white; border: 1px black solid; margin: 10px;"></div>
+ <div id="editorBox" style="height: 500px; overflow: scroll; background-color: white; border: 1px black solid; margin: 10px; position: relative; font-size: 32px;"></div>
<div id="editorMessageBox"></div>
</div>
</div>