-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSaveWithoutSpanwers.verse
120 lines (90 loc) · 3.79 KB
/
SaveWithoutSpanwers.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Simulation/Tags }
using { /Fortnite.com/UI }
using { /Verse.org/Colors }
using { /UnrealEngine.com/Temporary/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
#Gloomcraft Code https://gloomcraft.site/Shop.html
#Gloomcraft Video https://www.youtube.com/watch?v=pLnpfoXFR3c&t=77s
#Verse Documentation https://dev.epicgames.com/documentation/en-us/uefn/using-persistable-data-in-verse
TextForUI< localizes>(InText : string) : message = "Coins: {InText}"
player_data := class< final>< persistable>{
Gold : int = 0
#Initialize Stats for current players
InitializeAllPlayers(Players:[]player):void=
for(Player: Players):
InitializePlayer(Player)
#Initialize for one player
InitializePlayer(Player:player):void=
if:
not Data[Player]
set Data[Player] = player_data{}
}
player_data_update< constructor>(OldStat:player_data)< transacts> := player_data {
Gold := OldStat.Gold
}
var Data:weak_map(player, player_data) = map{}
# A Verse-authored creative device that can be placed in a level
Persist_without_SaveDevice := class(creative_device):
var NonSpawnerPlayerWay :player_data=player_data{}
@editable Increase : button_device = button_device{}
@editable Decrease : button_device = button_device{}
InitPlayers():void=
AllPlayers := GetPlayspace().GetPlayers()
NonSpawnerPlayerWay.InitializeAllPlayers(AllPlayers)
UpdateValues(PlayerObj : player)< suspends>: void = {
CoinsBlock : text_block = text_block {DefaultTextColor := MakeColorFromHex("#38c92a")}
if (PlayerUi := GetPlayerUI[PlayerObj]) {
MyCanvas : canvas = canvas:
Slots := array:
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.25}, Maximum := vector2{X := 0.5, Y := 0.25}}
Alignment := vector2{X := 0.5, Y := 0.0}
SizeToContent := true
Widget := CoinsBlock
PlayerUi.AddWidget(MyCanvas)
}
loop:
Sleep(0.1)
if (PlayerData := Data[PlayerObj]) {
CoinsBlock.SetText(TextForUI(ToString(PlayerData.Gold)))
}
}
IncreaseGold(Agent : agent) : void = {
if (PlayerObj := player[Agent]) {
if (PlayerData := Data[PlayerObj]) {
if:
OldData := Data[PlayerObj]
set Data[PlayerObj] = player_data{
player_data_update< constructor>(OldData)
Gold := OldData.Gold + 1
}
then:
Print("Gold Increased")
spawn{UpdateValues(PlayerObj)}
}
}
}
DecreaseGold(Agent : agent) : void = {
if (PlayerObj := player[Agent]) {
if (PlayerData := Data[PlayerObj]) {
if:
OldData := Data[PlayerObj]
set Data[PlayerObj] = player_data{
player_data_update< constructor>(OldData)
Gold := OldData.Gold - 1
}
then:
Print("Gold Decreased")
spawn{UpdateValues(PlayerObj)}
}
}
}
# Runs when the device is started in a running game
OnBegin< override>()< suspends>:void=
InitPlayers()
Increase.InteractedWithEvent.Subscribe(IncreaseGold)
Decrease.InteractedWithEvent.Subscribe(DecreaseGold)