99/* Function to request files */
1010function getFile ( sUrl ) {
1111 /* Init request */
12- var oReq = new XMLHttpRequest ( ) ;
12+ let oReq = new XMLHttpRequest ( ) ;
13+ //console.log("@<- " + sUrl);
1314
1415 /* Sending request */
1516 oReq . open ( "get" , sUrl , false ) ;
@@ -24,41 +25,44 @@ function getFile(sUrl) {
2425 }
2526}
2627
27- class Duckuino {
28- constructor ( ) { }
29-
30- listModules ( ) {
31- /* List all modules in the moduleList file */
32- if ( ! this . moduleArray ) {
33- this . moduleArray = getFile ( "modules/modules" ) . split ( '\n' ) ;
34- this . moduleArray . pop ( ) ;
35- }
36-
37- /* Return the list */
38- return this . moduleArray ;
39- }
40-
41- loadModule ( moduleName ) {
42- /* Check if module exists */
43- if ( this . listModules ( ) . indexOf ( moduleName ) == - 1 ) {
44- console . error ( "Error: This module doesn't exist !" ) ;
45-
46- /* Module is not loaded */
47- this . loadedModule = undefined ;
48- } else {
49- /* Load module */ /* jshint evil:true */
50- this . loadedModule = eval ( getFile ( "modules/" + moduleName + ".js" ) ) ;
28+ class Modules {
29+ constructor ( ) {
30+ /* Load modules */ /* jshint evil:true */
31+ let modules = JSON . parse ( getFile ( "modules/modules.json" ) ) ;
32+ for ( let x in modules ) {
33+ let m = modules [ x ] ;
34+ m . meta = JSON . parse ( getFile ( "modules/" + m . path + m . meta ) ) ;
35+ m . module = eval ( getFile ( "modules/" + m . path + m . module ) ) ;
36+ if ( Object . keys ( m . meta . locales ) . length > 0 ) {
37+ let ls = m . meta . locales ;
38+ for ( let y in ls ) {
39+ let l = ls [ y ] ;
40+ if ( y == "_meta" )
41+ continue ;
42+ l . data = getFile ( "modules/" + m . path + l . path ) ;
43+ }
44+ ls . _meta . header = getFile ( "modules/" + m . path + ls . _meta . header ) ;
45+ for ( let y in ls . _meta . parts ) {
46+ let f = ls . _meta . parts [ y ] ;
47+ if ( f == "_locale_" )
48+ continue ;
49+ ls . _meta . parts [ y ] = getFile ( "modules/" + m . path + f ) ;
50+ }
51+ }
5152 }
53+ this . list = modules ;
5254 }
55+ }
5356
54- /* TO-DO: getModuleInfos() {} */
57+ class Duckuino {
58+ constructor ( ) { }
5559
56- compileCode ( compileStr ) {
60+ compileCode ( compileStr , withModule ) {
5761 /* Init timer */
58- var timerStart = window . performance . now ( ) ;
62+ let timerStart = window . performance . now ( ) ;
5963
6064 /* Check if module loaded */
61- if ( this . loadedModule === undefined ) {
65+ if ( withModule === undefined ) {
6266 return {
6367 compiledCode : undefined ,
6468 compileTime : - 1 ,
@@ -92,32 +96,32 @@ class Duckuino {
9296 this . dataStorage = new Object ( ) ;
9397 this . compiledCode = '' ;
9498
95- var commandKnown ;
96- var lineStr ;
97- var lastLine = '' ; var lastLineCount = 0 ;
99+ let commandKnown ;
100+ let lineStr ;
101+ let lastLine = '' ; let lastLineCount = 0 ;
98102
99103 /* Cut the input in lines */
100- var lineArray = compileStr . split ( '\n' ) ;
104+ let lineArray = compileStr . split ( '\n' ) ;
101105
102106 /* Loop every line */
103- for ( var i = 0 ; i < lineArray . length ; i ++ )
107+ for ( let i = 0 ; i < lineArray . length ; i ++ )
104108 {
105109 /* Line empty, skip */
106110 if ( lineArray [ i ] === '' || lineArray [ i ] === '\n' )
107111 continue ;
108112
109- /* Reset vars */
113+ /* Reset lets */
110114 commandKnown = false ;
111115 lineStr = '' ;
112116
113117 /* Split lines in words */
114- var argList = lineArray [ i ] . split ( ' ' ) ;
115- var argOne = argList [ 0 ] ;
118+ let argList = lineArray [ i ] . split ( ' ' ) ;
119+ let argOne = argList [ 0 ] ;
116120
117121 /* Parse commands */
118- if ( this . loadedModule . functionMap [ argOne ] !== undefined ) {
119- var µ = new Object ( {
120- keyMap : this . loadedModule . keyMap ,
122+ if ( withModule . functionMap [ argOne ] !== undefined ) {
123+ let µ = new Object ( {
124+ keyMap : withModule . keyMap ,
121125 /**
122126 * Pushes the error to the global error list.
123127 */
@@ -136,10 +140,10 @@ class Duckuino {
136140 */
137141 trimLast : function ( thisPtr , lastLine , lastLineCount ) {
138142 return function ( ) {
139- var tmpVar = thisPtr . compiledCode . split ( '\n' ) ;
143+ let tmplet = thisPtr . compiledCode . split ( '\n' ) ;
140144
141- tmpVar . splice ( - lastLineCount , lastLineCount - 1 ) ;
142- thisPtr . compiledCode = tmpVar . join ( '\n' ) ;
145+ tmplet . splice ( - lastLineCount , lastLineCount - 1 ) ;
146+ thisPtr . compiledCode = tmplet . join ( '\n' ) ;
143147
144148 return lastLine ;
145149 } ;
@@ -161,24 +165,24 @@ class Duckuino {
161165 } ) ;
162166
163167 /* Execute the function and add the returned string to the current string */
164- lineStr += this . loadedModule . functionMap [ argOne ] ( argList , µ ) ;
168+ lineStr += withModule . functionMap [ argOne ] ( argList , µ ) ;
165169
166170 /* Post process the line */
167- lineStr = this . loadedModule . postLine ( lineStr , µ ) ;
171+ lineStr = withModule . postLine ( lineStr , µ ) ;
168172 } else { /* Parse keystokes */
169- var strokeArray = Array ( ) ;
173+ let strokeArray = Array ( ) ;
170174
171- for ( var y = 0 ; y < argList . length ; y ++ ) {
175+ for ( let y = 0 ; y < argList . length ; y ++ ) {
172176
173- if ( this . loadedModule . commandMap [ argList [ y ] ] !== undefined ) {
177+ if ( withModule . commandMap [ argList [ y ] ] !== undefined ) {
174178 /* Push key to Array */
175- strokeArray . push ( this . loadedModule . commandMap [ argList [ y ] ] ) ;
176- } else if ( this . loadedModule . comboMap [ argList [ y ] ] !== undefined ) {
179+ strokeArray . push ( withModule . commandMap [ argList [ y ] ] ) ;
180+ } else if ( withModule . comboMap [ argList [ y ] ] !== undefined ) {
177181 /* Push key to Array */
178- strokeArray . push ( this . loadedModule . comboMap [ argList [ y ] ] ) ;
179- } else if ( this . loadedModule . keyMap [ argList [ y ] ] !== undefined && y != 0 ) {
182+ strokeArray . push ( withModule . comboMap [ argList [ y ] ] ) ;
183+ } else if ( withModule . keyMap [ argList [ y ] ] !== undefined && y != 0 ) {
180184 /* Push key to Array */
181- strokeArray . push ( '"' + this . loadedModule . keyMap [ argList [ y ] ] + '"' ) ;
185+ strokeArray . push ( withModule . keyMap [ argList [ y ] ] ) ;
182186 } else {
183187 /* If command unknown, throw error */
184188 this . errorList . push ( {
@@ -189,7 +193,7 @@ class Duckuino {
189193 }
190194
191195 /* Transform key array to string */
192- lineStr += this . loadedModule . computeKeys ( strokeArray ) ;
196+ lineStr += withModule . computeKeys ( strokeArray ) ;
193197 }
194198
195199 /* Calculate line count */
@@ -201,8 +205,8 @@ class Duckuino {
201205 }
202206
203207 /* Stop timer */
204- var timerEnd = window . performance . now ( ) ;
205- var timeElapsed = ( timerEnd - timerStart ) . toFixed ( 2 ) ;
208+ let timerEnd = window . performance . now ( ) ;
209+ let timeElapsed = ( timerEnd - timerStart ) . toFixed ( 2 ) ;
206210
207211 /* Return error if error and code if not */
208212 if ( this . errorList . length > 0 ) {
@@ -213,7 +217,7 @@ class Duckuino {
213217
214218 returnCode : 1 ,
215219 returnMessage : function ( errorList ) {
216- var errorString ;
220+ let errorString ;
217221
218222 if ( errorList . length > 1 ) {
219223 errorString = "The compiler returned some errors:\n" ;
@@ -232,7 +236,7 @@ class Duckuino {
232236 } else {
233237 /* Return the compiled code */
234238 return {
235- compiledCode : this . loadedModule . getFinalCode ( this . compiledCode ) ,
239+ compiledCode : withModule . getFinalCode ( this . compiledCode ) ,
236240 compileTime : timeElapsed ,
237241
238242 returnCode : 0 ,
0 commit comments