Skip to content

Commit 4447f75

Browse files
authored
Merge pull request #76 from Nurrl/v2.1
v2.1 - The road to the new version
2 parents 0e45cb4 + 47299bd commit 4447f75

36 files changed

+3301
-207
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!-- DISCLAIMER: If you don't follow the issue sending guidelines,
2+
your issue may be marked as invalid and closed without any review ! Thanks -->
3+
4+
Are you using the live version that could be found [here](https://nurrl.github.io/Duckuino/) ?
5+
- [ ] Yes, absolutely
6+
- [ ] No, I might try it out
7+
<!--
8+
To select an option, put a 'x' in the [ ], like so:
9+
- [x]
10+
If you are not using the live version, please try it out before
11+
posting an issue because it might be already fixed.
12+
-->
13+
14+
What type of issue is it ?
15+
- [ ] Graphical issue (UX, UI, Graphical Glitch)
16+
- [ ] Feature issue (Command not/bad implemented, Non functionnal feature)
17+
- [ ] Crash (The buttons clicks does nothing at all, Error in console)
18+
- [ ] Question (Any type about the project :D)
19+
<!--
20+
You can ask any question about the project.
21+
If that's about a Crash/Feature issue, please paste any relevant output
22+
in the following block of code :
23+
|
24+
\/
25+
-->
26+
```
27+
Here are relevant errors/infos outputed by the code !
28+
```
29+
30+
_Describe your problem here :D_

Duckuino.js

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
/* Function to request files */
1010
function 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,

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ https://nurrl.github.io/Duckuino/
1515
## Why Duckuino ?
1616
You can compile **Duckyscript** to **Arduino** code directly through the [live](https://nurrl.github.io/Duckuino/ "Duckuino Live") version, or reuse `Duckuino.js` for standalone use :
1717
```javascript
18-
/* Need to fill */
19-
```
20-
Output:
18+
let Duck = new Duckuino();
19+
let mods = new Modules().list;
2120

22-
```c
23-
/* Need to fill */
21+
let output = Duck.compileCode("STRING This is a test string !", mods[0].module);
22+
/* ^- Here will be the final compiled code |
23+
** and errors if applicable. |
24+
** Here is the selected module -/
25+
**
26+
** Note: You can iterate through the list and find the desired one,
27+
** by default, `0` will be the first module.
28+
*/
2429
```
2530
# Members
2631
- [Plazmaz](https://github.com/Plazmaz)

assets/css/style.css

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,15 @@ html, body {
1010
font-family: Lato, sans-serif;
1111
font-size: 16px;
1212

13-
/* Disable Scroll */
14-
overflow: hidden;
15-
16-
/* Size */
17-
height: 100%; width: 100%;
18-
}
19-
20-
/* Background blured image */
21-
body::before {
22-
/* Position */
23-
position: absolute;
24-
top: 0; left: 0;
25-
26-
/* Size */
27-
height: 100%; width: 100%;
28-
2913
/* Background */
3014
background-size: cover;
3115
background-image: url(../imgs/background.jpg);
3216
background-repeat: no-repeat;
3317
background-position: center;
18+
background-attachment: fixed;
3419

35-
/* Misc */
36-
/*filter: blur(1px);*/
37-
content: "";
38-
z-index: -1;
20+
/* Size */
21+
height: 100%; width: 100%;
3922
}
4023

4124
/* Text */
@@ -53,6 +36,8 @@ textarea {
5336
border: none; border-radius: 4px;
5437
padding: 8px;
5538

39+
word-wrap: break-word;
40+
word-break: break-all;
5641
box-sizing: border-box;
5742
resize: none;
5843
}
@@ -126,6 +111,7 @@ button:disabled {
126111

127112
/* Center parts */
128113
display: flex;
114+
flex-wrap: wrap;
129115
}
130116

131117
.part {
@@ -139,12 +125,22 @@ button:disabled {
139125
border-radius: 4px;
140126

141127
/* Separation */
142-
/*box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);*/
128+
/*box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);*/
143129

144130
/* Text */
145131
color: white;
146132
}
147133

134+
@media (max-width: 860px) {
135+
.part {
136+
width: 100%;
137+
}
138+
139+
.input {
140+
margin-top: 28px;
141+
}
142+
}
143+
148144
/* Elements */
149145
.process {
150146
/* Center text */
@@ -157,6 +153,7 @@ button:disabled {
157153
width: 100%;
158154

159155
display: none;
156+
z-index: 2;
160157
}
161158
.tooltip > span {
162159
/* Size */
@@ -213,6 +210,10 @@ button:disabled {
213210
width: 16px;
214211
height: 32px;
215212
}
213+
.combined-but > select option {
214+
/* Style */
215+
color: black;
216+
}
216217
.combined-but > select:disabled {
217218
/* Postion */
218219
opacity: .5;

0 commit comments

Comments
 (0)