Skip to content

Commit

Permalink
Merge pull request #76 from Nurrl/v2.1
Browse files Browse the repository at this point in the history
v2.1 - The road to the new version
  • Loading branch information
lowlevl authored Apr 29, 2019
2 parents 0e45cb4 + 47299bd commit 4447f75
Show file tree
Hide file tree
Showing 36 changed files with 3,301 additions and 207 deletions.
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- DISCLAIMER: If you don't follow the issue sending guidelines,
your issue may be marked as invalid and closed without any review ! Thanks -->

Are you using the live version that could be found [here](https://nurrl.github.io/Duckuino/) ?
- [ ] Yes, absolutely
- [ ] No, I might try it out
<!--
To select an option, put a 'x' in the [ ], like so:
- [x]
If you are not using the live version, please try it out before
posting an issue because it might be already fixed.
-->

What type of issue is it ?
- [ ] Graphical issue (UX, UI, Graphical Glitch)
- [ ] Feature issue (Command not/bad implemented, Non functionnal feature)
- [ ] Crash (The buttons clicks does nothing at all, Error in console)
- [ ] Question (Any type about the project :D)
<!--
You can ask any question about the project.
If that's about a Crash/Feature issue, please paste any relevant output
in the following block of code :
|
\/
-->
```
Here are relevant errors/infos outputed by the code !
```

_Describe your problem here :D_
120 changes: 62 additions & 58 deletions Duckuino.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
/* Function to request files */
function getFile(sUrl) {
/* Init request */
var oReq = new XMLHttpRequest();
let oReq = new XMLHttpRequest();
//console.log("@<- " + sUrl);

/* Sending request */
oReq.open("get", sUrl, false);
Expand All @@ -24,41 +25,44 @@ function getFile(sUrl) {
}
}

class Duckuino {
constructor() {}

listModules() {
/* List all modules in the moduleList file */
if (!this.moduleArray) {
this.moduleArray = getFile("modules/modules").split('\n');
this.moduleArray.pop();
}

/* Return the list */
return this.moduleArray;
}

loadModule(moduleName) {
/* Check if module exists */
if (this.listModules().indexOf(moduleName) == -1) {
console.error("Error: This module doesn't exist !");

/* Module is not loaded */
this.loadedModule = undefined;
} else {
/* Load module *//* jshint evil:true */
this.loadedModule = eval(getFile("modules/" + moduleName + ".js"));
class Modules {
constructor() {
/* Load modules *//* jshint evil:true */
let modules = JSON.parse(getFile("modules/modules.json"));
for (let x in modules) {
let m = modules[x];
m.meta = JSON.parse(getFile("modules/" + m.path + m.meta));
m.module = eval(getFile("modules/" + m.path + m.module));
if (Object.keys(m.meta.locales).length > 0) {
let ls = m.meta.locales;
for (let y in ls) {
let l = ls[y];
if (y == "_meta")
continue;
l.data = getFile("modules/" + m.path + l.path);
}
ls._meta.header = getFile("modules/" + m.path + ls._meta.header);
for (let y in ls._meta.parts) {
let f = ls._meta.parts[y];
if (f == "_locale_")
continue;
ls._meta.parts[y] = getFile("modules/" + m.path + f);
}
}
}
this.list = modules;
}
}

/* TO-DO: getModuleInfos() {} */
class Duckuino {
constructor() {}

compileCode(compileStr) {
compileCode(compileStr, withModule) {
/* Init timer */
var timerStart = window.performance.now();
let timerStart = window.performance.now();

/* Check if module loaded */
if (this.loadedModule === undefined) {
if (withModule === undefined) {
return {
compiledCode: undefined,
compileTime: -1,
Expand Down Expand Up @@ -92,32 +96,32 @@ class Duckuino {
this.dataStorage = new Object();
this.compiledCode = '';

var commandKnown;
var lineStr;
var lastLine = ''; var lastLineCount = 0;
let commandKnown;
let lineStr;
let lastLine = ''; let lastLineCount = 0;

/* Cut the input in lines */
var lineArray = compileStr.split('\n');
let lineArray = compileStr.split('\n');

/* Loop every line */
for (var i = 0; i < lineArray.length; i++)
for (let i = 0; i < lineArray.length; i++)
{
/* Line empty, skip */
if (lineArray[i] === '' || lineArray[i] === '\n')
continue;

/* Reset vars */
/* Reset lets */
commandKnown = false;
lineStr = '';

/* Split lines in words */
var argList = lineArray[i].split(' ');
var argOne = argList[0];
let argList = lineArray[i].split(' ');
let argOne = argList[0];

/* Parse commands */
if (this.loadedModule.functionMap[argOne] !== undefined) {
var µ = new Object({
keyMap: this.loadedModule.keyMap,
if (withModule.functionMap[argOne] !== undefined) {
let µ = new Object({
keyMap: withModule.keyMap,
/**
* Pushes the error to the global error list.
*/
Expand All @@ -136,10 +140,10 @@ class Duckuino {
*/
trimLast: function(thisPtr, lastLine, lastLineCount) {
return function() {
var tmpVar = thisPtr.compiledCode.split('\n');
let tmplet = thisPtr.compiledCode.split('\n');

tmpVar.splice(-lastLineCount, lastLineCount - 1);
thisPtr.compiledCode = tmpVar.join('\n');
tmplet.splice(-lastLineCount, lastLineCount - 1);
thisPtr.compiledCode = tmplet.join('\n');

return lastLine;
};
Expand All @@ -161,24 +165,24 @@ class Duckuino {
});

/* Execute the function and add the returned string to the current string */
lineStr += this.loadedModule.functionMap[argOne](argList, µ);
lineStr += withModule.functionMap[argOne](argList, µ);

/* Post process the line */
lineStr = this.loadedModule.postLine(lineStr, µ);
lineStr = withModule.postLine(lineStr, µ);
} else { /* Parse keystokes */
var strokeArray = Array();
let strokeArray = Array();

for(var y = 0; y < argList.length; y++) {
for(let y = 0; y < argList.length; y++) {

if(this.loadedModule.commandMap[argList[y]] !== undefined) {
if(withModule.commandMap[argList[y]] !== undefined) {
/* Push key to Array */
strokeArray.push(this.loadedModule.commandMap[argList[y]]);
} else if(this.loadedModule.comboMap[argList[y]] !== undefined) {
strokeArray.push(withModule.commandMap[argList[y]]);
} else if(withModule.comboMap[argList[y]] !== undefined) {
/* Push key to Array */
strokeArray.push(this.loadedModule.comboMap[argList[y]]);
} else if(this.loadedModule.keyMap[argList[y]] !== undefined && y != 0) {
strokeArray.push(withModule.comboMap[argList[y]]);
} else if(withModule.keyMap[argList[y]] !== undefined && y != 0) {
/* Push key to Array */
strokeArray.push('"' + this.loadedModule.keyMap[argList[y]] + '"');
strokeArray.push(withModule.keyMap[argList[y]]);
} else {
/* If command unknown, throw error */
this.errorList.push({
Expand All @@ -189,7 +193,7 @@ class Duckuino {
}

/* Transform key array to string */
lineStr += this.loadedModule.computeKeys(strokeArray);
lineStr += withModule.computeKeys(strokeArray);
}

/* Calculate line count */
Expand All @@ -201,8 +205,8 @@ class Duckuino {
}

/* Stop timer */
var timerEnd = window.performance.now();
var timeElapsed = (timerEnd - timerStart).toFixed(2);
let timerEnd = window.performance.now();
let timeElapsed = (timerEnd - timerStart).toFixed(2);

/* Return error if error and code if not */
if (this.errorList.length > 0) {
Expand All @@ -213,7 +217,7 @@ class Duckuino {

returnCode: 1,
returnMessage: function(errorList) {
var errorString;
let errorString;

if(errorList.length > 1) {
errorString = "The compiler returned some errors:\n";
Expand All @@ -232,7 +236,7 @@ class Duckuino {
} else {
/* Return the compiled code */
return {
compiledCode: this.loadedModule.getFinalCode(this.compiledCode),
compiledCode: withModule.getFinalCode(this.compiledCode),
compileTime: timeElapsed,

returnCode: 0,
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ https://nurrl.github.io/Duckuino/
## Why Duckuino ?
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 :
```javascript
/* Need to fill */
```
Output:
let Duck = new Duckuino();
let mods = new Modules().list;

```c
/* Need to fill */
let output = Duck.compileCode("STRING This is a test string !", mods[0].module);
/* ^- Here will be the final compiled code |
** and errors if applicable. |
** Here is the selected module -/
**
** Note: You can iterate through the list and find the desired one,
** by default, `0` will be the first module.
*/
```
# Members
- [Plazmaz](https://github.com/Plazmaz)
Expand Down
43 changes: 22 additions & 21 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,15 @@ html, body {
font-family: Lato, sans-serif;
font-size: 16px;

/* Disable Scroll */
overflow: hidden;

/* Size */
height: 100%; width: 100%;
}

/* Background blured image */
body::before {
/* Position */
position: absolute;
top: 0; left: 0;

/* Size */
height: 100%; width: 100%;

/* Background */
background-size: cover;
background-image: url(../imgs/background.jpg);
background-repeat: no-repeat;
background-position: center;
background-attachment: fixed;

/* Misc */
/*filter: blur(1px);*/
content: "";
z-index: -1;
/* Size */
height: 100%; width: 100%;
}

/* Text */
Expand All @@ -53,6 +36,8 @@ textarea {
border: none; border-radius: 4px;
padding: 8px;

word-wrap: break-word;
word-break: break-all;
box-sizing: border-box;
resize: none;
}
Expand Down Expand Up @@ -126,6 +111,7 @@ button:disabled {

/* Center parts */
display: flex;
flex-wrap: wrap;
}

.part {
Expand All @@ -139,12 +125,22 @@ button:disabled {
border-radius: 4px;

/* Separation */
/*box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);*/
/*box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);*/

/* Text */
color: white;
}

@media (max-width: 860px) {
.part {
width: 100%;
}

.input {
margin-top: 28px;
}
}

/* Elements */
.process {
/* Center text */
Expand All @@ -157,6 +153,7 @@ button:disabled {
width: 100%;

display: none;
z-index: 2;
}
.tooltip > span {
/* Size */
Expand Down Expand Up @@ -213,6 +210,10 @@ button:disabled {
width: 16px;
height: 32px;
}
.combined-but > select option {
/* Style */
color: black;
}
.combined-but > select:disabled {
/* Postion */
opacity: .5;
Expand Down
Loading

0 comments on commit 4447f75

Please sign in to comment.