· 5 years ago · May 19, 2020, 08:50 PM
1return function(Madwork)
2--[[
3{Madwork}
4
5-[ProfileService]---------------------------------------
6 DataStore profiles - universal session-locked savable table API
7
8 WARNINGS FOR "Profile.Data" VALUES:
9 ! Do not create numeric tables with gaps - attempting to replicate such tables will result in an error;
10 ! Do not create mixed tables (some values indexed by number and others by string key), as only
11 the data indexed by number will be replicated.
12 ! Do not index tables by anything other than numbers and strings.
13 ! Do not reference Roblox Instances
14 ! Do not reference userdata (Vector3, Color3, CFrame...) - Serialize userdata before referencing
15 ! Do not reference functions
16
17 Functions:
18
19 ProfileService.GetProfileStore(profile_store_name, profile_template) --> [ProfileStore]
20
21 * Parameter description for "ProfileService.GetProfileStore()":
22
23 profile_store_name [string] -- DataStore name
24 profile_template []:
25 {} [table] -- Profiles will default to given table (hard-copy) when no data was saved previously
26 "StandardPlayerProfile" [string] -- Default to standard player profile table (SETTINGS.StandardPlayerProfile)
27
28 Methods [ProfileStore]:
29
30 ProfileStore:LoadProfileAsync(profile_key, not_released_handler) --> [Profile / nil] not_released_handler(game_place_id, game_job_id)
31 ProfileStore:GlobalUpdateProfileAsync(profile_key, update_handler) --> [GlobalUpdates] (update_handler(GlobalUpdates))
32
33 ProfileStore:ViewProfileAsync(profile_key) --> [Profile] -- Notice: Profile object methods will not be available
34
35 * Parameter description for "ProfileStore:LoadProfileAsync()":
36
37 profile_key [string] -- DataStore key
38 not_released_handler [function] (game_place_id, game_job_id) --> [string] ("Repeat", "Cancel", "ForceLoad")
39 -- "not_released_handler" will be triggered in cases where the profile is not released by a session. This
40 function may yield for as long as desirable and must return one of three string values:
41 ["Repeat"] - ProfileService will repeat the profile loading proccess and may trigger the release handler again
42 ["Cancel"] - ProfileStore:LoadProfileAsync() will immediately return nil
43 ["ForceLoad"] - ProfileService will repeat the profile loading call, but will return Profile object afterwards
44 and release the profile for another session that has loaded the profile
45
46 * Parameter description for "ProfileStore:GlobalUpdateProfileAsync()":
47
48 profile_key [string] -- DataStore key
49 update_handler [function] (GlobalUpdates) -- This function gains access to GlobalUpdates object methods
50 (update_handler can't yield)
51
52 Members [Profile]:
53
54 Profile.Data [table] -- Writable table that gets saved automatically and once the profile is released
55 Profile.MetaData [table] (Read-only) -- Information about this profile
56
57 Profile.MetaData.ProfileCreateTime [number] -- os.time() timestamp of profile creation
58 Profile.MetaData.SessionLoadCount [number] -- Amount of times the profile was loaded
59 Profile.MetaData.ActiveSession [table] {game_place_id, game_job_id} / nil -- Set to a session link if a
60 game session is currently having this profile loaded; nil if released
61
62 Profile.PurchaseIds [table] (Read-only)
63
64 Profile.GlobalUpdates [GlobalUpdates]
65
66 Methods [Profile]:
67
68 Profile:PurchaseIdCheck(purchase_id) --> [string] "GrantProduct" / "NoAction" / "PurchaseConfirmed"
69 -- Calling this method in a loop (every second) will return an action value to handle product purchases by
70 (Remember that MarketplaceService.ProcessReceipt is allowed to yield)
71
72 Profile:ListenToRelease(listener) --> [ScriptConnection] () -- WARNING: Profiles can be released externally if another session
73 force-loads this profile - use :ListenToRelease() to handle player leaving and only call :Release() on Player.PlayerRemoving
74 Profile:Release() -- Call after the session has finished working with this profile
75
76 Methods [GlobalUpdates]:
77
78 -- ALWAYS PUBLIC:
79 GlobalUpdates:GetActiveUpdates() --> [table] {{update_id, update_data}, ...}
80 GlobalUpdates:GetLockedUpdates() --> [table] {{update_id, update_data}, ...}
81
82 -- ONLY WHEN FROM "Profile.GlobalUpdates":
83 GlobalUpdates:ListenToNewActiveUpdate(listener) --> [ScriptConnection] listener(update_id, update_data)
84 GlobalUpdates:LockUpdate(update_id)
85 GlobalUpdates:ListenToNewLockedUpdate(listener) --> [ScriptConnection] listener(update_id, update_data)
86 GlobalUpdates:ClearLockedUpdate(update_id)
87
88 -- EXPOSED TO "update_handler" DURING ProfileStore:GlobalUpdateProfileAsync() CALL
89 GlobalUpdates:AddActiveUpdate(update_data)
90 GlobalUpdates:ChangeActiveUpdate(update_id, update_data)
91 GlobalUpdates:ClearActiveUpdate(update_id)
92
93--]]
94
95local SETTINGS = {
96
97 -- Madwork 1.1 player profile structure standard:
98 StandardPlayerProfile = {
99 ["Currency"] = { -- Dictionary of currencies (integers)
100 --[[
101 Ruby = 0,
102 Coin = 0,
103 ...
104 --]]
105 },
106 ["Collectibles"] = { -- Stackable and usually tradable items
107 --[[
108 ["ItemType"] = {
109 {unique_inventory_id, item_name, {tags (tag_name=value)}, count},
110 ...
111 },
112 ...
113 --]]
114 },
115 ["Progress"] = { -- Dictionary of various player progress data
116 --[[
117 Unlockable = {},
118 Boost = {},
119 PersistenceTags = {},
120 Consumables = {},
121 --]]
122 },
123 ["Totals"] = { -- Dictionary of integer values that are only incremented
124 --[[
125 robux_spent = 0,
126 rubies_spent = 0,
127 coins_spent = 0,
128 rubies_received_game = 0,
129 coins_received_game = 0,
130 rubies_bought = 0,
131 coins_bought = 0,
132 ...
133 --]]
134 },
135 ["Selection"] = { -- Dictionary of player selections (Equipped item, radio sound id, etc.)
136 --[[
137 ["selection_name"] = selection_data,
138 --]]
139 },
140 ["Settings"] = { -- Dictionary of player settings (Graphics quality, volume, accessibility, etc.)
141 --[[
142 ["setting_name"] = setting_data,
143 --]]
144 },
145 ["Tags"] = { -- Dictionary of various tags applied to this user
146 --[[
147 ["tag_name"] = true,
148 ...
149 --]]
150 },
151 }
152
153}
154
155----- Service Table -----
156
157local ProfileService = {
158
159}
160
161----- Loaded Services & Modules -----
162
163----- Private Variables -----
164
165----- Utils -----
166
167----- Private functions -----
168
169----- Public functions -----
170
171----- Initialize -----
172
173----- Connections -----
174
175return ProfileService
176
177---***---
178end