Skip to content

Commit

Permalink
Update ts version
Browse files Browse the repository at this point in the history
  • Loading branch information
Sopiro committed Mar 4, 2024
1 parent b1295d4 commit 8afcd5d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
32 changes: 21 additions & 11 deletions out/settings.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as Util from "./util.js";
export var GenerationShape;
(function (GenerationShape) {
(function (GenerationShape)
{
GenerationShape[GenerationShape["Box"] = 0] = "Box";
GenerationShape[GenerationShape["Circle"] = 1] = "Circle";
GenerationShape[GenerationShape["Regular"] = 2] = "Regular";
GenerationShape[GenerationShape["Random"] = 3] = "Random";
})(GenerationShape || (GenerationShape = {}));
export var MouseMode;
(function (MouseMode) {
(function (MouseMode)
{
MouseMode[MouseMode["Grab"] = 0] = "Grab";
MouseMode[MouseMode["Force"] = 1] = "Force";
})(MouseMode || (MouseMode = {}));
Expand All @@ -24,22 +26,25 @@ export const Settings = {
paused: false,
boxCount: 15,
genSpeed: 50,
aabbMargin: 0.1,
aabbMultiplier: 4.0,
colorize: true,
applyRotation: true,
// These two options are actually tree member variables..
aabbMargin: 0.1,
aabbMultiplier: 4.0,
};
// Remove the default pop-up context menu
let cvs = document.querySelector("#canvas");
cvs.oncontextmenu = (e) => {
cvs.oncontextmenu = (e) =>
{
e.preventDefault();
e.stopPropagation();
};
const boxCount = document.querySelector("#boxCount");
boxCount.value = String(Util.map(Settings.boxCount, boxCountRange.p1, boxCountRange.p2, 0, 100));
const boxCountLabel = document.querySelector("#boxCount_label");
boxCountLabel.innerHTML = String(Settings.boxCount);
boxCount.addEventListener("input", () => {
boxCount.addEventListener("input", () =>
{
let mappedValue = Util.map(Number(boxCount.value), 0, 100, boxCountRange.p1, boxCountRange.p2);
mappedValue = Math.trunc(mappedValue);
boxCountLabel.innerHTML = String(mappedValue);
Expand All @@ -49,7 +54,8 @@ const genSpeed = document.querySelector("#genSpeed");
genSpeed.value = String(Util.map(Settings.genSpeed, genSpeedRange.p1, genSpeedRange.p2, 0, 100));
const genSpeedLabel = document.querySelector("#genSpeed_label");
genSpeedLabel.innerHTML = String(Settings.genSpeed) + "ms";
genSpeed.addEventListener("input", () => {
genSpeed.addEventListener("input", () =>
{
let mappedValue = Util.map(Number(genSpeed.value), 0, 100, genSpeedRange.p1, genSpeedRange.p2);
mappedValue = Math.trunc(mappedValue);
genSpeedLabel.innerHTML = String(mappedValue) + "ms";
Expand All @@ -59,7 +65,8 @@ const margin = document.querySelector("#margin");
margin.value = String(Util.map(Settings.aabbMargin, marginRange.p1, marginRange.p2, 0, 100));
const marginLabel = document.querySelector("#margin_label");
marginLabel.innerHTML = String(Settings.aabbMargin) + "cm";
margin.addEventListener("input", () => {
margin.addEventListener("input", () =>
{
let mappedValue = Util.map(Number(margin.value), 0, 100, marginRange.p1, marginRange.p2);
marginLabel.innerHTML = String(mappedValue) + "cm";
updateSetting("margin", mappedValue);
Expand All @@ -68,7 +75,8 @@ const multiplier = document.querySelector("#multiplier");
multiplier.value = String(Util.map(Settings.aabbMultiplier, multiplierRange.p1, multiplierRange.p2, 0, 100));
const multiplierLabel = document.querySelector("#multiplier_label");
multiplierLabel.innerHTML = String(Settings.aabbMultiplier);
multiplier.addEventListener("input", () => {
multiplier.addEventListener("input", () =>
{
let mappedValue = Util.map(Number(multiplier.value), 0, 100, multiplierRange.p1, multiplierRange.p2);
mappedValue = Math.trunc(mappedValue);
multiplierLabel.innerHTML = String(mappedValue);
Expand All @@ -80,8 +88,10 @@ colorize.addEventListener("click", () => { Settings.colorize = colorize.checked;
const applyRotation = document.querySelector("#applyRotation");
applyRotation.checked = Settings.applyRotation;
applyRotation.addEventListener("click", () => { Settings.applyRotation = applyRotation.checked; });
export function updateSetting(id, content) {
switch (id) {
export function updateSetting(id, content)
{
switch (id)
{
case "pause":
Settings.paused = !Settings.paused;
break;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"devDependencies": {
"ts-loader": "^9.2.6",
"typescript": "^4.4.4"
"typescript": "^4.9.5"
}
}
4 changes: 2 additions & 2 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Game

private tree: AABBTree;

private initRoutines: NodeJS.Timer[] = [];
private initRoutines: NodeJS.Timeout[] = [];
private creating: boolean = false;
private grabbing: boolean = false;
private removing: boolean = false;
Expand Down Expand Up @@ -84,7 +84,7 @@ export class Game
this.tree.reset();

for (let r of this.initRoutines)
clearInterval(r);
clearInterval(r)

// Random initial spread
let seedString = this.seedTextBox.value;
Expand Down
5 changes: 3 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export const Settings = {
paused: false,
boxCount: 15,
genSpeed: 50,
aabbMargin: 0.1,
aabbMultiplier: 4.0,
colorize: true,
applyRotation: true,
// These two options are actually tree member variables..
aabbMargin: 0.1,
aabbMultiplier: 4.0,
}

// Remove the default pop-up context menu
Expand Down

0 comments on commit 8afcd5d

Please sign in to comment.