Skip to content

Commit 852f502

Browse files
committed
fix:! improve timer api
1 parent 001e321 commit 852f502

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

examples/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ async function main() {
5151
// this will be added everytime it's called so you can modify it's value
5252
const myChangingBool = aChild.addBool(false)
5353
const myChangingInt = aChild.addInt(0, { name: 'A cool counter' })
54-
const myTimer = aChild.addTimer(250, { SetTrue: [myChangingBool] })
54+
const myTimer = aChild.addTimer({
55+
time: { ms: 250 },
56+
outputs: { SetTrue: myChangingBool }
57+
})
5558

5659
// get an existing entity
5760
// note: my_entity_id is neither a valid entity id nor existing in the agent47_default.entitytemplate

examples/outfit.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ async function main() {
77
const entity = patch.addEntity({ parent: CommonRoots.Agent47, ...CommonPaths.Entity })
88

99
entity.setHeroOutfit('4d561409-84d4-4dae-abd2-852cf93471bb', modifier => ({
10-
In: entity.addTimer(100, {
11-
SetOutfit: modifier
10+
In: entity.addTimer({
11+
time: { ms: 100 },
12+
outputs: {
13+
SetOutfit: modifier
14+
}
1215
})
1316
}))
1417

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quickentity-script",
3-
"version": "2.2.2",
3+
"version": "2.3.0",
44
"description": "An easier way of writing QN patches with code",
55
"main": "dist/src/lib.js",
66
"types": "./dist/src/index.d.ts",

src/patches/entity/base.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,17 @@ export class PatchEntity {
264264
})
265265
}
266266

267-
public addTimer(timeMS: number, outputs: IEventTriggers, recursive = false, entityConfig: Partial<ICreateChildEntity> = {}) {
268-
let { name, id } = entityConfig
267+
public addTimer(options: {
268+
time: Partial<{
269+
ms: number,
270+
seconds: number,
271+
minutes: number
272+
}>,
273+
outputs: IEventTriggers,
274+
recursive?: boolean,
275+
entityConfig?: Partial<ICreateChildEntity>
276+
}) {
277+
let { name, id } = options.entityConfig ?? {}
269278
if(!name) name = 'Timer ' + generateRandomEntityName()
270279
if(!id) id = generateRandomEntityID()
271280
return this.addChild({
@@ -275,7 +284,7 @@ export class PatchEntity {
275284
properties: {
276285
'Delay time (ms)': {
277286
type: 'int32',
278-
value: timeMS
287+
value: (options.time.ms ?? 0) + (options.time.seconds ?? 0) * 1000 + (options.time.minutes ?? 0) * 60 * 1000
279288
},
280289
m_bEnabled: {
281290
type: 'bool',
@@ -284,8 +293,8 @@ export class PatchEntity {
284293
},
285294
events: {
286295
Out: {
287-
...outputsToEvent(outputs),
288-
In: recursive ? id : []
296+
...outputsToEvent(options.outputs),
297+
In: options.recursive ? id : []
289298
}
290299
}
291300
})

src/patches/entity/hero.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ PatchEntity.prototype.getHero = function(triggers: IEventTriggers, entityConfig?
2323
})
2424

2525
heroStandIn.addOnGameStartListener({
26-
In: heroStandIn.addTimer(1000, {
27-
GetHero: heroStandIn
26+
In: heroStandIn.addTimer({
27+
time: { seconds: 1 },
28+
outputs: {
29+
GetHero: heroStandIn
30+
}
2831
})
2932
})
3033

test/patch.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ describe('Simple Patch', () => {
7878
})
7979

8080
const someBool = root.addBool(false)
81-
const timer = root.addTimer(1250, { SetTrue: someBool })
81+
const timer = root.addTimer({
82+
time: { seconds: 1, ms: 250 },
83+
outputs: { SetTrue: someBool }
84+
})
8285

8386
it('should add timers', () => {
8487
const build = patch.buildPatch()

0 commit comments

Comments
 (0)