This commit is contained in:
Ladd 2025-12-27 17:10:34 -06:00
parent a1af83b392
commit e3fe7bd4e4
10 changed files with 1157 additions and 20 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*.sw[po] *.sw[po]
node_modules/

25
UNLICENSE Normal file
View File

@ -0,0 +1,25 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org/>

7
eslint.config.mjs Normal file
View File

@ -0,0 +1,7 @@
import js from "@eslint/js";
import globals from "globals";
import { defineConfig } from "eslint/config";
export default defineConfig([
{ files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.browser } },
]);

View File

@ -2,7 +2,6 @@ import { MassObject } from './object.js';
import { import {
MASS_CREATION_RATE, MASS_CREATION_RATE,
DISPLAY_OBJECTS_INFO, DISPLAY_OBJECTS_INFO,
MOTION_TIME_SCALE,
GRAVITATIONAL_CONSTANT, GRAVITATIONAL_CONSTANT,
ZOOM_TO_FIT_PADDING, ZOOM_TO_FIT_PADDING,
} from './config.js'; } from './config.js';
@ -57,7 +56,6 @@ export class Objects {
doneCreatingObject() { doneCreatingObject() {
if (this.creatingObject !== undefined) { if (this.creatingObject !== undefined) {
const obj = this.objects[this.creatingObject];
this.creatingObject = undefined; this.creatingObject = undefined;
this.resume(); this.resume();
} }
@ -138,7 +136,7 @@ export class Objects {
} }
} }
handlePointerUp({x, y}) { handlePointerUp() {
this.doneCreatingObject(); this.doneCreatingObject();
this.deselect(); this.deselect();
} }

1090
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

21
package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "gravity",
"version": "0.2.0",
"description": "Gravity Simulator",
"main": "simulator.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "npx eslint"
},
"repository": {
"type": "git",
"url": "git@git.laddhoffman.com:lentil/gravity.git"
},
"author": "Ladd Hoffman <lentil@laddhoffman.com>",
"license": "Unlicense",
"devDependencies": {
"@eslint/js": "^9.39.2",
"eslint": "^9.39.2",
"globals": "^16.5.0"
}
}

View File

@ -1,18 +1,13 @@
import { import {
POINTER_HISTORY_SIZE,
ZOOM_IN_FACTOR,
ZOOM_OUT_FACTOR,
DISPLAY_CURSOR_INFO, DISPLAY_CURSOR_INFO,
DRAGGABLE_ELEMENT_CLASSNAME, DRAGGABLE_ELEMENT_CLASSNAME,
MODE_MASS_GENERATION, MODE_MASS_GENERATION,
MODE_PAN_VIEW, MODE_PAN_VIEW,
POINTER_HISTORY_SIZE,
ZOOM_IN_FACTOR,
ZOOM_OUT_FACTOR,
} from './config.js'; } from './config.js';
function dispatchEvent(target, eventType, data) {
const ev = new CustomEvent(eventType, {detail: data});
target.dispatchEvent(ev);
}
export class Pointer { export class Pointer {
sim = undefined; sim = undefined;

View File

@ -40,11 +40,11 @@ export class ModeSwitch extends Tool {
button.innerHTML = `<h3>${modeTitle}</h3>`; button.innerHTML = `<h3>${modeTitle}</h3>`;
button.classList.add('wide'); button.classList.add('wide');
button.addEventListener('click', (e) => this.setCurrentMode(modeID)); button.addEventListener('click', () => this.setCurrentMode(modeID));
} }
// First listed mode is the default // First listed mode is the default
const [[currentModeID, _]] = this.modes; const [[currentModeID, ]] = this.modes;
this.setCurrentMode(currentModeID); this.setCurrentMode(currentModeID);
// Add global method to set/get current mode // Add global method to set/get current mode

View File

@ -29,7 +29,7 @@ export class PlayPause extends Tool {
} }
}); });
playButton.addEventListener('click', (e) => { playButton.addEventListener('click', () => {
if (!this.playing) { if (!this.playing) {
this.playing = true; this.playing = true;
pauseButton.style.opacity = '100%'; pauseButton.style.opacity = '100%';
@ -43,6 +43,6 @@ export class PlayPause extends Tool {
} }
set playing(playing) { set playing(playing) {
return this.sim.playing = playing; this.sim.playing = playing;
} }
} }

View File

@ -25,7 +25,7 @@ export class Toolbar {
frame() { frame() {
for (let tool in this.tools) { for (let tool in this.tools) {
// TODO: tool.frame() // TODO: tool.frame()
tool.frame();
} }
} }
} }