Better map selection. Prepare for prefabs
This commit is contained in:
parent
56417cf9b4
commit
1474324a1e
|
@ -28,14 +28,15 @@
|
|||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<div class="mx-auto" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav">
|
||||
<span class="navbar-text mr-2">Generator</span>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
|
||||
aria-haspopup="true" aria-expanded="false">
|
||||
Select generator
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<button class="btn btn-secondary dropdown-toggle mr-2" type="button" id="generatorDropdown"
|
||||
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Random
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="generatorDropdown">
|
||||
<a class="dropdown-item" id="cellular-automata-option">Cellular Automata</a>
|
||||
<a class="dropdown-item" id="simple-rooms-option">Simple Rooms</a>
|
||||
<a class="dropdown-item" id="bsp-rooms-option">BSP Rooms</a>
|
||||
|
@ -43,10 +44,12 @@
|
|||
<a class="dropdown-item" id="drunkard-option">Drunkard Walk</a>
|
||||
<a class="dropdown-item" id="maze-option">Maze</a>
|
||||
<a class="dropdown-item" id="voronoi-option">Voronoi Hive</a>
|
||||
<a class="dropdown-item" id="random-option">Random Generator</a>
|
||||
<a class="dropdown-item" id="random-option">Random</a>
|
||||
</div>
|
||||
</li>
|
||||
<input class="form-control mr-sm-2" id="seed" type="search" placeholder="Seed" aria-label="Seed">
|
||||
<span class="navbar-text mr-2">Seed</span>
|
||||
<input class="form-control mr-sm-2 w-25" id="seed" type="search" placeholder="random" aria-label="Seed">
|
||||
<button class="btn btn-outline-success my-2 my-sm-0" type="submit" id="refresh">Refresh</button>
|
||||
</ul>
|
||||
</div>
|
||||
<a class="github-button" href="https://github.com/klangner/mapgen.rs" data-icon="octicon-star"
|
||||
|
|
|
@ -30,55 +30,53 @@ function get_seed() {
|
|||
return Date.now();
|
||||
}
|
||||
|
||||
|
||||
function setGenerator(e) {
|
||||
document.getElementById("generatorDropdown").innerHTML = e.target.innerText;
|
||||
}
|
||||
|
||||
// Map generators
|
||||
function newCellularAutomata() {
|
||||
world = World.new_cellular_automata(GRID_COLS, GRID_ROWS, get_seed());
|
||||
function refreshMap() {
|
||||
var generator_name = document.getElementById("generatorDropdown").innerHTML;
|
||||
|
||||
switch(generator_name){
|
||||
case "Cellular Automata":
|
||||
world = World.new_cellular_automata(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "Simple Rooms":
|
||||
world = World.new_simple_rooms(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "BSP Rooms":
|
||||
world = World.new_bsp_rooms(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "BSP Interior":
|
||||
world = World.new_bsp_interior(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "Drunkard Walk":
|
||||
world = World.new_drunkard(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "Maze":
|
||||
world = World.new_maze(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
case "Voronoi Hive":
|
||||
world = World.new_voronoi(GRID_COLS, GRID_ROWS, get_seed());
|
||||
break;
|
||||
|
||||
default:
|
||||
world = World.new_random(GRID_COLS, GRID_ROWS, get_seed());
|
||||
}
|
||||
|
||||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
function newSimpleRooms() {
|
||||
var seed = Date.now();
|
||||
world = World.new_simple_rooms(GRID_COLS, GRID_ROWS, get_seed());
|
||||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
function newBspInterior() {
|
||||
var seed = Date.now();
|
||||
world = World.new_bsp_interior(GRID_COLS, GRID_ROWS, get_seed());
|
||||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
function newDrunkard() {
|
||||
var seed = Date.now();
|
||||
world = World.new_drunkard(GRID_COLS, GRID_ROWS, get_seed());
|
||||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
function newBspRooms() {
|
||||
var seed = Date.now();
|
||||
world = World.new_bsp_rooms(GRID_COLS, GRID_ROWS, get_seed());
|
||||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
function newMaze() {
|
||||
var seed = Date.now();
|
||||
world = World.new_maze(GRID_COLS, GRID_ROWS, get_seed());
|
||||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
function newVoronoi() {
|
||||
var seed = Date.now();
|
||||
world = World.new_voronoi(GRID_COLS, GRID_ROWS, get_seed());
|
||||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
function newRandomGen() {
|
||||
var seed = Date.now();
|
||||
world = World.new_random(GRID_COLS, GRID_ROWS, get_seed());
|
||||
requestAnimationFrame(renderLoop);
|
||||
}
|
||||
|
||||
const renderLoop = () => {
|
||||
// Main loop
|
||||
function renderLoop() {
|
||||
// universe.tick();
|
||||
drawCells();
|
||||
requestAnimationFrame(renderLoop);
|
||||
|
@ -160,14 +158,16 @@ const drawCells = () => {
|
|||
draw_tile(ctx, exit.row(), exit.col(), "exit");
|
||||
};
|
||||
|
||||
newRandomGen();
|
||||
|
||||
// Connect UI element
|
||||
document.getElementById('cellular-automata-option').addEventListener('click', newCellularAutomata);
|
||||
document.getElementById('simple-rooms-option').addEventListener('click', newSimpleRooms);
|
||||
document.getElementById('bsp-rooms-option').addEventListener('click', newBspRooms);
|
||||
document.getElementById('drunkard-option').addEventListener('click', newDrunkard);
|
||||
document.getElementById('bsp-interior-option').addEventListener('click', newBspInterior);
|
||||
document.getElementById('maze-option').addEventListener('click', newMaze);
|
||||
document.getElementById('voronoi-option').addEventListener('click', newVoronoi);
|
||||
document.getElementById('random-option').addEventListener('click', newRandomGen);
|
||||
document.getElementById('cellular-automata-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('simple-rooms-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('bsp-rooms-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('drunkard-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('bsp-interior-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('maze-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('voronoi-option').addEventListener('click', setGenerator);
|
||||
document.getElementById('random-option').addEventListener('click', setGenerator);
|
||||
|
||||
document.getElementById('refresh').addEventListener('click', refreshMap);
|
||||
|
||||
refreshMap();
|
Loading…
Reference in New Issue
Block a user