Skip to content

Commit

Permalink
Implement dungeon generation (#67)
Browse files Browse the repository at this point in the history
* Proof of concept dungeon generation.

* Whoops, add new files.

* Add rot.js and cellular generator.

* More cleanup and tweaks for generation.

* Refactor exterior shadow drawing.

* Implement smoothing.

* Expose per-algorithm form fields.

* Only apply smoothing for rot.js cellular.

* Generate doors for 2D-Dungeon and Dungeoneer.

* Latest.

* Latest bundle.
  • Loading branch information
mcglincy authored Dec 26, 2021
1 parent 0a5a512 commit e5ca15f
Show file tree
Hide file tree
Showing 15 changed files with 777 additions and 24 deletions.
18 changes: 16 additions & 2 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"DD.Algorithm": "Algorithm",
"DD.ApplyTheme": "Apply a Theme",
"DD.BackgroundImage": "Background Image",
"DD.ButtonTitleAddDoor": "Add Doors",
Expand All @@ -9,6 +10,7 @@
"DD.ButtonTitleClear": "Clear All",
"DD.ButtonTitleConfig": "Configure",
"DD.ButtonTitleFreehand": "Add Freehand",
"DD.ButtonTitleGenerate": "Generate a Dungeon",
"DD.ButtonTitleRedo": "Redo",
"DD.ButtonTitleSaveToSceneBackground": "Save to Scene Background",
"DD.ButtonTitleSelect": "Select",
Expand All @@ -18,8 +20,10 @@
"DD.ButtonTitleThemeEraser": "Theme Eraser",
"DD.ButtonTitleThemePainter": "Theme Painter",
"DD.ButtonTitleUndo": "Undo",
"DD.CenterExits": "Center Exits",
"DD.ClearAllDialogContent": "Clear this scene's dungeon? This cannot be undone.",
"DD.ConfigSheetTitle": "Dungeon Settings",
"DD.ConnectCaves": "Connect Caves",
"DD.CopyOf": "Copy of",
"DD.CopyTheme": "Copy Theme",
"DD.CustomThemes": "Custom Themes",
Expand All @@ -36,22 +40,31 @@
"DD.FloorColor": "Floor Color",
"DD.FloorTexture": "Floor Texture",
"DD.FloorTextureTint": "Floor Texture Tint",
"DD.Generate": "Generate",
"DD.GenerateDoors": "Generate Doors",
"DD.GeneratorSheetTitle": "Generate a Dungeon",
"DD.Height": "Height",
"DD.InteriorShadowColor": "Interior Shadow Color",
"DD.InteriorShadowOpacity": "Interior Shadow Opacity",
"DD.InteriorShadowThickness": "Interior Shadow Thickness",
"DD.OK": "OK",
"DD.MaxRoomSize": "Maximum Room Size",
"DD.MinRoomSize": "Minimum Room Size",
"DD.ModuleThemes": "Module Themes",
"DD.ReleaseNotes": "Dungeon Draw Release Notes",
"DD.ResetToDefaults": "Reset to Defaults",
"DD.RoomCount": "Room Count",
"DD.SceneBackgroundColor": "Scene Background Color",
"DD.SceneControlTitle": "Dungeon Draw",
"DD.SceneGridColor": "Scene Grid Color",
"DD.SceneGridOpacity": "Scene Grid Opacity",
"DD.SecretDoorSColor": "Secret Door S Color",
"DD.SecretDoorStyleGM": "Secret Door GM Style",
"DD.SecretDoorStylePlayer": "Secret Door Player Style",
"DD.ResetToDefaults": "Reset to Defaults",
"DD.Smoothing": "Smoothing (0-5)",
"DD.Save": "Save",
"DD.SaveAsCustomTheme": "Save new Custom Theme",
"DD.TabGeneratorSettings": "Generator Settings",
"DD.TabSettings": "Map Config",
"DD.TabThemes": "Themes",
"DD.TabThemePainter": "Theme Painter",
Expand All @@ -67,5 +80,6 @@
"DD.WallColor": "Wall Color",
"DD.WallTexture": "Wall Texture",
"DD.WallTextureTint": "Wall Texture Tint",
"DD.WallThickness": "Wall Thickness"
"DD.WallThickness": "Wall Thickness",
"DD.Width": "Width"
}
4 changes: 2 additions & 2 deletions modules/dungeondraw-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/dungeondraw-bundle.min.js.map

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"license": "MIT",
"author": "mcglintlock",
"dependencies": {
"jsts": "^2.8.1"
"2d-dungeon": "0.0.7",
"dungeoneer": "^2.1.5",
"jsts": "^2.8.1",
"rot-js": "^2.2.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.0.6",
Expand All @@ -14,6 +17,7 @@
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"rollup": "^2.60.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-terser": "^7.0.2"
},
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import nodeResolve from "@rollup/plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import commonjs from "rollup-plugin-commonjs";

export default () => {
return [
Expand All @@ -12,7 +13,7 @@ export default () => {
preferConst: true,
sourcemap: true,
},
plugins: [nodeResolve()],
plugins: [nodeResolve(), commonjs()],
},
];
};
5 changes: 5 additions & 0 deletions src/dungeon.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export class Dungeon extends PlaceableObject {
// uncomment for jpg+compression
//const filename = `${canvas.scene.name}-dungeon.jpg`;
//const base64 = await canvas.app.renderer.extract.base64(this, "image/jpeg", 0.5);
// const randString =
// Math.random().toString(36).substring(2, 6) +
// Math.random().toString(36).substring(2, 6);
// const filename = `${canvas.scene.name}-dungeon-${randString}.png`;
const filename = `${canvas.scene.name}-dungeon.png`;
const base64 = await canvas.app.renderer.extract.base64(tempContainer);
const res = await fetch(base64);
Expand All @@ -103,6 +107,7 @@ export class Dungeon extends PlaceableObject {
await FilePicker.upload("data", folder, file, {});
const path = folder ? folder + "/" + filename : filename;
// make sure we don't keep using a cached copy
// TODO: we only need to do this is we're keeping a fixed filename
TextureLoader.loader.cache.delete(path);
if (canvas.scene.data.img === path) {
// cheat to force a scene update when we're re-saving to the same filename
Expand Down
8 changes: 8 additions & 0 deletions src/dungeondraw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ConfigSheet } from "./configsheet.js";
import { DungeonLayer } from "./dungeonlayer.js";
import * as constants from "./constants.js";
import { GeneratorSheet } from "./generatorsheet.js";
import { Settings } from "./settings";

export class DungeonDraw {
Expand Down Expand Up @@ -90,6 +91,13 @@ export class DungeonDraw {
icon: "fas fa-dungeon",
visible: game.user.isTrusted,
tools: [
{
name: "generate",
title: "DD.ButtonTitleGenerate",
icon: "fas fa-magic",
onClick: async () => new GeneratorSheet().render(true),
button: true,
},
{
name: "addrect",
title: "DD.ButtonTitleAddRect",
Expand Down
6 changes: 6 additions & 0 deletions src/dungeonlayer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as constants from "./constants.js";
import { Dungeon } from "./dungeon.js";
import { regenerate } from "./generator.js";
import { Settings } from "./settings.js";

const FOLDER_NAME = "Dungeon Draw";
Expand Down Expand Up @@ -173,6 +174,11 @@ export class DungeonLayer extends PlaceablesLayer {
});
}

async generate(config) {
await this.dungeon.deleteAll();
await regenerate(this.dungeon, config);
}

/* -------------------------------------------- */

async loadDungeon() {
Expand Down
Loading

0 comments on commit e5ca15f

Please sign in to comment.