Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions documentation/codeSnippets/controller/basicjoycon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ function update(parent) {
if (!!gamepads[0] && gamepads[0].totalJoysticks > 0) {
//This gets the 1st joystick position on the first controller.
let joycon = gamepads[0].getJoystickPosition(0);

// The values can go from -1 to 1 for both the x and the y
parent.x += joycon.x * 10;
parent.y += joycon.y * 10;
parent.incrementX(joycon.x);
parent.incrementY(joycon.y);
}
}
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ <h1 class="orangeText" id="welcomeTitle">
href="./documentation/index.html"
class="orangeText"
id="welcomeDocsButton"
target="_blank"
>Looking for the docs? Click Here</a
>
</div>
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import {
} from "./scripts/toolbox.js";
import {} from "./scripts/flatted.min.js";
import { compileCurrentProject } from "./scripts/Compiler/compilerManager.js";
import { loadProject } from "./scripts/SaveProject/saveManager.js";
import {
initSaveManager,
loadProject,
} from "./scripts/SaveProject/saveManager.js";

game.start();

Expand All @@ -35,6 +38,7 @@ initRightClickMenuManager();
initCanvasSizer();
initAssetManager();
setupSaveButtonHandlers();
initSaveManager();

document.getElementById("AddObject").addEventListener("click", () => {
addEmptyObject(selectedObject);
Expand Down
9 changes: 9 additions & 0 deletions scripts/AssetPanel/fileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ addDirectory("/scripts");

document.getElementById("createNewFile").addEventListener("click", () => {
let name = prompt("Please name your script. Dont use any special characters");
if (!name) return;
//Dont allow fancy characters in the name
if (name.match(/[^a-zA-Z0-9_-]/g)) {
addInfoPopup("Error", "Dont use any special characters", popupTypes.ERROR);
Expand Down Expand Up @@ -95,6 +96,14 @@ export function addDirectory(fullDir) {
if (fullDir != "") directories.get(parentDir).addChildDirectory(fullDir);
directories.set(fullDir, dir);
}

function postHTTPSrequest(url, data) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.send(JSON.stringify(data));
}

/**
* @description - Reload the currend directory to show any new files/folders
*/
Expand Down
5 changes: 5 additions & 0 deletions scripts/Compiler/Dependencies/baseDep.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let updaters = [];

class File {
/**
*
Expand Down Expand Up @@ -68,6 +70,9 @@ function loop() {
lastRender = Date.now();
frame++;

updaters.forEach((updater) => {
updater();
});
//LOOP HERE
}

Expand Down
2 changes: 2 additions & 0 deletions scripts/Compiler/Dependencies/depList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ scripts/Objects/Components/textComponent.js
scripts/Objects/Components/imageComponent.js
//needed
scripts/Objects/ObjectManager.js
//extra
scripts/Compiler/Dependencies/gamepad.js
142 changes: 142 additions & 0 deletions scripts/Compiler/Dependencies/gamepad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//

/**
* @addToUpdate - updateGameController();
*/

updaters.push(() => {
updateGameController();
});

class GamePad {
gamepad;
id;
controllerButtonMap = new Map();
controllerJoysticks = new Map();
totalButtons;
totalJoysticks;
mapping;
setGamePad(gp) {
this.gamepad = gp;
this.totalButtons = gp.buttons.length;
this.totalJoysticks = gp.axes.length / 2;
this.mapping = gp.mapping;
//console.log(this.totalJoysticks);
}

getButton(id) {
try {
return !this.controllerButtonMap.get(id)
? 0
: this.controllerButtonMap.get(id);
} catch (error) {
console.error(error);
return 0;
}
}

getID() {
return this.id;
}

vibrate(intesity, duration) {
//Intensity 0 - 1
//Duration in ms
try {
this.gamepad.vibrationActuator.playEffect(
this.gamepad.vibrationActuator.type,
{
startDelay: 0,
duration: duration,
weakMagnitude: intesity,
strongMagnitude: intesity,
}
);
return true;
} catch (error) {
console.error(error);
return false;
}
}

getJoystickPosition(id) {
try {
return {
x: !this.controllerJoysticks.get(id * 2)
? 0
: this.controllerJoysticks.get(id * 2),
y: !this.controllerJoysticks.get(id * 2 + 1)
? 0
: this.controllerJoysticks.get(id * 2 + 1),
};
} catch (error) {
return {
x: 0,
y: 0,
};
}
}
}

function supportsGamepads() {
return !!navigator.getGamepads;
}

let driftGuard = 0.2;
function setDriftGuardBounds(d) {
driftGuard = d;
}

let _gamepads = navigator.getGamepads();
let controllerButtonMap = new Map();
let controllerJoysticks = new Map();

let gamepads = [];
let totalGamepads;

function updateGameController() {
_gamepads = navigator.getGamepads();

/*for(let i = 0; i < _gamepads.length; i++){
gamepads = [];
gamepads.push(new GamePad());
}*/
totalGamepads = 0;
for (let i = 0; i < _gamepads.length; i++) {
if (_gamepads[i] != null) totalGamepads++;
}

if (totalGamepads != gamepads.length) {
if (totalGamepads < gamepads.length) gamepads.pop();
else gamepads.push(new GamePad());
}

// For each controller, show all the button and axis information
for (let i = 0; i < totalGamepads; i++) {
let gp = _gamepads[i];
gamepads[i].setGamePad(gp);
gamepads[i].id = gp.id;
if (!gp || !gp.connected) {
continue;
}
for (let j = 0; j < gp.buttons.length; j++) {
gamepads[i].controllerButtonMap.set(j, gp.buttons[j].value);
}

let axesBoxCount = ((gp.axes.length + 1) / 2) | 0; // Round up (e.g. 3 axes is 2 boxes)
for (let j = 0; j < axesBoxCount; j++) {
let xAxis = gp.axes[j * 2];
gamepads[i].controllerJoysticks.set(
j * 2,
Math.abs(xAxis) > driftGuard ? xAxis : 0
);
if (!(j == axesBoxCount - 1 && gp.axes.length % 2 == 1)) {
let yAxis = gp.axes[j * 2 + 1];
gamepads[i].controllerJoysticks.set(
j * 2 + 1,
Math.abs(yAxis) > driftGuard ? yAxis : 0
);
}
}
}
}
26 changes: 21 additions & 5 deletions scripts/Compiler/compilerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,40 @@ export async function compileCurrentProject() {

//add all the dependencies to the compiled code
let dependenciesCode = ``;
let addToUpdateQueue = ``;
for (let dep of dependencies) {
let depCode = await readTextFile(`./${dep}`);

//read the top of the file to see if it has a comment
let top = depCode.split("\n")[0];
let comment = top.includes("/**");
if (comment) {
//TODO add a more permanent solution for this
//get the second line
let updateDep = depCode.split("\n")[1].split("- ")[1];
addToUpdateQueue += updateDep;
}

dependenciesCode += `\n${replaceRenderCode(
removeImports(
removeFunctionsWithIgnoreComment(await readTextFile(`./${dep}`))
).replace(/export /g, "")
removeImports(removeFunctionsWithIgnoreComment(depCode)).replace(
/export /g,
""
)
)}`;
}

baseCodeLib = baseCodeLib.replace("//DEPENDENCIES HERE", dependenciesCode);
console.log(dependencies);

baseCodeLib = baseCodeLib.replace("//INITIALIZATION HERE", compiledCode);
//baseCode = baseCode.replace("//LOOP HERE", "loop();");

//baseCodeLib = baseCodeLib.replace("//LOOP HERE", addToUpdateQueue);

let templateHTMLFile = await readTextFile(
"./scripts/Compiler/Dependencies/baseDep.html"
);

templateHTMLFile = templateHTMLFile.replace("//CODE HERE", baseCodeLib);
//baseCode = baseCode.replace("//LOOP HERE", "loop();");

//add credit comment
templateHTMLFile += `\n<!-- Created with the Aether Engine -->`;
Expand Down
3 changes: 2 additions & 1 deletion scripts/SaveProject/loadProjectUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export function createUI() {

loadSave.addEventListener("click", (e) => {
loadProject(
Flatted.parse(localStorage.getItem(e.target.getAttribute("loadName")))
Flatted.parse(localStorage.getItem(e.target.getAttribute("loadName"))),
{ name: saveName }
);
document.body.removeChild(ui);
});
Expand Down
25 changes: 21 additions & 4 deletions scripts/SaveProject/saveManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@ import { download } from "../toolbox.js";
import { createUI } from "./loadProjectUI.js";

let saveName = "";
export function saveProject(overideName, downloadFile = false) {
initSaveManager();
export function initSaveManager() {
//when cntrl + s is pressed
document.addEventListener("keydown", (e) => {
e.preventDefault();
if (e.ctrlKey && e.key == "s") {
if (saveName == "") {
saveProject();
} else {
saveProject(saveName);
}
}
});
}

export function saveProject(overideName, options = { downloadFile: false }) {
//return;
//If its already been saved, use that name
if (overideName == undefined && saveName == "")
Expand All @@ -38,7 +53,7 @@ export function saveProject(overideName, downloadFile = false) {
});
console.log(str);

if (downloadFile) {
if (options.downloadFile) {
download(str, `${name}.aether`, "AEFile");
}
//Get access to storage
Expand Down Expand Up @@ -70,7 +85,9 @@ export function saveProject(overideName, downloadFile = false) {
});
}

export async function loadProject(data = undefined) {
export async function loadProject(data = undefined, options) {
if (options == undefined) options = {};
if (options.name != undefined) saveName = options.name;
if (data == undefined) {
createUI();
return;
Expand All @@ -81,7 +98,7 @@ export async function loadProject(data = undefined) {
let directorys = data.directorys.sort(function (a, b) {
return (a.match(/\//g) || []).length - (b.match(/\//g) || []).length;
});
console.log(directorys);

for await (const directory of directorys) {
addDirectory(directory);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/SaveProject/saveProjectButtonManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function setupSaveButtonHandlers() {

downloadButtons.forEach((e) => {
e.addEventListener("click", (evnt) => {
saveProject("project", true);
saveProject("project", { downloadFile: true });
});
});

Expand Down
1 change: 0 additions & 1 deletion scripts/Tabs/tabCode/gameVisualEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ let cornerTopLeftDragHandle = new DragRect("red", (x, y, parent) => {
//parent.x = 0;
//parent.y = 0;
});

export let gameVisualEditor = {
init: () => {},
loop: (tick) => {
Expand Down
13 changes: 3 additions & 10 deletions scripts/Tabs/tabCode/jsCodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { openTabMetadata } from "../tabManager.js";

let change = false;
let saveFile = false;

export let jsCodeEditor = {
init: () => {
document
Expand All @@ -13,12 +14,6 @@ export let jsCodeEditor = {
//console.log(cMirror.getValue());
change = true;
});
document.addEventListener("keydown", (e) => {
if (e.ctrlKey && e.key == "s") {
e.preventDefault();
saveFile = true;
}
});

document.getElementById("addComponent").addEventListener("click", () => {
if (selectedObject == undefined)
Expand All @@ -32,17 +27,15 @@ export let jsCodeEditor = {
},
loop: (tick, extraData, tab) => {
if (change) {
tab.showDot();
change = false;
}
if (saveFile) {
//Put the data into the tab element
tab.setPartOfData("data", getCode());

//Save it to the file
setFileData(extraData.dir, getCode());
tab.hideDot();
saveFile = false;
//tab.showDot();
change = false;
}
},
onChange: (tabId, tabName, extraData) => {
Expand Down
Loading