-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
411 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,11 @@ | ||
import { capitalize } from "lodash-es"; | ||
import { WEAPON_TYPES, WeaponType } from "../common/types/weapon"; | ||
import { | ||
availableInputHandlers, | ||
InputHandlerId, | ||
} from "./input/input-handler-catalog"; | ||
import { joinRoom } from "./socket-io"; | ||
import "./styles/index.scss"; | ||
import { runStateMachine } from "./ui-manager/ui-manager"; | ||
import { FormUiState } from "./ui-manager/ui-state.form"; | ||
|
||
function main() { | ||
// Get controls | ||
const usernameInput = document.getElementById("username") as HTMLInputElement; | ||
const inputModeInput = document.getElementById( | ||
"input-mode", | ||
) as HTMLSelectElement; | ||
const weaponInput = document.getElementById("weapon") as HTMLSelectElement; | ||
const botsInput = document.getElementById("bots") as HTMLInputElement; | ||
const debugModeInput = document.getElementById( | ||
"debug-mode", | ||
) as HTMLInputElement; | ||
|
||
// Initialize controls | ||
inputModeInput.innerHTML = ""; | ||
for (const inputHandler of availableInputHandlers) { | ||
const option = document.createElement("option"); | ||
option.value = inputHandler.id; | ||
option.text = inputHandler.getName(); | ||
inputModeInput.add(option); | ||
} | ||
weaponInput.innerHTML = ""; | ||
for (const weaponType of WEAPON_TYPES) { | ||
const option = document.createElement("option"); | ||
option.value = weaponType; | ||
option.text = capitalize(weaponType); | ||
weaponInput.add(option); | ||
} | ||
|
||
// On start | ||
document | ||
.getElementById("room-selection-form-submit") | ||
?.addEventListener("click", (event) => { | ||
event.preventDefault(); | ||
|
||
const username = usernameInput.value; | ||
const inputHandlerId = inputModeInput.value as InputHandlerId; | ||
const weapon = weaponInput.value as WeaponType; | ||
const bots = botsInput.checked; | ||
const debugMode = debugModeInput.checked; | ||
|
||
joinRoom(username, inputHandlerId, weapon, bots, debugMode); | ||
}); | ||
runStateMachine(new FormUiState()).catch((error: unknown) => { | ||
console.error("Error running UI state machine", error); | ||
}); | ||
} | ||
|
||
window.addEventListener("DOMContentLoaded", main); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#room-selection-form { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 16px; | ||
height: fit-content; | ||
|
||
padding: 40px; | ||
border: 1px solid #225c09; | ||
border-radius: 5px; | ||
background-color: #48be11; | ||
box-shadow: 0 0 10px rgba(77, 117, 39, 0.1); | ||
|
||
& > h1 { | ||
margin: 0; | ||
margin-bottom: 16px; | ||
} | ||
|
||
& > .form-fields { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 8px; | ||
|
||
& > span { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
gap: 8px; | ||
} | ||
|
||
& > .submit { | ||
justify-content: center; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { UiState } from "./ui-state"; | ||
|
||
/** | ||
* Entry point of the UI state machine. | ||
* | ||
* This function will run the UI, which works as a simple state machine, | ||
* going from one state to another, where each state represents a different screen of the UI. | ||
*/ | ||
export async function runStateMachine(initialState: UiState) { | ||
let currentState = initialState; | ||
|
||
// Infinite loop with a safe limit of iterations | ||
for (let i = 0; i < 1_000_000; i++) { | ||
const newState = await currentState.enter(); | ||
|
||
if (newState !== currentState) { | ||
await currentState.exit(); | ||
} | ||
|
||
currentState = newState; | ||
} | ||
|
||
console.error("UI state machine exceeded maximum number of iterations"); | ||
} |
Oops, something went wrong.