diff --git a/demo/README.md b/demo/README.md index 4f879dd..403239d 100644 --- a/demo/README.md +++ b/demo/README.md @@ -11,7 +11,7 @@ npm run server Deply application ``` cd www -npm run deploy +npm run build ``` This app uses: diff --git a/docs/0.bootstrap.js b/docs/0.bootstrap.js index b03e627..87ae1e5 100644 --- a/docs/0.bootstrap.js +++ b/docs/0.bootstrap.js @@ -43,7 +43,7 @@ eval("\"use strict\";\n// Instantiate WebAssembly module\nvar wasmExports = __we /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var mapgen_demo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! mapgen-demo */ \"../pkg/mapgen_demo.js\");\n/* harmony import */ var mapgen_demo_mapgen_demo_bg__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! mapgen-demo/mapgen_demo_bg */ \"../pkg/mapgen_demo_bg.wasm\");\n\n\n\nconst CELL_SIZE = 12;\nconst GRID_COLOR = \"#CCCCCC\";\nconst DEAD_COLOR = \"#FFFFFF\";\nconst ALIVE_COLOR = \"#000000\";\n\nvar world = null;\nconst width = 80;\nconst height = 50;\n\nconst infoDiv = document.getElementById('map-info');\n// Give the canvas room for all of our cells and a 1px border\n// around each of them.\nconst canvas = document.getElementById(\"mapgen-canvas\");\ncanvas.height = (CELL_SIZE + 1) * height + 1;\ncanvas.width = (CELL_SIZE + 1) * width + 1;\n\nconst ctx = canvas.getContext('2d');\n\nfunction get_seed() {\n var seed_text = document.getElementById(\"seed\").value;\n if( seed_text.length > 0) {\n return Number(seed_text);\n } \n return Date.now();\n}\n\n// Map generators\nfunction newCellularAutomata() {\n world = mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"World\"].new_cellular_automata(width, height, get_seed());\n requestAnimationFrame(renderLoop);\n}\n\nfunction newSimpleRooms() {\n var seed = Date.now();\n world = mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"World\"].new_simple_rooms(width, height, get_seed());\n requestAnimationFrame(renderLoop);\n}\n\nfunction newBspInterior() {\n var seed = Date.now();\n world = mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"World\"].new_bsp_interior(width, height, get_seed());\n requestAnimationFrame(renderLoop);\n}\n\nfunction newDrunkard() {\n var seed = Date.now();\n world = mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"World\"].new_drunkard(width, height, get_seed());\n requestAnimationFrame(renderLoop);\n}\n\nfunction newRandomGen() {\n var seed = Date.now();\n world = mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"World\"].new_random(width, height, get_seed());\n requestAnimationFrame(renderLoop);\n}\n\nconst renderLoop = () => {\n // universe.tick();\n\n drawGrid();\n drawCells();\n\n // requestAnimationFrame(renderLoop);\n};\n\nconst drawGrid = () => {\n ctx.beginPath();\n ctx.strokeStyle = GRID_COLOR;\n\n // Vertical lines.\n for (let i = 0; i <= width; i++) {\n ctx.moveTo(i * (CELL_SIZE + 1) + 1, 0);\n ctx.lineTo(i * (CELL_SIZE + 1) + 1, (CELL_SIZE + 1) * height + 1);\n }\n\n // Horizontal lines.\n for (let j = 0; j <= height; j++) {\n ctx.moveTo(0, j * (CELL_SIZE + 1) + 1);\n ctx.lineTo((CELL_SIZE + 1) * width + 1, j * (CELL_SIZE + 1) + 1);\n }\n\n ctx.stroke();\n};\n\nconst getIndex = (row, column) => {\n return row * width + column;\n};\n\nconst drawCells = () => {\n const tilesPtr = world.tiles();\n const tiles = new Uint8Array(mapgen_demo_mapgen_demo_bg__WEBPACK_IMPORTED_MODULE_1__[\"memory\"].buffer, tilesPtr, width * height);\n\n ctx.beginPath();\n\n for (let row = 0; row < height; row++) {\n for (let col = 0; col < width; col++) {\n const idx = getIndex(row, col);\n\n ctx.fillStyle = tiles[idx] == mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"Cell\"].Floor\n ? DEAD_COLOR\n : ALIVE_COLOR;\n\n ctx.fillRect(\n col * (CELL_SIZE + 1) + 1,\n row * (CELL_SIZE + 1) + 1,\n CELL_SIZE,\n CELL_SIZE\n );\n }\n }\n\n ctx.stroke();\n};\n\nnewRandomGen();\n\n// Connect UI element\ndocument.getElementById('cellular-automata-option').addEventListener('click', newCellularAutomata);\ndocument.getElementById('simple-rooms-option').addEventListener('click', newSimpleRooms);\ndocument.getElementById('bsp-interior-option').addEventListener('click', newBspInterior);\ndocument.getElementById('drunkard-option').addEventListener('click', newDrunkard);\ndocument.getElementById('random-option').addEventListener('click', newRandomGen);\n\n\n//# sourceURL=webpack:///./index.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var mapgen_demo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! mapgen-demo */ \"../pkg/mapgen_demo.js\");\n/* harmony import */ var mapgen_demo_mapgen_demo_bg__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! mapgen-demo/mapgen_demo_bg */ \"../pkg/mapgen_demo_bg.wasm\");\n\n\n\nconst CELL_SIZE = 15;\nconst GRID_COLOR = \"#CCCCCC\";\nconst DEAD_COLOR = \"#FFFFFF\";\nconst ALIVE_COLOR = \"#000000\";\n\nvar world = null;\nconst width = 80;\nconst height = 50;\n\nconst infoDiv = document.getElementById('map-info');\n// Give the canvas room for all of our cells and a 1px border\n// around each of them.\nconst canvas = document.getElementById(\"mapgen-canvas\");\ncanvas.height = CELL_SIZE * height;\ncanvas.width = CELL_SIZE * width;\n// Load tiles bitmap\nlet tiles_image = new Image();\ntiles_image.src = '/assets/tiles.png';\n\nconst ctx = canvas.getContext('2d');\n\nfunction get_seed() {\n var seed_text = document.getElementById(\"seed\").value;\n if( seed_text.length > 0) {\n return Number(seed_text);\n } \n return Date.now();\n}\n\n// Map generators\nfunction newCellularAutomata() {\n world = mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"World\"].new_cellular_automata(width, height, get_seed());\n requestAnimationFrame(renderLoop);\n}\n\nfunction newSimpleRooms() {\n var seed = Date.now();\n world = mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"World\"].new_simple_rooms(width, height, get_seed());\n requestAnimationFrame(renderLoop);\n}\n\nfunction newBspInterior() {\n var seed = Date.now();\n world = mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"World\"].new_bsp_interior(width, height, get_seed());\n requestAnimationFrame(renderLoop);\n}\n\nfunction newDrunkard() {\n var seed = Date.now();\n world = mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"World\"].new_drunkard(width, height, get_seed());\n requestAnimationFrame(renderLoop);\n}\n\nfunction newRandomGen() {\n var seed = Date.now();\n world = mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"World\"].new_random(width, height, get_seed());\n requestAnimationFrame(renderLoop);\n}\n\nconst renderLoop = () => {\n // universe.tick();\n\n // drawGrid();\n drawCells();\n\n requestAnimationFrame(renderLoop);\n};\n\nconst drawGrid = () => {\n ctx.beginPath();\n ctx.strokeStyle = GRID_COLOR;\n\n // Vertical lines.\n for (let i = 0; i <= width; i++) {\n ctx.moveTo(i * (CELL_SIZE + 1) + 1, 0);\n ctx.lineTo(i * (CELL_SIZE + 1) + 1, (CELL_SIZE + 1) * height + 1);\n }\n\n // Horizontal lines.\n for (let j = 0; j <= height; j++) {\n ctx.moveTo(0, j * (CELL_SIZE + 1) + 1);\n ctx.lineTo((CELL_SIZE + 1) * width + 1, j * (CELL_SIZE + 1) + 1);\n }\n\n ctx.stroke();\n};\n\nconst getIndex = (row, column) => {\n return row * width + column;\n};\n\nconst is_inner_wall = (tiles, col, row) => {\n\n for (let c = Math.max(col-1, 0); c < Math.min(col+2, width); c++) {\n for (let r = Math.max(row-1, 0); r < Math.min(row+2, height); r++) {\n if ((c != col || r != row) && tiles[getIndex(r, c)] == mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"Cell\"].Floor) {\n return false;\n }\n }\n }\n\n return true;\n}\n\nconst drawCells = () => {\n const tilesPtr = world.tiles();\n const tiles = new Uint8Array(mapgen_demo_mapgen_demo_bg__WEBPACK_IMPORTED_MODULE_1__[\"memory\"].buffer, tilesPtr, width * height);\n const tile_size = 39;\n\n ctx.beginPath();\n\n for (let row = 0; row < height; row++) {\n for (let col = 0; col < width; col++) {\n const idx = getIndex(row, col);\n\n var tile_x = 0;\n var tile_y = 0;\n if (tiles[idx] == mapgen_demo__WEBPACK_IMPORTED_MODULE_0__[\"Cell\"].Floor) {\n tile_x = 3;\n tile_y = 2;\n } else if (is_inner_wall(tiles, col, row)){\n tile_x = 18;\n tile_y = 0;\n } else {\n tile_x = 0;\n tile_y = 3;\n }\n ctx.drawImage(\n tiles_image, \n tile_x * tile_size+3, \n tile_y * tile_size+3, \n tile_size-3, \n tile_size-3, \n col * CELL_SIZE,\n row * CELL_SIZE,\n CELL_SIZE,\n CELL_SIZE);\n }\n }\n\n ctx.stroke();\n};\n\nnewRandomGen();\n\n// Connect UI element\ndocument.getElementById('cellular-automata-option').addEventListener('click', newCellularAutomata);\ndocument.getElementById('simple-rooms-option').addEventListener('click', newSimpleRooms);\ndocument.getElementById('bsp-interior-option').addEventListener('click', newBspInterior);\ndocument.getElementById('drunkard-option').addEventListener('click', newDrunkard);\ndocument.getElementById('random-option').addEventListener('click', newRandomGen);\n\n\n//# sourceURL=webpack:///./index.js?"); /***/ }), diff --git a/docs/44ffe41e5a9c873b1c79.module.wasm b/docs/3450392053799dfed08d.module.wasm similarity index 89% rename from docs/44ffe41e5a9c873b1c79.module.wasm rename to docs/3450392053799dfed08d.module.wasm index 88115cb..b2b83b9 100644 Binary files a/docs/44ffe41e5a9c873b1c79.module.wasm and b/docs/3450392053799dfed08d.module.wasm differ diff --git a/docs/5a858ffd967a1d3be2df.module.wasm b/docs/5a858ffd967a1d3be2df.module.wasm deleted file mode 100644 index b4c24e0..0000000 Binary files a/docs/5a858ffd967a1d3be2df.module.wasm and /dev/null differ diff --git a/docs/bbf7fe2631d06e11148e.module.wasm b/docs/bbf7fe2631d06e11148e.module.wasm deleted file mode 100644 index 9582c05..0000000 Binary files a/docs/bbf7fe2631d06e11148e.module.wasm and /dev/null differ diff --git a/docs/bf853f7fb17b7aed38db.module.wasm b/docs/bf853f7fb17b7aed38db.module.wasm deleted file mode 100644 index 3874075..0000000 Binary files a/docs/bf853f7fb17b7aed38db.module.wasm and /dev/null differ diff --git a/docs/bootstrap.js b/docs/bootstrap.js index 877afb3..10ec261 100644 --- a/docs/bootstrap.js +++ b/docs/bootstrap.js @@ -222,7 +222,7 @@ /******/ promises.push(installedWasmModuleData); /******/ else { /******/ var importObject = wasmImportObjects[wasmModuleId](); -/******/ var req = fetch(__webpack_require__.p + "" + {"../pkg/mapgen_demo_bg.wasm":"44ffe41e5a9c873b1c79"}[wasmModuleId] + ".module.wasm"); +/******/ var req = fetch(__webpack_require__.p + "" + {"../pkg/mapgen_demo_bg.wasm":"3450392053799dfed08d"}[wasmModuleId] + ".module.wasm"); /******/ var promise; /******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') { /******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) { diff --git a/docs/cbb67d3121ca19dbc9af.module.wasm b/docs/cbb67d3121ca19dbc9af.module.wasm deleted file mode 100644 index a0d00bd..0000000 Binary files a/docs/cbb67d3121ca19dbc9af.module.wasm and /dev/null differ diff --git a/docs/index.html b/docs/index.html index 3ef797c..c691bd3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,6 +2,7 @@ + Mapgen demo @@ -45,6 +46,8 @@ + Star @@ -56,5 +59,6 @@ integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"> + diff --git a/docs/tiles.png b/docs/tiles.png new file mode 100644 index 0000000..2888695 Binary files /dev/null and b/docs/tiles.png differ