Path: blob/main/projects/HexGL/libs/Editor_files/Project.js
4627 views
var pgli = pgli || {};123pgli.Project = gamecore.Base.extend('Project',4{5patternRoot: /\/([a-z]+\.pmod)/ig,6patternPath: /([a-z\/]+\/)[a-z]+\.pmod/ig78},910{11appInstance: null,12modules: null,13activeFile: null,14files:null,15keys :[],16name: "default",17path: "/files/",18root: "default.pmod",19diagram: null,20loadingQueue: [],21onLoad: function() { console.log("Project loaded."); },22232425init : function(projectFile, onLoad)26{27this.onLoad = onLoad;28this.modules = new gamecore.Hashtable();29this.files = new gamecore.Hashtable();30this.path = pgli.Project.patternPath.exec(projectFile)[1];31this.root = pgli.Project.patternRoot.exec(projectFile)[1];3233var self = this;3435this.loadFile(projectFile,this.root,true,true);3637},3839loadFile: function(path,name,doDependencies,doDiagram)40{41trace("#Loading ["+name+"].");42var self = this;43var request = $.ajax({44url: path,45type: 'get',46dataType: "text",47})48.success(function(data)49{50self.files.put(name, data);51self.keys.push(name);5253var object = pgli.lang.Parser.parseModule(data);54self.modules.put(name, object);5556if(doDependencies == true)57self.loadDependencies(object);5859if(doDiagram == true)60self.getAppInstance().addDiagramNode(name, object);6162trace("#["+name+"] loaded");6364self.onLoad();65})66.error(function()67{68throw "Unable to load file: " + path;69});70},7172loadDependencies: function(object)73{7475if(!("layers" in object))76return;7778var layers = object.layers;79var self = this;8081for (var i=0, len = layers.length; i<len ; i++)82{83if(!("use" in layers[i]) )84continue;8586var layerName = layers[i].use;8788trace("#Found dependency ["+layerName+"]");8990(function(name,self)91{92self.loadFile(self.path+name,name,true,true);9394})(layerName,self);95}9697},9899getModulesCount: function()100{101return this.keys.length;102},103104getModule: function(key)105{106return this.modules.get(key);107},108109getFile: function(key)110{111return this.files.get(key);112},113114getModuleKey: function(index)115{116return this.keys[index];117},118119getRootModule: function()120{121return this.modules.get(this.root);122},123124isEmpty: function()125{126return (this.keys.length <= 0);127},128129setAppInstance: function(app)130{131this.appInstance = app;132},133134getAppInstance: function()135{136return this.appInstance;137},138139setActiveFile: function(key)140{141this.activeFile = key;142},143144rememberActiveFile: function()145{146if(!this.activeFile) return;147148this.files.put(this.activeFile, this.getAppInstance().getEditorContent());149}150151/*updateDiagram: function()152{153154},155156render: function(canvasRenderer)157{158//canvasRenderer.Render(modules, root, new Hashtable());159}*/160161});162163