mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
refactor(es modules): set src as TS base folder
This commit is contained in:
parent
0d05e1b250
commit
32d7db765d
8 changed files with 33 additions and 40 deletions
|
|
@ -7664,7 +7664,6 @@
|
||||||
<script src="/src/libs/priority-queue.min.js"></script>
|
<script src="/src/libs/priority-queue.min.js"></script>
|
||||||
<script src="/src/libs/delaunator.min.js"></script>
|
<script src="/src/libs/delaunator.min.js"></script>
|
||||||
|
|
||||||
<script src="/src/modules/voronoi.js"></script>
|
|
||||||
<script src="/src/config/heightmap-templates.js"></script>
|
<script src="/src/config/heightmap-templates.js"></script>
|
||||||
<script src="/src/config/precreated-heightmaps.js"></script>
|
<script src="/src/config/precreated-heightmaps.js"></script>
|
||||||
<script type="module" src="/src/modules/heightmap-generator.js"></script>
|
<script type="module" src="/src/modules/heightmap-generator.js"></script>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
import {rand, P, each, gauss, ra, rw, generateSeed} from "/src/utils/probabilityUtils";
|
import {rand, P, each, gauss, ra, rw, generateSeed} from "/src/utils/probabilityUtils";
|
||||||
import {round, splitInTwo} from "/src/utils/stringUtils";
|
import {round, splitInTwo} from "/src/utils/stringUtils";
|
||||||
import {trimVowels, getAdjective} from "/src/utils/languageUtils";
|
import {trimVowels, getAdjective} from "/src/utils/languageUtils";
|
||||||
|
import {Voronoi} from "/src/modules/voronoi";
|
||||||
|
|
||||||
window.BurgsAndStates = (function () {
|
window.BurgsAndStates = (function () {
|
||||||
const generate = function () {
|
const generate = function () {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import {applyOption} from "./general";
|
import {applyOption} from "./general";
|
||||||
import {last} from "/src/utils/arrayUtils";
|
|
||||||
import {lock, locked} from "/src/scripts/options/lock";
|
import {lock, locked} from "/src/scripts/options/lock";
|
||||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
import {clearMainTip, tip} from "/src/scripts/tooltips";
|
||||||
|
import {last} from "/src/utils/arrayUtils";
|
||||||
|
import {minmax, rn} from "/src/utils/numberUtils";
|
||||||
|
import {gauss, P, rand, rw} from "/src/utils/probabilityUtils";
|
||||||
import {byId, stored} from "/src/utils/shorthands";
|
import {byId, stored} from "/src/utils/shorthands";
|
||||||
import {rn, minmax} from "/src/utils/numberUtils";
|
|
||||||
import {rand, P, gauss} from "/src/utils/probabilityUtils";
|
|
||||||
|
|
||||||
$("#optionsContainer").draggable({handle: ".drag-trigger", snap: "svg", snapMode: "both"});
|
$("#optionsContainer").draggable({handle: ".drag-trigger", snap: "svg", snapMode: "both"});
|
||||||
$("#exitCustomization").draggable({handle: "div"});
|
$("#exitCustomization").draggable({handle: "div"});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
class Voronoi {
|
export class Voronoi {
|
||||||
/**
|
/**
|
||||||
* Creates a Voronoi diagram from the given Delaunator, a list of points, and the number of points. The Voronoi diagram is constructed using (I think) the {@link https://en.wikipedia.org/wiki/Bowyer%E2%80%93Watson_algorithm |Bowyer-Watson Algorithm}
|
* Creates a Voronoi diagram from the given Delaunator, a list of points, and the number of points. The Voronoi diagram is constructed using (I think) the {@link https://en.wikipedia.org/wiki/Bowyer%E2%80%93Watson_algorithm |Bowyer-Watson Algorithm}
|
||||||
* The {@link https://github.com/mapbox/delaunator/ |Delaunator} library uses {@link https://en.wikipedia.org/wiki/Doubly_connected_edge_list |half-edges} to represent the relationship between points and triangles.
|
* The {@link https://github.com/mapbox/delaunator/ |Delaunator} library uses {@link https://en.wikipedia.org/wiki/Doubly_connected_edge_list |half-edges} to represent the relationship between points and triangles.
|
||||||
|
|
@ -17,7 +17,6 @@ class Voronoi {
|
||||||
// delaunay.triangles[e] gives the point ID where the half-edge starts
|
// delaunay.triangles[e] gives the point ID where the half-edge starts
|
||||||
// delaunay.halfedges[e] returns either the opposite half-edge in the adjacent triangle, or -1 if there's not an adjacent triangle.
|
// delaunay.halfedges[e] returns either the opposite half-edge in the adjacent triangle, or -1 if there's not an adjacent triangle.
|
||||||
for (let e = 0; e < this.delaunay.triangles.length; e++) {
|
for (let e = 0; e < this.delaunay.triangles.length; e++) {
|
||||||
|
|
||||||
const p = this.delaunay.triangles[this.nextHalfedge(e)];
|
const p = this.delaunay.triangles[this.nextHalfedge(e)];
|
||||||
if (p < this.pointsN && !this.cells.c[p]) {
|
if (p < this.pointsN && !this.cells.c[p]) {
|
||||||
const edges = this.edgesAroundPoint(e);
|
const edges = this.edgesAroundPoint(e);
|
||||||
|
|
@ -89,28 +88,36 @@ class Voronoi {
|
||||||
* @param {number} t The index of the triangle
|
* @param {number} t The index of the triangle
|
||||||
* @returns {[number, number, number]} The edges of the triangle.
|
* @returns {[number, number, number]} The edges of the triangle.
|
||||||
*/
|
*/
|
||||||
edgesOfTriangle(t) { return [3 * t, 3 * t + 1, 3 * t + 2]; }
|
edgesOfTriangle(t) {
|
||||||
|
return [3 * t, 3 * t + 1, 3 * t + 2];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables lookup of a triangle, given one of the half-edges of that triangle. Taken from {@link https://mapbox.github.io/delaunator/#edge-and-triangle| the Delaunator docs.}
|
* Enables lookup of a triangle, given one of the half-edges of that triangle. Taken from {@link https://mapbox.github.io/delaunator/#edge-and-triangle| the Delaunator docs.}
|
||||||
* @param {number} e The index of the edge
|
* @param {number} e The index of the edge
|
||||||
* @returns {number} The index of the triangle
|
* @returns {number} The index of the triangle
|
||||||
*/
|
*/
|
||||||
triangleOfEdge(e) { return Math.floor(e / 3); }
|
triangleOfEdge(e) {
|
||||||
|
return Math.floor(e / 3);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves to the next half-edge of a triangle, given the current half-edge's index. Taken from {@link https://mapbox.github.io/delaunator/#edge-to-edges| the Delaunator docs.}
|
* Moves to the next half-edge of a triangle, given the current half-edge's index. Taken from {@link https://mapbox.github.io/delaunator/#edge-to-edges| the Delaunator docs.}
|
||||||
* @param {number} e The index of the current half edge
|
* @param {number} e The index of the current half edge
|
||||||
* @returns {number} The index of the next half edge
|
* @returns {number} The index of the next half edge
|
||||||
*/
|
*/
|
||||||
nextHalfedge(e) { return (e % 3 === 2) ? e - 2 : e + 1; }
|
nextHalfedge(e) {
|
||||||
|
return e % 3 === 2 ? e - 2 : e + 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves to the previous half-edge of a triangle, given the current half-edge's index. Taken from {@link https://mapbox.github.io/delaunator/#edge-to-edges| the Delaunator docs.}
|
* Moves to the previous half-edge of a triangle, given the current half-edge's index. Taken from {@link https://mapbox.github.io/delaunator/#edge-to-edges| the Delaunator docs.}
|
||||||
* @param {number} e The index of the current half edge
|
* @param {number} e The index of the current half edge
|
||||||
* @returns {number} The index of the previous half edge
|
* @returns {number} The index of the previous half edge
|
||||||
*/
|
*/
|
||||||
prevHalfedge(e) { return (e % 3 === 0) ? e + 2 : e - 1; }
|
prevHalfedge(e) {
|
||||||
|
return e % 3 === 0 ? e + 2 : e - 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the circumcenter of the triangle identified by points a, b, and c. Taken from {@link https://en.wikipedia.org/wiki/Circumscribed_circle#Circumcenter_coordinates| Wikipedia}
|
* Finds the circumcenter of the triangle identified by points a, b, and c. Taken from {@link https://en.wikipedia.org/wiki/Circumscribed_circle#Circumcenter_coordinates| Wikipedia}
|
||||||
|
|
@ -128,8 +135,8 @@ class Voronoi {
|
||||||
const cd = cx * cx + cy * cy;
|
const cd = cx * cx + cy * cy;
|
||||||
const D = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by));
|
const D = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by));
|
||||||
return [
|
return [
|
||||||
Math.floor(1 / D * (ad * (by - cy) + bd * (cy - ay) + cd * (ay - by))),
|
Math.floor((1 / D) * (ad * (by - cy) + bd * (cy - ay) + cd * (ay - by))),
|
||||||
Math.floor(1 / D * (ad * (cx - bx) + bd * (ax - cx) + cd * (bx - ax)))
|
Math.floor((1 / D) * (ad * (cx - bx) + bd * (ax - cx) + cd * (bx - ax)))
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import {UINT8_MAX, UINT16_MAX, UINT32_MAX} from "../constants";
|
import {UINT16_MAX, UINT32_MAX, UINT8_MAX} from "../constants";
|
||||||
|
|
||||||
export function last<T>(array: T[]) {
|
export function last<T>(array: T[]) {
|
||||||
return array[array.length - 1];
|
return array[array.length - 1];
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ import {TIME} from "../config/logging";
|
||||||
import {createTypedArray} from "./arrayUtils";
|
import {createTypedArray} from "./arrayUtils";
|
||||||
import {rn} from "./numberUtils";
|
import {rn} from "./numberUtils";
|
||||||
import {byId} from "./shorthands";
|
import {byId} from "./shorthands";
|
||||||
|
import {Voronoi} from "/src/modules/voronoi";
|
||||||
|
|
||||||
const Delaunator = window.Delaunator;
|
const Delaunator = window.Delaunator;
|
||||||
const Voronoi = window.Voronoi;
|
|
||||||
const graphWidth = window.graphWidth;
|
const graphWidth = window.graphWidth;
|
||||||
const graphHeight = window.graphHeight;
|
const graphHeight = window.graphHeight;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,8 @@
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": true,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"skipLibCheck": true
|
"skipLibCheck": true,
|
||||||
// "baseUrl": ".",
|
"baseUrl": "src"
|
||||||
// "paths": {
|
|
||||||
// "@/*": ["./src/*"]
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
"include": ["src"]
|
"include": ["src"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,23 +3,12 @@
|
||||||
// import path from "path";
|
// import path from "path";
|
||||||
|
|
||||||
// const pathName = path.dirname(fileURLToPath(import.meta.url));
|
// const pathName = path.dirname(fileURLToPath(import.meta.url));
|
||||||
// const resolved = path.resolve(pathName, "./src");
|
|
||||||
|
|
||||||
// export default defineConfig({
|
// export default defineConfig({
|
||||||
// // base: "/Fantasy-Map-Generator/",
|
// // base: "/Fantasy-Map-Generator/",
|
||||||
// resolve: {
|
// resolve: {
|
||||||
// alias: {
|
// alias: [
|
||||||
// // "@": path.resolve(pathName, "./src")
|
// {find: "@", replacement: path.resolve(pathName, "./src")}
|
||||||
// // "@": path.resolve(path.dirname(fileURLToPath(import.meta.url)), "./src")
|
// ]
|
||||||
// // "@": path.resolve(path.dirname(fileURLToPath(import.meta.url)), "/src")
|
|
||||||
// // {
|
|
||||||
// // find: "@",
|
|
||||||
// // replacement: path.resolve(pathName, "./src"),
|
|
||||||
// // customResolver: request => {
|
|
||||||
// // console.log(request);
|
|
||||||
// // return request;
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue