From 608bdde8c8135025f55c4d8d6993ff4c60576355 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 17 Feb 2021 15:36:43 +0100 Subject: [PATCH] New Preserves float interface --- packages/core/package.json | 2 +- packages/html/examples/flappy-bird/src/index.ts | 12 ++++++------ packages/timer/src/index.ts | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 55ae610..8c9d9b9 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -22,6 +22,6 @@ "types": "lib/index.d.ts", "author": "Tony Garnock-Jones ", "dependencies": { - "preserves": "0.5.2" + "preserves": "0.5.3" } } diff --git a/packages/html/examples/flappy-bird/src/index.ts b/packages/html/examples/flappy-bird/src/index.ts index 8eaecf2..037d759 100644 --- a/packages/html/examples/flappy-bird/src/index.ts +++ b/packages/html/examples/flappy-bird/src/index.ts @@ -16,7 +16,7 @@ // along with this program. If not, see . //--------------------------------------------------------------------------- -import { $QuitDataspace, Double, Facet, Inbound, Outbound } from '@syndicate-lang/core'; +import { $QuitDataspace, Double, Facet, Inbound, Outbound, floatValue } from '@syndicate-lang/core'; activate import { WindowEvent, template, Anchor } from '@syndicate-lang/html'; activate import { PeriodicTick } from '@syndicate-lang/timer'; @@ -77,7 +77,7 @@ function spawnGame(thisFacet: Facet) { field ypos: number = 312; field yvel: number = 0; - assert Position(new Double(this.xpos), new Double(this.ypos)); + assert Position(Double(this.xpos), Double(this.ypos)); assert Outbound( ui.html('#board-area', @@ -99,7 +99,7 @@ function spawnGame(thisFacet: Facet) { on message Inbound(WindowEvent('+click', $_e)) => this.yvel = -10; const ms_per_tick = 1000.0 / 60; - on message Inbound(PeriodicTick(new Double(ms_per_tick))) => { + on message Inbound(PeriodicTick(Double(ms_per_tick))) => { this.xpos += 0.15 * ms_per_tick; this.ypos = (this.ypos + this.yvel); this.yvel += ms_per_tick * 0.05; @@ -110,7 +110,7 @@ function spawnGame(thisFacet: Facet) { spawn named 'border-scroll' { let ui = new Anchor(); field pos: number = 0; - on asserted Position($xpos, _) => this.pos = Double.unwrap(xpos as any) % 23; + on asserted Position($xpos, _) => this.pos = floatValue(xpos) % 23; assert Outbound(ui.html( '#board-area', template`
`, @@ -138,10 +138,10 @@ function spawnGame(thisFacet: Facet) { on start react { stop on (this.xpos <= 0) send message IncreaseScore(); }; field xpos: number = xlocation; - on asserted Position($xpos, _) => this.xpos = xlocation - Double.unwrap(xpos as any); + on asserted Position($xpos, _) => this.xpos = xlocation - floatValue(xpos); on asserted Position($xpos, $ypos) => { - if (touchingPillar(Double.unwrap(xpos as any), Double.unwrap(ypos as any))) { + if (touchingPillar(floatValue(xpos), floatValue(ypos))) { react { assert GameOver(); } diff --git a/packages/timer/src/index.ts b/packages/timer/src/index.ts index 1c181ba..6a1f536 100644 --- a/packages/timer/src/index.ts +++ b/packages/timer/src/index.ts @@ -16,7 +16,7 @@ // along with this program. If not, see . //--------------------------------------------------------------------------- -import { preserves, Observe, Dataspace, Float, Facet } from "@syndicate-lang/core"; +import { preserves, Observe, Dataspace, floatValue, Facet } from "@syndicate-lang/core"; export message type PeriodicTick(intervalMS); export assertion type TimeLaterThan(deadlineMS); @@ -38,7 +38,7 @@ boot { on start { handle = setInterval(thisFacet.wrapExternal((thisFacet) => { send message PeriodicTick(intervalMS); - }), Float.unwrap(intervalMS as any)); + }), floatValue(intervalMS as any)); } on stop { if (handle) { @@ -59,7 +59,7 @@ boot { let handle: any | null = null; let finish: (() => void) | null = thisFacet.actor.dataspace.backgroundTask(); on start { - let delta = Float.unwrap(deadlineMS as any) - (+(new Date())); + let delta = floatValue(deadlineMS as any) - (+(new Date())); handle = setTimeout(thisFacet.wrapExternal((thisFacet) => { handle = null; if (finish) finish();