-
Notifications
You must be signed in to change notification settings - Fork 2
/
Subscribe.verse
88 lines (66 loc) · 2.27 KB
/
Subscribe.verse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using { /Verse.org/Concurrency }
using { /Fortnite.com/AI }
using { /Verse.org/Simulation }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Random }
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation/Tags }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/UI }
using { /Verse.org/Assets }
using { /Fortnite.com/Devices/CreativeAnimation }
custom_cancelable<public> := class:
var Canceled : logic = false
CancelEvent : event() = event(){}
Cancel():void=
set Canceled = true
CancelEvent.Signal()
custom_subscribable<public>(t:type)<computes> := class<public>(awaitable(t)):
InnerEvent : event(t) = event(t){}
Subscribe(Callback:type {__(:t):void}):custom_cancelable=
Cancelable := custom_cancelable{}
spawn{_WaitForEvent(Callback, Cancelable)}
Cancelable
_WaitForEvent(Callback:type {__(:t):void}, Cancelable: custom_cancelable)<suspends>:void=
race:
# Wait for payload to be sent
loop:
Payload := InnerEvent.Await()
# Just in case
if(not Cancelable.Canceled?):
Callback(Payload)
else:
break # Just in case
# Cancelable got canceled
Cancelable.CancelEvent.Await()
Signal<public>(Payload:t):void =
InnerEvent.Signal(Payload)
Await<override>()<suspends>:t=
InnerEvent.Await()
CustomSubscribe := class:
var TrackedProps: []creative_prop =array{}
var Trigger:logic =false
Subscribe(Prop:creative_prop):void=
set TrackedProps += array{Prop}
Cancel():void=
set Trigger = true
StartUpdate(TrackingProp:creative_prop)<suspends>:void=
loop:
Sleep(0.1)
if(TrackingProp.GetTransform().Scale.Z=2.0):
for(Prop:TrackedProps):
Prop.Dispose()
if(Trigger = true):
break
Test()<suspends>:void=
Prop1 := creative_prop{}
Prop2 := creative_prop{}
Prop3 := creative_prop{}
Sub := CustomSubscribe{}
Sub.Subscribe(Prop1)
Sub.Subscribe(Prop2)
Sub.Subscribe(Prop3)
spawn{Sub.StartUpdate(Prop1)}
Sleep(1.0)
Sub.Cancel()