Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions css/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ body {
position: absolute;
bottom: 0px;
right: 0px;
min-width: 100px;
max-width: 300px;
max-height: 60%;
padding: 2px;
Expand Down Expand Up @@ -167,6 +168,19 @@ body {
display: none;// hmmmm
}
}
#instancefindwindow {
position: absolute;
top: @tabs-height;
right: 0px;
padding-right: 10px;
max-width: 300px;
max-height: 40%;
padding: 2px;
background-color: rgba(0,0,0,0.8);
overflow: auto;
white-space: nowrap;
scrollbar-width: thin;
}
#statustextwindow {
position: absolute;
bottom: 0px;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build-prod": "npm ci && rimraf ./dist && webpack --mode=production"
"build-prod": "npm ci && rimraf ./dist && webpack --mode=production",
"develop": "webpack-dev-server"
},
"author": "",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions res/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<canvas id='mapwindow' tabindex="-1"></canvas>
<div id='tabwindow'></div>
<div id='instancewindow'></div>
<div id='instancefindwindow'></div>
<div id='toolwindow'></div>
<div id='statustextwindow'></div>
<div id='notificationwindow'></div>
Expand Down
2 changes: 2 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Parser = require('./parser/parser.js');
const MapWindow = require('./mapwindow.js');
const ObjTreeWindow = require('./objtreewindow.js');
const InstanceWindow = require('./instancewindow.js');
const InstanceFindWindow = require('./instancefindwindow.js');
const DMM = require('./parser/dmm.js');
const {FileMenu, OptionsMenu, HelpMenu} = require('./menu/menubar_menus.js');
const ProgressBarPanel = require('./panels/progress_bar_panel.js');
Expand Down Expand Up @@ -43,6 +44,7 @@ class Editor {
this.map_window = new MapWindow(this);
this.objtree_window = new ObjTreeWindow(this);
this.instance_window = new InstanceWindow(this);
this.instance_find_window = new InstanceFindWindow(this);

this.file_menu = new FileMenu(this);
this.file_menu.add_to_menubar(document.getElementById("ui-menubar"), "File");
Expand Down
56 changes: 56 additions & 0 deletions src/instancefindwindow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

module.exports = class InstanceFindWindow {
/**
*
* @param {import("./editor")} editor
*/
constructor(editor) {
this.editor = editor;
this.container = document.getElementById("instancefindwindow");
}

set_instance_search(item) {
if(!item) return;
this.selected = item;
// Clear old entries
this.container.innerHTML = '';
let found_tiles = [];
// Search the entire map
for(let x = 1; x <= this.editor.dmm.maxx; x++) {
for(let y = 1; y <= this.editor.dmm.maxy; y++) {
for(let z = 1; z <= this.editor.dmm.maxz; z++) {
let tile = this.editor.dmm.get_tile(x, y, z);
for(let content of tile.contents) {
if(content.toString() == item) {
found_tiles.push([x, y, z]);
}
}
}
}
}
for(let tile of found_tiles) {
let entry = document.createElement("div");
entry.dataset.coordinates = tile;
let gotoButton = document.createElement("button");
gotoButton.innerText = "Jump";
gotoButton.addEventListener("click", this.on_goto.bind(this))
let text = document.createElement("span");
text.innerText = " at " + tile[0] + ", " + tile[1] + ", " + tile[2];
entry.appendChild(gotoButton);
entry.appendChild(text);
this.container.appendChild(entry);
}
}

on_goto(e) {
if(!e.target) return;
let leaf = e.target.closest("div");
if(leaf && leaf.dataset.coordinates) {
let coord = leaf.dataset.coordinates.split(",")
this.editor.dmm.mapwindow_x = Math.min(Math.max(coord[0], 1), this.editor.dmm.maxx);
this.editor.dmm.mapwindow_y = Math.min(Math.max(coord[1], 1), this.editor.dmm.maxy);
this.editor.dmm.mapwindow_z = Math.min(Math.max(coord[2], 1), this.editor.dmm.maxz);
}
}
}
17 changes: 17 additions & 0 deletions src/instancewindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ module.exports = class InstanceWindow {
container.appendChild(label);
}

let buttons = document.createElement("div");
let instancesButton = document.createElement("button");
instancesButton.innerText = "Search";
instancesButton.addEventListener("click", this.handle_search_click.bind(this));
buttons.append(instancesButton);
container.appendChild(buttons);

return container;
}

Expand Down Expand Up @@ -120,4 +127,14 @@ module.exports = class InstanceWindow {
}
}
}

handle_search_click(e) {
if(!e.target) return;
// cursed, but we need the variant-leaf
let leaf = e.target.closest(".vertical-node-container").firstChild;
if(leaf && leaf.dataset.instance) {
this.editor.instance_find_window.set_instance_search(leaf.dataset.instance);
}
}

}