OSDN Git Service

Merge commit 'c0ecce88cd8ecb7817b7283945e9f3e7315ccf5d'
authorhikarupsp <hikarupsp@users.sourceforge.jp>
Wed, 21 Aug 2013 17:08:28 +0000 (02:08 +0900)
committerhikarupsp <hikarupsp@users.sourceforge.jp>
Wed, 21 Aug 2013 17:08:28 +0000 (02:08 +0900)
Conflicts:
www/corelib/classes/BlockClass.js
www/corelib/classes/StageObjectClass.js

www/corelib/classes/GameStageClass.js
www/corelib/classes/HorizonalScrollStageClass.js
www/corelib/classes/OperatedCharacterClass.js
www/corelib/core.js
www/editor/index.html
www/index.html
www/index_local_debug.html

index 5104f82..55a21c8 100644 (file)
@@ -112,7 +112,10 @@ GameStage.prototype = {
                        //\83L\83\83\83\93\83o\83X\82ð\91S\8fÁ\8b\8e
                        this.mainContext.clearRect(0, 0, this.mainCanvas.width, this.mainCanvas.height);
                }
-               this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width, this.collisionMapCanvas.height);
+               if(this.collisionMapContext)
+               {
+                       this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width, this.collisionMapCanvas.height);
+               }
        },
        runStage: function(){
                //\83X\83e\81[\83W\8f\89\8aú\89»\8f\88\97\9d
@@ -122,7 +125,6 @@ GameStage.prototype = {
                this.collisionMapContext = this.collisionMapCanvas.getContext('2d');
                this.collisionMapContext.fillStyle = "rgba(0,0,0, 0.2)";
                this.collisionMapContext.strokeStyle = "rgba(0,0,0, 0.2)";
-               this.collisionMapContext.scale(1, 1);
        },
        stopStage: function(){
                //\83X\83e\81[\83W\8fI\97¹\8f\88\97\9d
index b32fba6..97e914d 100644 (file)
@@ -46,12 +46,14 @@ var HorizonalScrollStageClass = function()
                        {
                                this.mainContext.drawImage(this.background, pos, 0, 640, 480);
                        }
-               }else
-               {
+               } else{
                        //\83L\83\83\83\93\83o\83X\82ð\91S\8fÁ\8b\8e
                        this.mainContext.clearRect(0, 0, this.mainCanvas.width, this.mainCanvas.height);
                }
-               this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width, this.collisionMapCanvas.height);
+               if(this.collisionMapContext)
+               {
+                       this.collisionMapContext.clearRect(0, 0, this.collisionMapCanvas.width, this.collisionMapCanvas.height);
+               }
        },
        
        //\83X\83N\83\8d\81[\83\8b\82µ\82½\82¢\82Æ\82«\82É\81Atick\96\88\82É\8cÄ\82Ô\81B
index 4132c5f..66325de 100644 (file)
@@ -34,6 +34,7 @@ var OperatedCharacterClass = function(ownerStage, args){
        },
        
        //\92Ê\8fí\83W\83\83\83\93\83v\82·\82é\82Æ\82«\82É\8cÄ\82Î\82ê\82é\81B\83W\83\83\83\93\83v\83L\81[\82ð\89\9f\82µ\82Ä\82¢\82é\8aÔ\82Í\82¸\82Á\82Æ\8cÄ\82Î\82ê\82é
+       //\83W\83\83\83\93\83v\83L\81[\82ð\89\9f\82µ\82Ä\82¢\82é\8e\9e\8aÔ\82Ì\92·\82³\82É\89\9e\82\82Ä\83W\83\83\83\93\83v\82Ì\8d\82\82³\82ª\95Ï\89»\82·\82é\81B
        jump : function(){
                if((this.collideFlag & 4) != 0)
                {
@@ -50,6 +51,8 @@ var OperatedCharacterClass = function(ownerStage, args){
                }
        },
        jumpEnd: function(){
+               //\83W\83\83\83\93\83v\83L\81[\82ª\89\9f\82³\82ê\82Ä\82¢\82È\82¢\8aÔ\82Í\82±\82¿\82ç\82ª\8cÄ\82Ñ\8fo\82³\82ê\82é\81B
+               //\83W\83\83\83\93\83v\83L\81[\82ð\82²\82­\92Z\8e\9e\8aÔ\89\9f\82µ\82½\8fê\8d\87\82Å\82à\81A\82 \82é\88ê\92è\82Ì\8d\82\82³\82Ü\82Å\82Í\83W\83\83\83\93\83v\82·\82é\82æ\82¤\82É\82·\82é\82½\82ß\81B
                if(this.jumpPower_tickCount < this.jumpPower_tickCountBase - this.jumpPower_tickCountAtLeast){
                        this.jumpPower_tickCount = 0;
                } else{
index ab784ed..91b992b 100644 (file)
@@ -66,6 +66,9 @@ function GameManager(parent, debugTextName){
        if(debugTextName == undefined) debugTextName = "DebugText";
        if(parent == undefined) parent = document.getElementById("MainArea");
        
+       //parentの初期設定
+       if(parent.style.position != 'absolute') parent.style.position = 'relative';
+       
        this.userID = 0;
        //サブマネージャーの設定
        this.networkManager = new NetworkManager(this);
@@ -78,7 +81,6 @@ function GameManager(parent, debugTextName){
        this.mainContext = this.mainCanvas.getContext('2d');
        this.debugText = document.getElementById(debugTextName);        //要素が存在しないとnullになり、デバッグが無効になる
        if(!this.debugText) this.debugText = null;
-
        
        //ブラウザチェック
        this.isIE = false;
index d6389c1..aacaf58 100644 (file)
@@ -116,6 +116,14 @@ window.onload = function(){
 
 };
 
+window.onbeforeunload = function(e) {
+       if(isModified)
+       {
+               e = e || window.event;
+               return e.returnValue = '変更が保存されていません。破棄されますが続行しますか?';
+       }
+};
+
 function openFile()
 {
        if(isModified)
@@ -206,21 +214,176 @@ function editInTextEditor()
 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);
 
@@ -232,7 +395,7 @@ $(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>
@@ -243,11 +406,40 @@ $(window).bind("resize", resize);
                                <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>
index cbfbe30..91281ce 100755 (executable)
@@ -20,10 +20,10 @@ onload = function() {
 </script>
 </head>
 <body>
-       <div id="MainArea" style="position:absolute; top:0px; left:0px"></div>
+       <div id="MainArea" style="width: 640px; height: 480px;"></div>
        <div id="Resources"></div>
        <form>
-       <textarea id="DebugText" rows="8" cols="64" style="position:absolute; top:600px; z-index:4"></textarea>
+       <textarea id="DebugText" rows="8" cols="64" style="z-index:4"></textarea>
        </form>
 </body>
 </html>
\ No newline at end of file
index de31e7c..e5f38db 100644 (file)
@@ -74,9 +74,9 @@ function switchDebug()
 </script>
 </head>
 <body>
-       <div id="MainArea" style="position: inline"></div>
+       <div id="MainArea" style="width: 640px; height: 480px"></div>
        <div id="Resources"></div>
-       <div style="z-index: 1; top: 520px; position: absolute; left: 0;">
+       <div style="z-index: 1;">
                <form><textarea id="DebugText" rows="8" cols="64"></textarea></form>
                <input type="button" onclick="run(); return false;" value="ステージの実行/再実行"><input type="button" onclick="stop(); return false;" value="ステージの停止"><input type="button" onclick="switchDebug(); return false;" value="デバッグの有効/無効">
        </div>