Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mamayaya1
GitHub Repository: mamayaya1/game
Path: blob/main/projects/HexGL/libs/Editor_files/Project.js
4627 views
1
var pgli = pgli || {};
2
3
4
pgli.Project = gamecore.Base.extend('Project',
5
{
6
patternRoot: /\/([a-z]+\.pmod)/ig,
7
patternPath: /([a-z\/]+\/)[a-z]+\.pmod/ig
8
9
},
10
11
{
12
appInstance: null,
13
modules: null,
14
activeFile: null,
15
files:null,
16
keys :[],
17
name: "default",
18
path: "/files/",
19
root: "default.pmod",
20
diagram: null,
21
loadingQueue: [],
22
onLoad: function() { console.log("Project loaded."); },
23
24
25
26
init : function(projectFile, onLoad)
27
{
28
this.onLoad = onLoad;
29
this.modules = new gamecore.Hashtable();
30
this.files = new gamecore.Hashtable();
31
this.path = pgli.Project.patternPath.exec(projectFile)[1];
32
this.root = pgli.Project.patternRoot.exec(projectFile)[1];
33
34
var self = this;
35
36
this.loadFile(projectFile,this.root,true,true);
37
38
},
39
40
loadFile: function(path,name,doDependencies,doDiagram)
41
{
42
trace("#Loading ["+name+"].");
43
var self = this;
44
var request = $.ajax({
45
url: path,
46
type: 'get',
47
dataType: "text",
48
})
49
.success(function(data)
50
{
51
self.files.put(name, data);
52
self.keys.push(name);
53
54
var object = pgli.lang.Parser.parseModule(data);
55
self.modules.put(name, object);
56
57
if(doDependencies == true)
58
self.loadDependencies(object);
59
60
if(doDiagram == true)
61
self.getAppInstance().addDiagramNode(name, object);
62
63
trace("#["+name+"] loaded");
64
65
self.onLoad();
66
})
67
.error(function()
68
{
69
throw "Unable to load file: " + path;
70
});
71
},
72
73
loadDependencies: function(object)
74
{
75
76
if(!("layers" in object))
77
return;
78
79
var layers = object.layers;
80
var self = this;
81
82
for (var i=0, len = layers.length; i<len ; i++)
83
{
84
if(!("use" in layers[i]) )
85
continue;
86
87
var layerName = layers[i].use;
88
89
trace("#Found dependency ["+layerName+"]");
90
91
(function(name,self)
92
{
93
self.loadFile(self.path+name,name,true,true);
94
95
})(layerName,self);
96
}
97
98
},
99
100
getModulesCount: function()
101
{
102
return this.keys.length;
103
},
104
105
getModule: function(key)
106
{
107
return this.modules.get(key);
108
},
109
110
getFile: function(key)
111
{
112
return this.files.get(key);
113
},
114
115
getModuleKey: function(index)
116
{
117
return this.keys[index];
118
},
119
120
getRootModule: function()
121
{
122
return this.modules.get(this.root);
123
},
124
125
isEmpty: function()
126
{
127
return (this.keys.length <= 0);
128
},
129
130
setAppInstance: function(app)
131
{
132
this.appInstance = app;
133
},
134
135
getAppInstance: function()
136
{
137
return this.appInstance;
138
},
139
140
setActiveFile: function(key)
141
{
142
this.activeFile = key;
143
},
144
145
rememberActiveFile: function()
146
{
147
if(!this.activeFile) return;
148
149
this.files.put(this.activeFile, this.getAppInstance().getEditorContent());
150
}
151
152
/*updateDiagram: function()
153
{
154
155
},
156
157
render: function(canvasRenderer)
158
{
159
//canvasRenderer.Render(modules, root, new Hashtable());
160
}*/
161
162
});
163