Skip to content

Commit

Permalink
New toolbar (#92)
Browse files Browse the repository at this point in the history
* Reorganize control tools

* Use toggle-on class for enclosing radio divs.

* Update CHANGELOG.

* Add button translations.
  • Loading branch information
mcglincy authored Apr 22, 2022
1 parent 0fe20b5 commit 9610f8e
Show file tree
Hide file tree
Showing 13 changed files with 562 additions and 197 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 0.22.1

- Add missing button text.

# 0.22.0

- Reorganize drawing tools into a new tool window and add/remove toggle.

# 0.21.1

- Handle missing texture files more gracefully.
Expand Down
28 changes: 14 additions & 14 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
{
"DD.Add": "Add",
"DD.Algorithm": "Algorithm",
"DD.ApplyTheme": "Apply a Theme",
"DD.BackgroundImage": "Background Image",
"DD.ButtonTitleAddDoor": "Add Doors",
"DD.ButtonTitleAddEllipse": "Add Ellipse",
"DD.ButtonTitleAddPoly": "Add Polygon",
"DD.ButtonTitleAddRect": "Add Rectangle",
"DD.ButtonTitleAddSecretDoor": "Add Secret Doors",
"DD.ButtonTitleAddWall": "Add Interior Walls",
"DD.ButtonTitleClear": "Clear All",
"DD.ButtonTitleClearAll": "Clear All",
"DD.ButtonTitleConfig": "Configure",
"DD.ButtonTitleFreehand": "Add Freehand",
"DD.ButtonTitleDoor": "Door",
"DD.ButtonTitleDrawMap": "Draw Map",
"DD.ButtonTitleEllipse": "Ellipse",
"DD.ButtonTitleFreehand": "Freehand",
"DD.ButtonTitleGenerate": "Generate a Dungeon",
"DD.ButtonTitleInteriorWall": "Interior Wall",
"DD.ButtonTitlePolygon": "Polygon",
"DD.ButtonTitleRectangle": "Rectangle",
"DD.ButtonTitleRedo": "Redo",
"DD.ButtonTitleSaveToSceneBackground": "Save to Scene Background",
"DD.ButtonTitleSecretDoor": "Secret Door",
"DD.ButtonTitleSelect": "Select",
"DD.ButtonTitleSubtractDoorsAndWalls": "Remove Interior Walls and Doors",
"DD.ButtonTitleSubtractFloors": "Remove Floors",
"DD.ButtonTitleSubtractRect": "Remove Rectangle",
"DD.ButtonTitleThemeEraser": "Theme Eraser",
"DD.ButtonTitleThemePainter": "Theme Painter",
"DD.ButtonTitleUndo": "Undo",
"DD.Cancel": "Cancel",
Expand All @@ -37,6 +35,9 @@
"DD.DoorLineThickness": "Door Line Thickness",
"DD.DoorThickness": "Door Thickness",
"DD.EditTheme": "Edit Theme",
"DD.ErrorAddingPolygon": "Error adding polygon - see JS console for details.",
"DD.ErrorRemovingPolygon": "Error removing polygon - see JS console for details.",
"DD.ErrorInvalidShape": "Invalid shape - try drawing a simpler closed polygon.",
"DD.Export": "Export",
"DD.ExteriorShadowColor": "Exterior Shadow Color",
"DD.ExteriorShadowOpacity": "Exterior Shadow Opacity",
Expand All @@ -55,8 +56,6 @@
"DD.ImportCustomThemesHint": "Choose a JSON file to import as your custom themes. This cannot be undone.",
"DD.ImportJsonFile": "JSON file",
"DD.ImportWipeExistingData": "Wipe existing data",
"DD.ErrorAddingPolygon": "Error adding polygon - see JS console for details.",
"DD.ErrorInvalidShape": "Invalid shape - try drawing a simpler closed polygon.",
"DD.InteriorShadowColor": "Interior Shadow Color",
"DD.InteriorShadowOpacity": "Interior Shadow Opacity",
"DD.InteriorShadowThickness": "Interior Shadow Thickness",
Expand All @@ -66,6 +65,7 @@
"DD.MinRoomSize": "Minimum Room Size",
"DD.ModuleThemes": "Module Themes",
"DD.ReleaseNotes": "Dungeon Draw Release Notes",
"DD.Remove": "Remove",
"DD.ResetToDefaults": "Reset to Defaults",
"DD.RoomCount": "Room Count",
"DD.SettingAllowTrustedPlayers": "Allow Trusted Players",
Expand Down
28 changes: 14 additions & 14 deletions lang/ja.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
{
"DD.Add": "加算",
"DD.Algorithm": "アルゴリズム",
"DD.ApplyTheme": "テーマ適用",
"DD.BackgroundImage": "背景画像",
"DD.ButtonTitleAddDoor": "扉追加",
"DD.ButtonTitleAddPoly": "多角形追加",
"DD.ButtonTitleAddEllipse": "楕円を追加",
"DD.ButtonTitleAddRect": "正方形追加",
"DD.ButtonTitleAddSecretDoor": "シークレットドア追加",
"DD.ButtonTitleAddWall": "内壁追加",
"DD.ButtonTitleClear": "全てクリア",
"DD.ButtonTitleClearAll": "全てクリア",
"DD.ButtonTitleConfig": "設定",
"DD.ButtonTitleFreehand": "お絵かき追加",
"DD.ButtonTitleDoor": "",
"DD.ButtonTitleDrawMap": "地図を描く",
"DD.ButtonTitleFreehand": "描画",
"DD.ButtonTitleEllipse": "楕円",
"DD.ButtonTitleGenerate": "ダンジョン生成",
"DD.ButtonTitleInteriorWall": "内壁",
"DD.ButtonTitlePolygon": "多角",
"DD.ButtonTitleRectangle": "矩形",
"DD.ButtonTitleRedo": "やり直す",
"DD.ButtonTitleSaveToSceneBackground": "シーン背景として保存",
"DD.ButtonTitleSecretDoor": "シークレットドア追加",
"DD.ButtonTitleSelect": "選択",
"DD.ButtonTitleSubtractDoorsAndWalls": "内壁や扉を削除",
"DD.ButtonTitleSubtractFloors": "床を削除",
"DD.ButtonTitleSubtractRect": "正方形を削除",
"DD.ButtonTitleThemeEraser": "テーマ消しゴム",
"DD.ButtonTitleThemePainter": "テーマブラシ",
"DD.ButtonTitleUndo": "元に戻す",
"DD.Cancel": "キャンセル",
Expand All @@ -37,6 +35,9 @@
"DD.DoorLineThickness": "扉の線の太さ",
"DD.DoorThickness": "扉の厚さ",
"DD.EditTheme": "テーマ編集",
"DD.ErrorAddingPolygon": "ポリゴンを追加できませんでした。JSコンソールより詳細を御覧ください。",
"DD.ErrorRemovingPolygon": "ポリゴンの削除中にエラーが発生しました-詳細については、JSコンソールを参照してください.",
"DD.ErrorInvalidShape": "無効な形状です。もう少し単純な形の多角形を描いてみてください。",
"DD.Export": "エクスポート",
"DD.ExteriorShadowColor": "外装の影の色",
"DD.ExteriorShadowOpacity": "外装の影の不透明度",
Expand All @@ -53,8 +54,6 @@
"DD.Import": "インポート",
"DD.ImportCustomThemes": "カスタム・テーマをインポート",
"DD.ImportCustomThemesHint": "カスタム・テーマとしてインポートするJSONファイルを選択肢てください。この操作は元に戻せません。",
"DD.ErrorAddingPolygon": "ポリゴンを追加できませんでした。JSコンソールより詳細を御覧ください。",
"DD.ErrorInvalidShape": "無効な形状です。もう少し単純な形の多角形を描いてみてください。",
"DD.InteriorShadowColor": "内装の影の色",
"DD.InteriorShadowOpacity": "内装の影のの不透明度",
"DD.InteriorShadowThickness": "内装の影の濃さ",
Expand All @@ -64,6 +63,7 @@
"DD.MinRoomSize": "最小部屋サイズ",
"DD.ModuleThemes": "既存テーマ",
"DD.ReleaseNotes": "Dungeon Draw更新ノート",
"DD.Remove": "取り除く",
"DD.ResetToDefaults": "デフォルトに戻す",
"DD.RoomCount": "部屋の数",
"DD.SceneBackgroundColor": "シーンの背景色",
Expand Down
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.

2 changes: 0 additions & 2 deletions src/configsheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ export class ConfigSheet extends FormApplication {
}
readTextFromFile(form.data.files[0]).then((text) => {
const newJson = JSON.parse(text);
console.log(`form wipe ${form.wipe.checked}`);
if (form.wipe.checked) {
// replace existing JSON
setCustomThemes(newJson);
Expand All @@ -264,7 +263,6 @@ export class ConfigSheet extends FormApplication {
oldJson,
newJson
);
console.log(mergedJson);
setCustomThemes(mergedJson);
}
this.render();
Expand Down
80 changes: 50 additions & 30 deletions src/dungeon.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,6 @@ export class Dungeon extends PlaceableObject {
await this.pushState(newState);
}

// {x:, y:, height:, width:}
async subtractDoors(rect) {
const rectPoly = geo.rectToPolygon(rect);
const doorsToKeep = this.history[this.historyIndex].doors.filter((d) => {
const doorPoly = geo.twoPointsToLineString(d[0], d[1], d[2], d[3]);
return !geo.intersects(rectPoly, doorPoly);
});
if (doorsToKeep.length != this.history[this.historyIndex].doors.length) {
const newState = this.history[this.historyIndex].clone();
newState.doors = doorsToKeep;
await this.pushState(newState);
}
}

/**
* Split the wall if it's drawn over an existing door.
*
Expand Down Expand Up @@ -286,7 +272,7 @@ export class Dungeon extends PlaceableObject {
}

// {x:, y:, height:, width:}
async subtractInteriorWalls(rect) {
async removeInteriorWalls(rect) {
const rectPoly = geo.rectToPolygon(rect);
const wallsToKeep = this.history[this.historyIndex].interiorWalls.filter(
(w) => {
Expand All @@ -304,30 +290,31 @@ export class Dungeon extends PlaceableObject {
}

// {x:, y:, height:, width:}
async subtractDoorsAndInteriorWalls(rect) {
async removeDoors(rect) {
const rectPoly = geo.rectToPolygon(rect);
const oldState = this.history[this.historyIndex];
const doorsToKeep = oldState.doors.filter((d) => {
const doorPoly = geo.twoPointsToLineString(d[0], d[1], d[2], d[3]);
return !geo.intersects(rectPoly, doorPoly);
});
if (doorsToKeep.length != oldState.doors.length) {
const newState = oldState.clone();
newState.doors = doorsToKeep;
await this.pushState(newState);
}
}

// {x:, y:, height:, width:}
async removeSecretDoors(rect) {
const rectPoly = geo.rectToPolygon(rect);
const oldState = this.history[this.historyIndex];
const secretDoorsToKeep = oldState.secretDoors.filter((d) => {
const doorPoly = geo.twoPointsToLineString(d[0], d[1], d[2], d[3]);
return !geo.intersects(rectPoly, doorPoly);
});
const wallsToKeep = oldState.interiorWalls.filter((w) => {
const wallPoly = geo.twoPointsToLineString(w[0], w[1], w[2], w[3]);
return !geo.intersects(rectPoly, wallPoly);
});
if (
doorsToKeep.length != oldState.doors.length ||
secretDoorsToKeep.length != oldState.secretDoors.length ||
wallsToKeep.length != oldState.interiorWalls.length
) {
if (secretDoorsToKeep.length != oldState.secretDoors.length) {
const newState = oldState.clone();
newState.doors = doorsToKeep;
newState.secretDoors = secretDoorsToKeep;
newState.interiorWalls = wallsToKeep;
await this.pushState(newState);
}
}
Expand Down Expand Up @@ -378,12 +365,16 @@ export class Dungeon extends PlaceableObject {
}

// {x:, y:, height:, width:}
async subtractRectangle(rect) {
// only makes sense to subtract if we have geometry
async removeRectangle(rect) {
const poly = geo.rectToPolygon(rect);
await this._removePoly(poly);
}

async _removePoly(poly) {
// only makes sense to remove if we have geometry
if (!this.history[this.historyIndex].geometry) {
return;
}
const poly = geo.rectToPolygon(rect);
// and if the poly intersects existing geometry
if (!geo.intersects(this.history[this.historyIndex].geometry, poly)) {
return;
Expand All @@ -408,6 +399,21 @@ export class Dungeon extends PlaceableObject {
}
}

// [[x,y]...]
async removePolygon(points) {
const poly = geo.pointsToPolygon(points);
if (!geo.isValid(poly)) {
ui.notifications.error(game.i18n.localize("DD.ErrorInvalidShape"));
return;
}
try {
await this._removePoly(poly);
} catch (error) {
console.log(error);
ui.notifications.error(game.i18n.localize("DD.ErrorRemovingPolygon"));
}
}

async addEllipse(x, y, width, height) {
const poly = geo.ellipse(x, y, width, height);
if (!geo.isValid(poly)) {
Expand All @@ -422,6 +428,20 @@ export class Dungeon extends PlaceableObject {
}
}

async removeEllipse(x, y, width, height) {
const poly = geo.ellipse(x, y, width, height);
if (!geo.isValid(poly)) {
ui.notifications.error(game.i18n.localize("DD.ErrorInvalidShape"));
return;
}
try {
await this._removePoly(poly);
} catch (error) {
console.log(error);
ui.notifications.error(game.i18n.localize("DD.ErrorRemovingPolygon"));
}
}

/**
* @param {Object} rect
* @param {Number} rect.x
Expand Down
Loading

0 comments on commit 9610f8e

Please sign in to comment.