From bf4ff3ba36547a3c57890dca8fa9aab5ae30e3dc Mon Sep 17 00:00:00 2001 From: Jacob Medina Date: Tue, 5 Sep 2023 18:55:48 -0400 Subject: [PATCH] extra race options --- public/assets/modules/options.js | 30 +++++++++++++++++++++++++++++- public/assets/modules/race.js | 8 +++++--- public/index.html | 31 +++++++++++++++++++++++-------- public/main.js | 11 +++++++---- 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/public/assets/modules/options.js b/public/assets/modules/options.js index a997024..1dd401d 100644 --- a/public/assets/modules/options.js +++ b/public/assets/modules/options.js @@ -8,6 +8,7 @@ const defaultDiffMultiplier = 1.0; let boardSize = defaultBoardSize; let diffMultiplier = defaultDiffMultiplier; +let excludeItems = []; function handleRandomSeedBtn(reload=true) { @@ -92,6 +93,33 @@ function setDifficultyValue(val) { $('.difficulty').text(diffMultiplier); } +function getExcludeArray(searchParams, spaces=false) { + const exclude = searchParams.get("exclude"); + let excludeTypes = []; + if (exclude) { + excludeTypes = exclude.split(','); + if (spaces) excludeTypes = excludeTypes.map(item => item.split('-').join(' ')); + } + return excludeTypes; +} + + +function setExclude(items) { + excludeItems = items; + const excludeUl = $('.exclude-items'); + excludeUl.text(''); + + if (items.length === 0) { + $('.exclude-items-container').text('Include all challenge types'); + return; + } + + items.forEach(item => { + item = titleCase(item); + excludeUl.append(`
  • ${item}
  • `); + }); +} + function generateChallengeOptions() { const params = new URLSearchParams(new URL(location.href).search); @@ -115,4 +143,4 @@ function generateChallengeOptions() { optionsContainer.append(html); } -export { boardSize, diffMultiplier, defaultBoardSize, defaultDiffMultiplier, newBoard, handleRandomSeedBtn, handleOptionsFormSubmit, resetOptions, setBoardSize, setDifficulty, setBoardSizeValue, setDifficultyValue, generateChallengeOptions }; \ No newline at end of file +export { boardSize, diffMultiplier, getExcludeArray, defaultBoardSize, defaultDiffMultiplier, newBoard, handleRandomSeedBtn, handleOptionsFormSubmit, resetOptions, setBoardSize, setDifficulty, setBoardSizeValue, setDifficultyValue, setExclude, generateChallengeOptions }; \ No newline at end of file diff --git a/public/assets/modules/race.js b/public/assets/modules/race.js index 3b152bb..381c276 100644 --- a/public/assets/modules/race.js +++ b/public/assets/modules/race.js @@ -9,7 +9,7 @@ let room = null; function onConnect(socket) { socket.on('connect', () => { - console.log(`You connected with ID: ${socket.id}`); + // console.log(`You connected with ID: ${socket.id}`); socket.on('client-joined-room', clientNum => { // $('.ready-btn').prop('disabled', false); @@ -91,7 +91,9 @@ function createRoom(event, socket, urlSearchParams) { } -function joinRoom(socket, urlSearchParams) { +function joinRoom(event, socket, urlSearchParams) { + event.preventDefault(); + const roomName = $('#join-room-name').val(); socket.emit('join-room', roomName); @@ -112,7 +114,7 @@ function joinRoom(socket, urlSearchParams) { generatePlayerMenu(clients) ); - console.log(res.message); + // console.log(res.message); urlSearchParams = new URLSearchParams(res.params); const seed = urlSearchParams.get("seed"); diff --git a/public/index.html b/public/index.html index 5e0c25b..2a7349c 100644 --- a/public/index.html +++ b/public/index.html @@ -157,8 +157,8 @@

    Race

    -
    -

    Create a room:

    +
    Create a Room
    +
    Room name taken! + +
    + +

    Board parameters:

    +
      +
    • Board Size: 5x5
    • +
    • Difficulty: 1.0
    • +
    • + Exclude... +
        +
      • Main Quests
      • +
      • Korok Seeds
      • +
      +
    • +
    -
    -
    -
    -

    Join a room:

    +
    Join a Room
    +
    -
    Room name does not exist! -
    +
    @@ -204,6 +217,8 @@

    done +

    Wait for others to be ready.

    +