Вход Регистрация
Файл: Space race/libs/Editor_files/App.js
Строк: 184
<?php
var pgli pgli || {};

pgli.App gamecore.Base.extend("App",
// static

},
// instance

    
projectnull,
    
moduleListnull,
    
editornull,
    
diagramnull,
    
previewnull,
    
nodeCount0,
    
consolenull,
    
debug2// 0:none, 1:inapp, 2:console, 3:both

    
init: function(domDiagramdomModuleListdomEditordomPreview)
    {
        var 
self this;

        
this.moduleList = new pgli.ui.ModuleList(domModuleList);

        
this.editor ace.edit(domEditor);
        
this.editor.setFontSize("16px");
        
this.editor.setTheme("ace/theme/monokai");
        
this.editor.getSession().setMode("ace/mode/json");

        
this.diagram = new pgli.diagram.Diagram(domDiagram30);

        
this.preview = new pgli.render.CanvasRenderer(domPreview);

        
this.console = $('#console-text');

        
this.bindEvents();

        
pgli.lang.Parser.debug self.debug;

        
window.trace = function(args)
        {
            if(!
self.debug) return;
            for(var 
i=0len=arguments.lengthi<len; ++i)
            {
                if(
self.debug 2console.log(arguments[i]);
                if(
self.debug == || self.debug == 3) return;
                
self.console.append(arguments[i].toString()+"n");
                
self.console.scrollTop(
                    
self.console[0].scrollHeight self.console.height()
                );
            };
        }

        
window.clearTrace = function()
        {
            
self.console.text("");
        }
    },

    
bindEvents: function()
    {
        var 
self this;

        $(
window).on('resize', function(){ return self.resize.call(self); });
        $(
document).bind('keydown', function(e){ return self.onKeyDown.call(self,e); });
        $(
'#modules').on('drop', function(e) { return self.onDropEvent.call(self,e); });
        
//window.addEventListener("drop",function(e){ return self.onDropEvent.call(self,e); }) ;
         
    
},

    
bindProject: function(project)
    {
        
this.nodeCount 0;
        
this.project project;
        
this.project.setAppInstance(this);
        
this.moduleList.bindProject(project);
        
this.preview.bindProject(project);
        
this.draw();
    },

    
draw: function()
    {
        
this.moduleList != undefined && this.moduleList.draw();
        
//this.preview.draw();
    
},

    
showInEditor: function(module)
    {
        
this.project.setActiveFile(module);
        
this.editor.getSession().setValue(this.project.files.get(module));
    },

    
getEditorContent: function()
    {
        return 
this.editor.getSession().getValue();
    },

    
addDiagramNode: function(keymodule)
    {
        
this.diagram.addNode(new pgli.diagram.Node(keymodule50 160 this.nodeCount++, 50));
    },

    
resize: function()
    {
        
this.diagram.resize();
        
this.preview.resize();
    },

    
saveModule: function()
    {
        for(var 
i=0i<this.project.keys.length;i++)
        {
            var 
name this.project.keys[i]
            var 
fileToSave this.project.getModule(name);
            var 
jsonData = {file :'files/'+name ,objfileToSave};

            $.
ajax({
            
url:"/",
            
type:"POST",
            
dataJSON.stringify(jsonData),
            
contentType"application/json; charset=utf-8",
            
dataType"text",
            
success:function(a)
            {
                
console.log("AJAX POST OK: "a);
            },
            
error: function(a)
            {
                
console.log("AJAX POST ERROR: "a);
            }
            });
            
            
console.log("STARTED AJAX REQUEST");
        }
        
    },

    
onKeyDown: function(e)
    {
        if(
e.keyCode==117)
        {
            
this.updateDiagram();
            
e.preventDefault();
            return 
false;
        }
        else if(
e.keyCode==118)
        {
            
this.preview.draw();
            
e.preventDefault();
            return 
false;
        }
        else if(
e.keyCode==119)
        {
            
this.saveModule();
            
e.preventDefault();
            return 
false;
        }    
    },

    
updateDiagram:function()
    {
        
this.project.rememberActiveFile();
        
        for(var 
0len this.project.keys.lengthi<leni++)
        {

            var 
object pgli.lang.Parser.parseModule(this.project.files.get(this.project.keys[i]));
            
this.project.modules.put(this.project.keys[i], object);
            
this.diagram.getNode(this.project.keys[i]).module object;
            
//this.getNode.updateModule()...

        
}

        
this.diagram.draw();
    },

    
onDropEvent: function(e)
    {
        
trace("#Parsing dropped file(s)...");
        
e.preventDefault();
        var 
self this;

        var 
length e.originalEvent.dataTransfer.files.length;
        for (var 
0lengthi++) 
        {
            var 
file e.originalEvent.dataTransfer.files[i];
            
console.log(file);

            
fileName file.name;

            if(
== && this.project == null)
            {
                var 
path window.prompt("Please prove project's root path (with trailing slash).""../files/");
                
trace("#Opening new project from ["+fileName+"]...");
                
this.bindProject(new pgli.Project(path+fileName, function(){ 
                    
self.draw(); 
                    
self.showInEditor(self.project.root);
                }));
            }
            else
                
this.project.loadFile(self.project.path+fileName,fileName,true,true);

        }

        
this.draw();
        return 
false;
        

    }



});
?>
Онлайн: 2
Реклама