Skip to content

Commit

Permalink
Custom map!
Browse files Browse the repository at this point in the history
  • Loading branch information
Yareaj committed May 29, 2023
1 parent 24eb9ed commit edbe96f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 1 addition & 2 deletions custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ function setup() {
textArea.style('width', `${width-50}px`);
textArea.style('height', `${height/3}px`);
textArea.style('resize', 'none');
textArea.attribute('placeholder', 'Insert the menu data');
textArea.attribute('placeholder', 'Insert the custom level data');
textArea.attribute('required', true);
textArea.position(30, height/1.97);

// Position the submit button on the screen
submitButton.position(width/2.4, (height/1.95)+(height/3)+20);

submitButton.mousePressed(obtainLevelData);
}

Expand Down
8 changes: 7 additions & 1 deletion functions/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ function toCustom() {
}

function obtainLevelData() {
console.log(textArea.value());
customLevelString = textArea.value();

if (!customLevelString) {
return alert('Please insert level data');
}
localStorage.setItem("mapId", customLevelString);
initiateLevelPlay();
}
11 changes: 9 additions & 2 deletions functions/levelHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ function preload() {
loadFont('./assets/fonts/Fredoka-Medium.ttf');
loadFont('./assets/fonts/Fredoka-Regular.ttf');

// Import the map string into the global variable
mapOutline = loadStrings(`./assets/levels/level${levelId}.txt`);
const referrer = document.referrer.split('/')
const lastReference = referrer[referrer.length-1];

// Import the map string into the global variable
if (lastReference == 'custom.html') {
mapOutline = localStorage.getItem("mapId").split('\n');
} else {
mapOutline = loadStrings(`./assets/levels/level${levelId}.txt`);
}

// Load the buttonStyles JSON file
buttonStyles = loadJSON('./assets/json/levelButtonStyles.json');
}
Expand Down

0 comments on commit edbe96f

Please sign in to comment.