1
0
Fork 0

Remove stat set event

This commit is contained in:
Pabloader 2026-05-12 07:51:16 +00:00
parent bfb4979c6b
commit ec8cff15ac
2 changed files with 0 additions and 31 deletions

View File

@ -42,19 +42,11 @@ export class Stat<T = {}> extends Component<StatState & T> {
@action
set(value: number) {
const prev = this.value;
this.state.base = value;
const next = this.value;
if (prev !== next) {
this.emit('set', { prev, value: next });
}
}
applyModifier(delta: number, field: 'value' | 'max' | 'min' = 'value'): void {
const prev = this.value;
this.state.modifierSums[field] += delta;
const next = this.value;
if (prev !== next) this.emit('set', { prev, value: next });
}
removeModifier(delta: number, field: 'value' | 'max' | 'min' = 'value'): void {

View File

@ -109,29 +109,6 @@ describe('Stat — value / base / modifiers', () => {
s.applyModifier(-100);
expect(s.value).toBe(0);
});
it("set() emits 'set' event with prev and value", () => {
const w = world();
const e = w.createEntity();
e.add(new Stat({ value: 10 }), 's');
const s = e.get(Stat, 's')!;
const events: unknown[] = [];
e.on('Stat(s).set', ({ data }) => events.push(data));
s.set(20);
expect(events).toEqual([{ prev: 10, value: 20 }]);
});
it("set() does not emit 'set' when value unchanged", () => {
const w = world();
const e = w.createEntity();
e.add(new Stat({ value: 10, min: 0 }), 's');
const s = e.get(Stat, 's')!;
const events: unknown[] = [];
e.on('Stat(s).set', ({ data }) => events.push(data));
s.set(-100); // clamped to 0, still changes
s.set(-200); // still 0, no change
expect(events.length).toBe(1);
});
});
describe('Health', () => {