cluaupp 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/README.md +10 -5
- package/api/CHANGELOG.md +3 -0
- package/api/chat.js +74 -0
- package/api/fixtures/roblox/README.md +6 -0
- package/api/fixtures/roblox/aux/sample.d.luau +6 -0
- package/api/fixtures/roblox/mini/Mini-API-Dump.json +72 -0
- package/api/generated/bench-latest.json +39 -0
- package/api/generated/capability-profile.json +76 -0
- package/api/generated/lsp-index.json +1 -0
- package/api/generated/luau/classes.d.luau +11221 -0
- package/api/generated/luau/datatypes.d.luau +327 -0
- package/api/generated/luau/enums.d.luau +4918 -0
- package/api/generated/luau/globals.d.luau +12 -0
- package/api/manifests/roblox-target.manifest.json +22 -0
- package/api/normalized/roblox-target.profile.json +237461 -0
- package/api/overrides/classes.json +8 -0
- package/api/overrides/compatibility.json +9 -0
- package/api/overrides/datatypes.json +1579 -0
- package/api/overrides/enums.json +8 -0
- package/api/overrides/globals.json +8 -0
- package/api/overrides/type-mappings.json +9 -0
- package/api/roblox-api.lock.json +9 -0
- package/data/Mini-API-Dump.json +1 -0
- package/editors/vscode/README.md +12 -10
- package/editors/vscode/extension.js +82 -0
- package/editors/vscode/icons/axiom.svg +4 -0
- package/editors/vscode/icons/bloom.svg +5 -0
- package/editors/vscode/icons/helm.svg +4 -0
- package/editors/vscode/icons/hive.svg +5 -0
- package/editors/vscode/icons/mint.svg +4 -0
- package/editors/vscode/icons/shift.svg +6 -0
- package/editors/vscode/language-configuration-schema.json +24 -0
- package/editors/vscode/package.json +172 -12
- package/editors/vscode/snippets/axiom.json +12 -0
- package/editors/vscode/snippets/bloom.json +12 -0
- package/editors/vscode/snippets/helm.json +12 -0
- package/editors/vscode/snippets/hive.json +12 -0
- package/editors/vscode/snippets/mint.json +12 -0
- package/editors/vscode/snippets/shift.json +17 -0
- package/editors/vscode/syntaxes/axiom.tmLanguage.json +5 -0
- package/editors/vscode/syntaxes/bloom.tmLanguage.json +5 -0
- package/editors/vscode/syntaxes/helm.tmLanguage.json +5 -0
- package/editors/vscode/syntaxes/hive.tmLanguage.json +5 -0
- package/editors/vscode/syntaxes/mint.tmLanguage.json +5 -0
- package/editors/vscode/syntaxes/schema.tmLanguage.json +89 -0
- package/editors/vscode/syntaxes/shift.tmLanguage.json +5 -0
- package/examples/game/.cluaupp/compile-cache/ReplicatedStorage__Shared__Constants__Datas__TemplateData.clh.json +1 -0
- package/examples/game/.cluaupp/compile-cache/ServerScriptService__Boot__DataBoot.server.clpp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/ServerScriptService__Configuration__ServerConfig.clp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/ServerScriptService__Handlers__Guard.server.clpp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/ServerScriptService__Handlers__PlayerHandler.server.clpp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/StarterPlayer__StarterCharacterScripts__Character__CharacterReady.client.clpp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/StarterPlayer__StarterPlayerScripts__Controllers__DataController.client.clpp.json +1 -0
- package/examples/game/.cluaupp/compile-cache/index.json +12 -0
- package/examples/game/.cluaupp/datamodel-profile.json +94 -0
- package/examples/game/.vscode/settings.json +12 -1
- package/examples/game/include/clpp/datatypes.clh +337 -373
- package/examples/game/include/clpp/generated/datamodel.clh +25 -0
- package/examples/game/include/clpp/generated/enums.clh +1 -1
- package/examples/game/include/clpp/generated/instances.clh +41135 -41064
- package/examples/game/include/clpp/libs/axiom.clh +1 -1
- package/examples/game/include/clpp/libs/math.clh +14 -0
- package/examples/game/include/clpp/libs/spring.clh +17 -0
- package/examples/game/include/clpp/libs/ward.clh +1 -0
- package/examples/game/include/clpp/roblox.clh +3 -4
- package/examples/game/libs/ArrayIndexer/init.luau +209 -0
- package/examples/game/libs/Axiom/init.luau +608 -0
- package/examples/game/libs/Bloom/init.luau +433 -0
- package/examples/game/libs/Coil/init.luau +215 -0
- package/examples/game/libs/Crest/init.luau +426 -0
- package/examples/game/libs/Echo/init.luau +417 -0
- package/examples/game/libs/Ember/init.luau +365 -0
- package/examples/game/libs/Flare/init.luau +717 -0
- package/examples/game/libs/Gleam/init.luau +729 -0
- package/examples/game/libs/Guide/init.luau +215 -0
- package/examples/game/libs/Helm/init.luau +377 -0
- package/examples/game/libs/Hive/init.luau +241 -0
- package/examples/game/libs/Keep/Client.luau +114 -0
- package/examples/game/libs/Keep/Data.luau +883 -0
- package/examples/game/libs/Keep/Engine.luau +211 -0
- package/examples/game/libs/Keep/Enum.luau +6 -0
- package/examples/game/libs/Keep/Enums.luau +10 -0
- package/examples/game/libs/Keep/Path.luau +236 -0
- package/examples/game/libs/Keep/Replicator.luau +298 -0
- package/examples/game/libs/Keep/Server.luau +251 -0
- package/examples/game/libs/Keep/Store.luau +652 -0
- package/examples/game/libs/Keep/Trade.luau +455 -0
- package/examples/game/libs/Keep/init.luau +205 -0
- package/examples/game/libs/Lens/init.luau +609 -0
- package/examples/game/libs/Mint/init.luau +279 -0
- package/examples/game/libs/Net/init.luau +156 -0
- package/examples/game/libs/Net/src/codec.luau +224 -0
- package/examples/game/libs/Occlude/init.luau +117 -0
- package/examples/game/libs/Pin/init.luau +309 -0
- package/examples/game/libs/Promise/LICENSE +21 -0
- package/examples/game/libs/Promise/_impl/LICENSE +21 -0
- package/examples/game/libs/Promise/_impl/init.lua +1991 -0
- package/examples/game/libs/Promise/init.lua +1990 -0
- package/examples/game/libs/Promise/init.luau +13 -0
- package/examples/game/libs/Promise/types.luau +46 -0
- package/examples/game/libs/Roster/init.luau +686 -0
- package/examples/game/libs/SOURCES.md +31 -0
- package/examples/game/libs/Shift/init.luau +238 -0
- package/examples/game/libs/Spark/init.luau +487 -0
- package/examples/game/libs/Stage/init.luau +178 -0
- package/examples/game/libs/Sweep/init.luau +259 -0
- package/examples/game/libs/Trace/init.luau +213 -0
- package/examples/game/libs/Ward/init.luau +211 -0
- package/examples/game/out/ReplicatedStorage/Shared/Constants/Datas/TemplateData.luau +29 -0
- package/examples/game/out/ReplicatedStorage/Shared/Constants/Datas/TemplateData.luau.map.json +13 -0
- package/examples/game/out/ReplicatedStorage/Shared/Net/Net.luau +83 -0
- package/examples/game/out/ReplicatedStorage/Shared/Net/Net.luau.map.json +13 -0
- package/examples/game/out/ServerScriptService/Boot/DataBoot.server.luau +18 -0
- package/examples/game/out/ServerScriptService/Boot/DataBoot.server.luau.map.json +13 -0
- package/examples/game/out/ServerScriptService/Configuration/ServerConfig.luau +14 -0
- package/examples/game/out/ServerScriptService/Configuration/ServerConfig.luau.map.json +13 -0
- package/examples/game/out/ServerScriptService/Handlers/Guard.server.luau +15 -0
- package/examples/game/out/ServerScriptService/Handlers/Guard.server.luau.map.json +13 -0
- package/examples/game/out/ServerScriptService/Handlers/PlayerHandler.server.luau +50 -0
- package/examples/game/out/ServerScriptService/Handlers/PlayerHandler.server.luau.map.json +13 -0
- package/examples/game/out/StarterPlayer/StarterCharacterScripts/Character/CharacterReady.client.luau +12 -0
- package/examples/game/out/StarterPlayer/StarterCharacterScripts/Character/CharacterReady.client.luau.map.json +13 -0
- package/examples/game/out/StarterPlayer/StarterPlayerScripts/Controllers/DataController.client.luau +16 -0
- package/examples/game/out/StarterPlayer/StarterPlayerScripts/Controllers/DataController.client.luau.map.json +13 -0
- package/examples/game/src/ReplicatedStorage/Shared/Net/Net.clh +26 -0
- package/examples/game/src/ServerScriptService/Boot/DataBoot.server.clpp +1 -1
- package/examples/game/src/ServerScriptService/Handlers/PlayerHandler.server.clpp +1 -1
- package/examples/game/stylua.toml +9 -0
- package/generated/api/build-profile.js +115 -0
- package/generated/api/cache.js +44 -0
- package/generated/api/coverage.js +32 -0
- package/generated/api/diff.js +125 -0
- package/generated/api/generators/clpp-headers.js +353 -0
- package/generated/api/generators/docs-reference.js +7 -0
- package/generated/api/generators/lsp-index.js +81 -0
- package/generated/api/generators/luau-defs.js +94 -0
- package/generated/api/ide.js +76 -0
- package/generated/api/identifier.js +47 -0
- package/generated/api/index.js +324 -0
- package/generated/api/loader.js +57 -0
- package/generated/api/merge.js +88 -0
- package/generated/api/model.js +5 -0
- package/generated/api/normalize.js +231 -0
- package/generated/api/overrides-validate.js +58 -0
- package/generated/api/perf.js +12 -0
- package/generated/api/registry.js +136 -0
- package/generated/api/release.js +44 -0
- package/generated/api/resolver.js +250 -0
- package/generated/api/sources/aux-types-diff.js +75 -0
- package/generated/api/sources/client-tracker.js +11 -0
- package/generated/api/sources/creator-docs.js +42 -0
- package/generated/api/sources/luau-types.js +34 -0
- package/generated/api/sources/mini-dump.js +17 -0
- package/generated/api/sources/studio-api.js +8 -0
- package/generated/api/sources/studio-apiv2.js +11 -0
- package/generated/api/sources/studio-full-api.js +8 -0
- package/generated/api/studio-smoke.js +80 -0
- package/generated/api/type-parse.js +49 -0
- package/generated/api/understander.js +51 -0
- package/generated/api/validate.js +135 -0
- package/generated/api-cli.js +421 -0
- package/generated/cli.js +16 -5
- package/generated/clpp/contract.js +3 -3
- package/generated/clpp/format-luau.js +236 -0
- package/generated/clpp/index.js +13 -1
- package/generated/clpp/modules.js +227 -0
- package/generated/clpp/postprocess.js +86 -5
- package/generated/clpp/rewrite-janitor.js +145 -0
- package/generated/clpp/runner.js +14 -2
- package/generated/compile.js +82 -0
- package/generated/flare/parse.js +12 -1
- package/generated/intellisense.js +57 -1
- package/generated/native/index.js +217 -16
- package/generated/target/authority-check.js +136 -0
- package/generated/target/authority-graph.js +74 -0
- package/generated/target/build-cache.js +112 -0
- package/generated/target/capabilities.js +89 -0
- package/generated/target/capability-profile.js +30 -0
- package/generated/target/component-contracts.js +60 -0
- package/generated/target/context-check.js +160 -0
- package/generated/target/datamodel-check.js +170 -0
- package/generated/target/datamodel-generate.js +74 -0
- package/generated/target/datamodel.js +233 -0
- package/generated/target/diagnostics.js +63 -0
- package/generated/target/doctor.js +152 -0
- package/generated/target/flare-version.js +58 -0
- package/generated/target/get-service.js +69 -0
- package/generated/target/lifetime-check.js +47 -0
- package/generated/target/luau-stamp.js +39 -0
- package/generated/target/optimizer-advise.js +88 -0
- package/generated/target/optimizer-apply.js +44 -0
- package/generated/target/optimizer-soa.js +254 -0
- package/generated/target/parallel-check.js +136 -0
- package/generated/target/pgo.js +148 -0
- package/generated/target/project-docs.js +69 -0
- package/generated/target/project-graph.js +71 -0
- package/generated/target/roblox.js +63 -0
- package/generated/target/security-check.js +41 -0
- package/generated/target/source-map.js +25 -0
- package/generated/target/studio-bridge.js +112 -0
- package/generated/utils/project.js +178 -8
- package/generated/utils/rojo-mapper.js +11 -3
- package/include/clpp/datatypes.clh +337 -373
- package/include/clpp/generated/enums.clh +1 -1
- package/include/clpp/generated/instances.clh +41135 -41064
- package/include/clpp/libs/axiom.clh +1 -1
- package/include/clpp/libs/hive.clh +1 -0
- package/include/clpp/libs/keep.clh +2 -0
- package/include/clpp/libs/math.clh +14 -0
- package/include/clpp/libs/spring.clh +17 -0
- package/include/clpp/libs/ward.clh +1 -0
- package/include/clpp/roblox.clh +3 -4
- package/package.json +10 -3
- package/plugins/CluauppNav/Plugin.luau +207 -0
- package/plugins/CluauppNav/ProfileLogger.luau +27 -0
- package/plugins/CluauppNav/README.md +24 -0
- package/runtime/Axiom/init.luau +10 -7
- package/runtime/Coil/init.luau +8 -2
- package/runtime/Crest/init.luau +1 -0
- package/runtime/Flare/init.luau +2 -1
- package/runtime/Gleam/init.luau +15 -4
- package/runtime/Hive/init.luau +36 -14
- package/runtime/Pin/init.luau +5 -2
- package/runtime/Roster/init.luau +2 -0
- package/runtime/Spark/init.luau +3 -0
- package/runtime/Sweep/init.luau +2 -0
- package/runtime/Trace/init.luau +3 -0
- package/runtime/Ward/init.luau +38 -5
- package/scripts/postinstall-editor.js +17 -0
- package/skills/README.md +13 -0
- package/skills/clpp-hive-flare/SKILL.md +79 -0
- package/skills/clpp-language/SKILL.md +123 -0
- package/skills/clpp-language/compiler.md +89 -0
- package/skills/clpp-style/SKILL.md +95 -0
- package/src/api/build-profile.ts +138 -0
- package/src/api/cache.ts +45 -0
- package/src/api/coverage.ts +46 -0
- package/src/api/diff.ts +143 -0
- package/src/api/generators/clpp-headers.ts +377 -0
- package/src/api/generators/docs-reference.ts +11 -0
- package/src/api/generators/lsp-index.ts +106 -0
- package/src/api/generators/luau-defs.ts +98 -0
- package/src/api/ide.ts +87 -0
- package/src/api/identifier.ts +47 -0
- package/src/api/index.ts +269 -0
- package/src/api/loader.ts +60 -0
- package/src/api/merge.ts +126 -0
- package/src/api/model.ts +283 -0
- package/src/api/normalize.ts +257 -0
- package/src/api/overrides-validate.ts +58 -0
- package/src/api/perf.ts +15 -0
- package/src/api/registry.ts +162 -0
- package/src/api/release.ts +47 -0
- package/src/api/resolver.ts +255 -0
- package/src/api/sources/aux-types-diff.ts +81 -0
- package/src/api/sources/client-tracker.ts +10 -0
- package/src/api/sources/creator-docs.ts +37 -0
- package/src/api/sources/luau-types.ts +30 -0
- package/src/api/sources/mini-dump.ts +50 -0
- package/src/api/sources/studio-api.ts +7 -0
- package/src/api/sources/studio-apiv2.ts +10 -0
- package/src/api/sources/studio-full-api.ts +7 -0
- package/src/api/studio-smoke.ts +82 -0
- package/src/api/type-parse.ts +48 -0
- package/src/api/understander.ts +72 -0
- package/src/api/validate.ts +160 -0
- package/src/api-cli.ts +493 -0
- package/src/api.generated.js +37 -22
- package/src/cli.ts +21 -6
- package/src/clpp/contract.ts +34 -3
- package/src/clpp/format-luau.ts +262 -0
- package/src/clpp/index.ts +13 -2
- package/src/clpp/modules.ts +252 -0
- package/src/clpp/postprocess.ts +100 -5
- package/src/clpp/rewrite-janitor.ts +156 -0
- package/src/clpp/runner.ts +14 -2
- package/src/compile.ts +87 -0
- package/src/flare/parse.ts +14 -1
- package/src/flare/types.ts +2 -0
- package/src/intellisense.ts +58 -1
- package/src/native/index.ts +225 -16
- package/src/target/authority-check.ts +162 -0
- package/src/target/authority-graph.ts +80 -0
- package/src/target/build-cache.ts +129 -0
- package/src/target/capabilities.ts +115 -0
- package/src/target/capability-profile.ts +25 -0
- package/src/target/component-contracts.ts +64 -0
- package/src/target/context-check.ts +177 -0
- package/src/target/datamodel-check.ts +188 -0
- package/src/target/datamodel-generate.ts +78 -0
- package/src/target/datamodel.ts +261 -0
- package/src/target/diagnostics.ts +67 -0
- package/src/target/doctor.ts +171 -0
- package/src/target/flare-version.ts +61 -0
- package/src/target/get-service.ts +85 -0
- package/src/target/lifetime-check.ts +45 -0
- package/src/target/luau-stamp.ts +33 -0
- package/src/target/optimizer-advise.ts +93 -0
- package/src/target/optimizer-apply.ts +63 -0
- package/src/target/optimizer-soa.ts +270 -0
- package/src/target/parallel-check.ts +135 -0
- package/src/target/pgo.ts +157 -0
- package/src/target/project-docs.ts +68 -0
- package/src/target/project-graph.ts +75 -0
- package/src/target/roblox.ts +78 -0
- package/src/target/security-check.ts +40 -0
- package/src/target/source-map.ts +36 -0
- package/src/target/studio-bridge.ts +140 -0
- package/src/types.ts +14 -0
- package/src/utils/project.ts +183 -9
- package/src/utils/rojo-mapper.ts +12 -3
- package/stylua.toml +9 -0
- package/templates/game/.vscode/settings.json +7 -1
- package/templates/game/include/clpp/datatypes.clh +337 -373
- package/templates/game/include/clpp/generated/enums.clh +1 -1
- package/templates/game/include/clpp/generated/instances.clh +41135 -41064
- package/templates/game/include/clpp/libs/axiom.clh +1 -1
- package/templates/game/include/clpp/libs/ward.clh +1 -0
- package/templates/game/include/clpp/roblox.clh +3 -4
- package/templates/game/src/ServerScriptService/Boot/DataBoot.server.clpp +1 -1
- package/templates/game/src/ServerScriptService/Handlers/PlayerHandler.server.clpp +1 -1
- package/templates/game/stylua.toml +9 -0
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
--!optimize 2
|
|
2
|
+
--!strict
|
|
3
|
+
-- Keep Store — ProfileStore session contract (MadStudio algorithm), PascalCase, Spark signals.
|
|
4
|
+
-- Improvements: trade messages are first-class; UpdateAsync is serialized per key;
|
|
5
|
+
-- LastSavedData is the receipt source of truth; Mock never touches live DataStores.
|
|
6
|
+
|
|
7
|
+
local DataStoreService = game:GetService("DataStoreService")
|
|
8
|
+
local MessagingService = game:GetService("MessagingService")
|
|
9
|
+
local HttpService = game:GetService("HttpService")
|
|
10
|
+
local RunService = game:GetService("RunService")
|
|
11
|
+
|
|
12
|
+
local Spark = require(script.Parent.Parent.Spark)
|
|
13
|
+
local Trade = require(script.Parent.Trade)
|
|
14
|
+
|
|
15
|
+
local AUTO_SAVE_PERIOD = 300
|
|
16
|
+
local LOAD_REPEAT_PERIOD = 10
|
|
17
|
+
local FIRST_LOAD_REPEAT = 5
|
|
18
|
+
local SESSION_STEAL = 40
|
|
19
|
+
local ASSUME_DEAD = 630
|
|
20
|
+
local START_SESSION_TIMEOUT = 120
|
|
21
|
+
local CRITICAL_STATE_ERROR_COUNT = 5
|
|
22
|
+
local CRITICAL_STATE_ERROR_EXPIRE = 120
|
|
23
|
+
local CRITICAL_STATE_EXPIRE = 120
|
|
24
|
+
local MAX_MESSAGE_QUEUE = 1000
|
|
25
|
+
|
|
26
|
+
local PlaceId = game.PlaceId
|
|
27
|
+
local JobId = if game.JobId ~= "" then game.JobId else "Studio"
|
|
28
|
+
local IsStudio = RunService:IsStudio()
|
|
29
|
+
|
|
30
|
+
local ActiveSessionCheck: { [string]: any } = {}
|
|
31
|
+
local AutoSaveList: { any } = {}
|
|
32
|
+
local AutoSaveIndex = 1
|
|
33
|
+
local LastAutoSave = os.clock()
|
|
34
|
+
local IssueQueue: { number } = {}
|
|
35
|
+
local UpdateQueue: { [string]: { any } } = {}
|
|
36
|
+
local ActiveProfileLoadJobs = 0
|
|
37
|
+
local ActiveProfileSaveJobs = 0
|
|
38
|
+
local CriticalStateStart = 0
|
|
39
|
+
local MockStore: { [string]: any } = {}
|
|
40
|
+
local UserMockStore: { [string]: any } = {}
|
|
41
|
+
local MockFlag = false
|
|
42
|
+
|
|
43
|
+
local Store = {}
|
|
44
|
+
Store.__index = Store
|
|
45
|
+
Store.IsClosing = false
|
|
46
|
+
Store.IsCriticalState = false
|
|
47
|
+
Store.OnError = Spark.new()
|
|
48
|
+
Store.OnOverwrite = Spark.new()
|
|
49
|
+
Store.OnCriticalToggle = Spark.new()
|
|
50
|
+
Store.DataStoreState = "NotReady"
|
|
51
|
+
|
|
52
|
+
local function deepCopy(value: any): any
|
|
53
|
+
if typeof(value) ~= "table" then
|
|
54
|
+
return value
|
|
55
|
+
end
|
|
56
|
+
local out = {}
|
|
57
|
+
for key, item in value do
|
|
58
|
+
out[key] = deepCopy(item)
|
|
59
|
+
end
|
|
60
|
+
return out
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
local function reconcile(data: any, template: any)
|
|
64
|
+
if typeof(template) ~= "table" then
|
|
65
|
+
return data
|
|
66
|
+
end
|
|
67
|
+
if typeof(data) ~= "table" then
|
|
68
|
+
return deepCopy(template)
|
|
69
|
+
end
|
|
70
|
+
for key, value in template do
|
|
71
|
+
if data[key] == nil then
|
|
72
|
+
data[key] = deepCopy(value)
|
|
73
|
+
elseif typeof(value) == "table" then
|
|
74
|
+
reconcile(data[key], value)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
return data
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
local function thisSession(session: any): boolean
|
|
81
|
+
return typeof(session) == "table" and session.PlaceId == PlaceId and session.JobId == JobId
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
local function sessionToken(storeName: string, key: string): string
|
|
85
|
+
return storeName .. "/" .. key
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
local function uniqueId(): string
|
|
89
|
+
return HttpService:GenerateGUID(false)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
local function requestEnd(session: any)
|
|
93
|
+
if typeof(session) ~= "table" or typeof(session.UniqueSessionId) ~= "string" or session.UniqueSessionId == "" then
|
|
94
|
+
return
|
|
95
|
+
end
|
|
96
|
+
pcall(function()
|
|
97
|
+
MessagingService:PublishAsync("Keep_" .. session.UniqueSessionId, { EndSession = true })
|
|
98
|
+
end)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
local function registerIssue()
|
|
102
|
+
local now = os.clock()
|
|
103
|
+
table.insert(IssueQueue, now)
|
|
104
|
+
while IssueQueue[1] and now - IssueQueue[1] > CRITICAL_STATE_ERROR_EXPIRE do
|
|
105
|
+
table.remove(IssueQueue, 1)
|
|
106
|
+
end
|
|
107
|
+
if #IssueQueue >= CRITICAL_STATE_ERROR_COUNT then
|
|
108
|
+
Store.IsCriticalState = true
|
|
109
|
+
CriticalStateStart = now
|
|
110
|
+
Store.OnCriticalToggle:Fire(true)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
local function emptyPayload(template: any)
|
|
115
|
+
return {
|
|
116
|
+
Data = deepCopy(template),
|
|
117
|
+
MetaData = {
|
|
118
|
+
ProfileCreateTime = os.time(),
|
|
119
|
+
SessionLoadCount = 0,
|
|
120
|
+
ActiveSession = nil,
|
|
121
|
+
ForceLoadSession = nil,
|
|
122
|
+
LastUpdate = os.time(),
|
|
123
|
+
UniqueSessionId = "",
|
|
124
|
+
},
|
|
125
|
+
RobloxMetaData = {},
|
|
126
|
+
UserIds = {},
|
|
127
|
+
GlobalUpdates = { 0, {} },
|
|
128
|
+
}
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
local function mockBucket(userMock: boolean)
|
|
132
|
+
return if userMock then UserMockStore else MockStore
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
local function readMock(userMock: boolean, name: string, key: string)
|
|
136
|
+
local bucket = mockBucket(userMock)
|
|
137
|
+
bucket[name] = bucket[name] or {}
|
|
138
|
+
return bucket[name][key]
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
local function writeMock(userMock: boolean, name: string, key: string, payload: any)
|
|
142
|
+
local bucket = mockBucket(userMock)
|
|
143
|
+
bucket[name] = bucket[name] or {}
|
|
144
|
+
bucket[name][key] = payload
|
|
145
|
+
return payload
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
local function waitQueue(token: string)
|
|
149
|
+
UpdateQueue[token] = UpdateQueue[token] or {}
|
|
150
|
+
local waiters = UpdateQueue[token]
|
|
151
|
+
local thread = coroutine.running()
|
|
152
|
+
table.insert(waiters, thread)
|
|
153
|
+
if waiters[1] ~= thread then
|
|
154
|
+
coroutine.yield()
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
local function releaseQueue(token: string)
|
|
159
|
+
local waiters = UpdateQueue[token]
|
|
160
|
+
if not waiters then
|
|
161
|
+
return
|
|
162
|
+
end
|
|
163
|
+
table.remove(waiters, 1)
|
|
164
|
+
local nextThread = waiters[1]
|
|
165
|
+
if nextThread then
|
|
166
|
+
task.spawn(nextThread)
|
|
167
|
+
else
|
|
168
|
+
UpdateQueue[token] = nil
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
local function transformUpdate(store: any, key: string, transform: (any) -> any): (any, any)
|
|
173
|
+
local token = sessionToken(store.Name, key)
|
|
174
|
+
waitQueue(token)
|
|
175
|
+
local payload
|
|
176
|
+
local keyInfo
|
|
177
|
+
if store._store and not store._mockFlag then
|
|
178
|
+
local ok, result, info = pcall(function()
|
|
179
|
+
return store._store:UpdateAsync(key, function(old, info)
|
|
180
|
+
keyInfo = info
|
|
181
|
+
return transform(old)
|
|
182
|
+
end)
|
|
183
|
+
end)
|
|
184
|
+
if ok then
|
|
185
|
+
payload = result
|
|
186
|
+
else
|
|
187
|
+
registerIssue()
|
|
188
|
+
Store.OnError:Fire(tostring(result), store.Name, key)
|
|
189
|
+
end
|
|
190
|
+
else
|
|
191
|
+
local old = readMock(store._userMock, store.Name, key)
|
|
192
|
+
payload = transform(old)
|
|
193
|
+
if payload ~= nil then
|
|
194
|
+
writeMock(store._userMock, store.Name, key, payload)
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
releaseQueue(token)
|
|
198
|
+
return payload, keyInfo
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
local Profile = {}
|
|
202
|
+
Profile.__index = Profile
|
|
203
|
+
|
|
204
|
+
function Profile:IsActive(): boolean
|
|
205
|
+
return ActiveSessionCheck[self._token] == self and not Store.IsClosing
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
function Profile:Reconcile()
|
|
209
|
+
self.Data = reconcile(self.Data, self._store.Template)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
function Profile:AddUserId(userId: number)
|
|
213
|
+
if typeof(userId) ~= "number" then
|
|
214
|
+
return
|
|
215
|
+
end
|
|
216
|
+
if table.find(self.UserIds, userId) == nil then
|
|
217
|
+
table.insert(self.UserIds, userId)
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
function Profile:RemoveUserId(userId: number)
|
|
222
|
+
local index = table.find(self.UserIds, userId)
|
|
223
|
+
if index then
|
|
224
|
+
table.remove(self.UserIds, index)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
function Profile:MessageHandler(fn: (any, () -> ()) -> ())
|
|
229
|
+
table.insert(self._handlers, fn)
|
|
230
|
+
for _, update in self._updates do
|
|
231
|
+
local index = update[1]
|
|
232
|
+
if not self._locked[index] then
|
|
233
|
+
local processed = false
|
|
234
|
+
fn(deepCopy(update[2]), function()
|
|
235
|
+
processed = true
|
|
236
|
+
self._locked[index] = true
|
|
237
|
+
end)
|
|
238
|
+
if processed then
|
|
239
|
+
break
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
local saveProfileAsync
|
|
246
|
+
|
|
247
|
+
function Profile:Save()
|
|
248
|
+
if self._view then
|
|
249
|
+
error("Keep: Save is not valid in view mode; use SetAsync")
|
|
250
|
+
end
|
|
251
|
+
if not self:IsActive() then
|
|
252
|
+
return
|
|
253
|
+
end
|
|
254
|
+
task.spawn(saveProfileAsync, self, false, "Manual")
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
function Profile:SaveWait(): boolean
|
|
258
|
+
if self._view then
|
|
259
|
+
error("Keep: SaveWait is not valid in view mode; use SetAsync")
|
|
260
|
+
end
|
|
261
|
+
while self._saving do
|
|
262
|
+
task.wait()
|
|
263
|
+
end
|
|
264
|
+
if not self:IsActive() then
|
|
265
|
+
return false
|
|
266
|
+
end
|
|
267
|
+
return saveProfileAsync(self, false, "Manual") == true
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
function Profile:SetAsync()
|
|
271
|
+
if not self._view then
|
|
272
|
+
error("Keep: SetAsync is only valid in view mode")
|
|
273
|
+
end
|
|
274
|
+
saveProfileAsync(self, true, "Manual")
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
function Profile:EndSession()
|
|
278
|
+
if self._view then
|
|
279
|
+
return
|
|
280
|
+
end
|
|
281
|
+
saveProfileAsync(self, true, "Manual")
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
saveProfileAsync = function(profile: any, ending: boolean, reason: string): boolean
|
|
285
|
+
while profile._saving do
|
|
286
|
+
task.wait()
|
|
287
|
+
end
|
|
288
|
+
if profile._ended then
|
|
289
|
+
return false
|
|
290
|
+
end
|
|
291
|
+
if ending then
|
|
292
|
+
if not profile._view then
|
|
293
|
+
Trade.AbortIfActive(profile)
|
|
294
|
+
end
|
|
295
|
+
elseif not profile:IsActive() then
|
|
296
|
+
return false
|
|
297
|
+
end
|
|
298
|
+
profile._saving = true
|
|
299
|
+
ActiveProfileSaveJobs += 1
|
|
300
|
+
profile.OnSave:Fire()
|
|
301
|
+
if ending then
|
|
302
|
+
profile.OnLastSave:Fire(if Store.IsClosing then "Shutdown" else reason)
|
|
303
|
+
end
|
|
304
|
+
local stealRequested = false
|
|
305
|
+
local payload = transformUpdate(profile._store, profile.Key, function(old)
|
|
306
|
+
old = old or emptyPayload(profile._store.Template)
|
|
307
|
+
old.MetaData = old.MetaData or {}
|
|
308
|
+
local incoming = (old.GlobalUpdates and old.GlobalUpdates[2]) or {}
|
|
309
|
+
for _, update in incoming do
|
|
310
|
+
local index = update[1]
|
|
311
|
+
local exists = false
|
|
312
|
+
for _, have in profile._updates do
|
|
313
|
+
if have[1] == index then
|
|
314
|
+
exists = true
|
|
315
|
+
break
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
if not exists then
|
|
319
|
+
table.insert(profile._updates, update)
|
|
320
|
+
profile._updateIndex = math.max(profile._updateIndex, index or 0)
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
for _, update in profile._updates do
|
|
324
|
+
if not profile._locked[update[1]] then
|
|
325
|
+
for _, fn in profile._handlers do
|
|
326
|
+
local processed = false
|
|
327
|
+
fn(deepCopy(update[2]), function()
|
|
328
|
+
processed = true
|
|
329
|
+
profile._locked[update[1]] = true
|
|
330
|
+
end)
|
|
331
|
+
if processed then
|
|
332
|
+
break
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
local remaining = {}
|
|
338
|
+
for _, update in profile._updates do
|
|
339
|
+
if not profile._locked[update[1]] then
|
|
340
|
+
table.insert(remaining, update)
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
profile._updates = remaining
|
|
344
|
+
stealRequested = typeof(old.MetaData.ForceLoadSession) == "table" and not thisSession(old.MetaData.ForceLoadSession)
|
|
345
|
+
if ending or stealRequested then
|
|
346
|
+
if thisSession(old.MetaData.ActiveSession) then
|
|
347
|
+
old.MetaData.ActiveSession = nil
|
|
348
|
+
end
|
|
349
|
+
else
|
|
350
|
+
old.MetaData.ActiveSession = {
|
|
351
|
+
PlaceId = PlaceId,
|
|
352
|
+
JobId = JobId,
|
|
353
|
+
UniqueSessionId = profile._sessionId,
|
|
354
|
+
}
|
|
355
|
+
end
|
|
356
|
+
old.Data = profile.Data
|
|
357
|
+
old.RobloxMetaData = profile.RobloxMetaData
|
|
358
|
+
old.UserIds = profile.UserIds
|
|
359
|
+
old.MetaData.LastUpdate = os.time()
|
|
360
|
+
old.GlobalUpdates = { profile._updateIndex, remaining }
|
|
361
|
+
return old
|
|
362
|
+
end)
|
|
363
|
+
if payload then
|
|
364
|
+
profile.LastSavedData = deepCopy(payload.Data)
|
|
365
|
+
profile.OnAfterSave:Fire(profile.LastSavedData)
|
|
366
|
+
end
|
|
367
|
+
if ending or stealRequested then
|
|
368
|
+
if not profile._view then
|
|
369
|
+
profile._ended = true
|
|
370
|
+
ActiveSessionCheck[profile._token] = nil
|
|
371
|
+
for index, item in AutoSaveList do
|
|
372
|
+
if item == profile then
|
|
373
|
+
table.remove(AutoSaveList, index)
|
|
374
|
+
break
|
|
375
|
+
end
|
|
376
|
+
end
|
|
377
|
+
profile.OnSessionEnd:Fire()
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
profile._saving = false
|
|
381
|
+
ActiveProfileSaveJobs -= 1
|
|
382
|
+
return payload ~= nil
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
local function attachAutosave(profile: any)
|
|
386
|
+
table.insert(AutoSaveList, profile)
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
local function makeProfile(store: any, key: string, payload: any, view: boolean)
|
|
390
|
+
local token = sessionToken(store.Name, key)
|
|
391
|
+
local profile = setmetatable({
|
|
392
|
+
Data = payload.Data,
|
|
393
|
+
LastSavedData = deepCopy(payload.Data),
|
|
394
|
+
FirstSessionTime = payload.MetaData.ProfileCreateTime or os.time(),
|
|
395
|
+
SessionLoadCount = payload.MetaData.SessionLoadCount or 0,
|
|
396
|
+
Session = payload.MetaData.ActiveSession,
|
|
397
|
+
RobloxMetaData = payload.RobloxMetaData or {},
|
|
398
|
+
UserIds = payload.UserIds or {},
|
|
399
|
+
Key = key,
|
|
400
|
+
IsActive = Profile.IsActive,
|
|
401
|
+
_store = store,
|
|
402
|
+
_token = token,
|
|
403
|
+
_view = view,
|
|
404
|
+
_sessionId = payload.MetaData.UniqueSessionId or uniqueId(),
|
|
405
|
+
_handlers = {},
|
|
406
|
+
_locked = {},
|
|
407
|
+
_updates = (payload.GlobalUpdates and payload.GlobalUpdates[2]) or {},
|
|
408
|
+
_updateIndex = (payload.GlobalUpdates and payload.GlobalUpdates[1]) or 0,
|
|
409
|
+
_saving = false,
|
|
410
|
+
_ended = false,
|
|
411
|
+
OnSave = Spark.new(),
|
|
412
|
+
OnLastSave = Spark.new(),
|
|
413
|
+
OnSessionEnd = Spark.new(),
|
|
414
|
+
OnAfterSave = Spark.new(),
|
|
415
|
+
}, Profile)
|
|
416
|
+
profile.ProfileStore = store
|
|
417
|
+
return profile
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
function Store.SetConstant(name: string, value: number)
|
|
421
|
+
if name == "AUTO_SAVE_PERIOD" then
|
|
422
|
+
AUTO_SAVE_PERIOD = value
|
|
423
|
+
elseif name == "LOAD_REPEAT_PERIOD" then
|
|
424
|
+
LOAD_REPEAT_PERIOD = value
|
|
425
|
+
elseif name == "FIRST_LOAD_REPEAT" then
|
|
426
|
+
FIRST_LOAD_REPEAT = value
|
|
427
|
+
elseif name == "SESSION_STEAL" then
|
|
428
|
+
SESSION_STEAL = value
|
|
429
|
+
elseif name == "ASSUME_DEAD" then
|
|
430
|
+
ASSUME_DEAD = value
|
|
431
|
+
elseif name == "START_SESSION_TIMEOUT" then
|
|
432
|
+
START_SESSION_TIMEOUT = value
|
|
433
|
+
elseif name == "MAX_MESSAGE_QUEUE" then
|
|
434
|
+
MAX_MESSAGE_QUEUE = value
|
|
435
|
+
end
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
function Store.New(name: string, template: any)
|
|
439
|
+
local self = setmetatable({
|
|
440
|
+
Name = name,
|
|
441
|
+
Template = template or {},
|
|
442
|
+
_store = nil :: GlobalDataStore?,
|
|
443
|
+
_mockFlag = false,
|
|
444
|
+
_userMock = false,
|
|
445
|
+
Mock = nil :: any,
|
|
446
|
+
}, Store)
|
|
447
|
+
local ok = pcall(function()
|
|
448
|
+
self._store = DataStoreService:GetDataStore("Keep_" .. name)
|
|
449
|
+
Store.DataStoreState = "Access"
|
|
450
|
+
end)
|
|
451
|
+
if not ok or self._store == nil then
|
|
452
|
+
self._mockFlag = IsStudio
|
|
453
|
+
Store.DataStoreState = if IsStudio then "Access" else "NoAccess"
|
|
454
|
+
end
|
|
455
|
+
self.Mock = setmetatable({
|
|
456
|
+
Name = name,
|
|
457
|
+
Template = self.Template,
|
|
458
|
+
_store = nil,
|
|
459
|
+
_mockFlag = true,
|
|
460
|
+
_userMock = true,
|
|
461
|
+
Mock = nil,
|
|
462
|
+
}, Store)
|
|
463
|
+
self.Mock.Mock = self.Mock
|
|
464
|
+
return self
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
function Store:StartSessionAsync(key: string, params: any)
|
|
468
|
+
params = params or {}
|
|
469
|
+
local steal = params.Steal == true
|
|
470
|
+
local cancel = params.Cancel
|
|
471
|
+
local started = os.clock()
|
|
472
|
+
local firstWait = true
|
|
473
|
+
ActiveProfileLoadJobs += 1
|
|
474
|
+
local profile
|
|
475
|
+
while true do
|
|
476
|
+
if typeof(cancel) == "function" and cancel() then
|
|
477
|
+
break
|
|
478
|
+
end
|
|
479
|
+
if os.clock() - started > START_SESSION_TIMEOUT then
|
|
480
|
+
break
|
|
481
|
+
end
|
|
482
|
+
local sessionId = uniqueId()
|
|
483
|
+
local payload = transformUpdate(self, key, function(old)
|
|
484
|
+
old = old or emptyPayload(self.Template)
|
|
485
|
+
old.MetaData = old.MetaData or {}
|
|
486
|
+
local lock = old.MetaData.ActiveSession
|
|
487
|
+
local last = old.MetaData.LastUpdate or 0
|
|
488
|
+
local dead = os.time() - last >= ASSUME_DEAD
|
|
489
|
+
if lock and not thisSession(lock) and not dead and not steal then
|
|
490
|
+
old.MetaData.ForceLoadSession = { PlaceId = PlaceId, JobId = JobId }
|
|
491
|
+
return old
|
|
492
|
+
end
|
|
493
|
+
old.Data = reconcile(old.Data or {}, self.Template)
|
|
494
|
+
old.MetaData.SessionLoadCount = (old.MetaData.SessionLoadCount or 0) + 1
|
|
495
|
+
old.MetaData.UniqueSessionId = sessionId
|
|
496
|
+
old.MetaData.ActiveSession = { PlaceId = PlaceId, JobId = JobId, UniqueSessionId = sessionId }
|
|
497
|
+
old.MetaData.ForceLoadSession = nil
|
|
498
|
+
old.MetaData.LastUpdate = os.time()
|
|
499
|
+
old.GlobalUpdates = old.GlobalUpdates or { 0, {} }
|
|
500
|
+
return old
|
|
501
|
+
end)
|
|
502
|
+
if payload and thisSession(payload.MetaData.ActiveSession) then
|
|
503
|
+
profile = makeProfile(self, key, payload, false)
|
|
504
|
+
ActiveSessionCheck[profile._token] = profile
|
|
505
|
+
attachAutosave(profile)
|
|
506
|
+
pcall(function()
|
|
507
|
+
MessagingService:SubscribeAsync("Keep_" .. profile._sessionId, function(message)
|
|
508
|
+
if typeof(message.Data) == "table" and message.Data.EndSession and profile:IsActive() then
|
|
509
|
+
saveProfileAsync(profile, true, "External")
|
|
510
|
+
end
|
|
511
|
+
end)
|
|
512
|
+
end)
|
|
513
|
+
break
|
|
514
|
+
end
|
|
515
|
+
if payload then
|
|
516
|
+
requestEnd(payload.MetaData.ActiveSession)
|
|
517
|
+
end
|
|
518
|
+
task.wait(if firstWait then FIRST_LOAD_REPEAT else LOAD_REPEAT_PERIOD)
|
|
519
|
+
firstWait = false
|
|
520
|
+
if os.clock() - started > SESSION_STEAL then
|
|
521
|
+
steal = true
|
|
522
|
+
end
|
|
523
|
+
end
|
|
524
|
+
ActiveProfileLoadJobs -= 1
|
|
525
|
+
return profile
|
|
526
|
+
end
|
|
527
|
+
|
|
528
|
+
function Store:GetAsync(key: string): any
|
|
529
|
+
local payload
|
|
530
|
+
if self._store and not self._mockFlag then
|
|
531
|
+
local ok, result = pcall(function()
|
|
532
|
+
return self._store:GetAsync(key)
|
|
533
|
+
end)
|
|
534
|
+
if ok then
|
|
535
|
+
payload = result
|
|
536
|
+
end
|
|
537
|
+
else
|
|
538
|
+
payload = readMock(self._userMock, self.Name, key)
|
|
539
|
+
end
|
|
540
|
+
if not payload then
|
|
541
|
+
return nil
|
|
542
|
+
end
|
|
543
|
+
return makeProfile(self, key, payload, true)
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
function Store:MessageAsync(key: string, message: any): boolean
|
|
547
|
+
if typeof(message) ~= "table" then
|
|
548
|
+
return false
|
|
549
|
+
end
|
|
550
|
+
local payload = transformUpdate(self, key, function(old)
|
|
551
|
+
old = old or emptyPayload(self.Template)
|
|
552
|
+
old.GlobalUpdates = old.GlobalUpdates or { 0, {} }
|
|
553
|
+
local index = (old.GlobalUpdates[1] or 0) + 1
|
|
554
|
+
old.GlobalUpdates[1] = index
|
|
555
|
+
old.GlobalUpdates[2] = old.GlobalUpdates[2] or {}
|
|
556
|
+
if #old.GlobalUpdates[2] >= MAX_MESSAGE_QUEUE then
|
|
557
|
+
table.remove(old.GlobalUpdates[2], 1)
|
|
558
|
+
end
|
|
559
|
+
table.insert(old.GlobalUpdates[2], { index, message })
|
|
560
|
+
return old
|
|
561
|
+
end)
|
|
562
|
+
return payload ~= nil
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
function Store:RemoveAsync(key: string): boolean
|
|
566
|
+
if self._store and not self._mockFlag then
|
|
567
|
+
local ok = pcall(function()
|
|
568
|
+
self._store:RemoveAsync(key)
|
|
569
|
+
end)
|
|
570
|
+
return ok
|
|
571
|
+
end
|
|
572
|
+
local bucket = mockBucket(self._userMock)
|
|
573
|
+
if bucket[self.Name] then
|
|
574
|
+
bucket[self.Name][key] = nil
|
|
575
|
+
end
|
|
576
|
+
return true
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
function Store:VersionQuery(key: string, sortDirection: any, minDate: any, maxDate: any)
|
|
580
|
+
local versions = {}
|
|
581
|
+
local cursor = 0
|
|
582
|
+
if self._store and not self._mockFlag then
|
|
583
|
+
pcall(function()
|
|
584
|
+
local pages = self._store:ListVersionsAsync(key, sortDirection, minDate, maxDate)
|
|
585
|
+
if pages then
|
|
586
|
+
for _, item in pages:GetCurrentPage() do
|
|
587
|
+
table.insert(versions, item)
|
|
588
|
+
end
|
|
589
|
+
end
|
|
590
|
+
end)
|
|
591
|
+
end
|
|
592
|
+
return {
|
|
593
|
+
Get = function(_self, index: number)
|
|
594
|
+
return versions[index]
|
|
595
|
+
end,
|
|
596
|
+
List = function()
|
|
597
|
+
return versions
|
|
598
|
+
end,
|
|
599
|
+
Next = function()
|
|
600
|
+
cursor += 1
|
|
601
|
+
return versions[cursor]
|
|
602
|
+
end,
|
|
603
|
+
NextAsync = function()
|
|
604
|
+
cursor += 1
|
|
605
|
+
local info = versions[cursor]
|
|
606
|
+
if not info then
|
|
607
|
+
return nil
|
|
608
|
+
end
|
|
609
|
+
return self:GetAsync(key)
|
|
610
|
+
end,
|
|
611
|
+
}
|
|
612
|
+
end
|
|
613
|
+
|
|
614
|
+
if RunService:IsServer() then
|
|
615
|
+
task.spawn(function()
|
|
616
|
+
while true do
|
|
617
|
+
task.wait(1)
|
|
618
|
+
if Store.IsCriticalState and os.clock() - CriticalStateStart > CRITICAL_STATE_EXPIRE then
|
|
619
|
+
Store.IsCriticalState = false
|
|
620
|
+
Store.OnCriticalToggle:Fire(false)
|
|
621
|
+
end
|
|
622
|
+
if os.clock() - LastAutoSave >= 1 and #AutoSaveList > 0 then
|
|
623
|
+
local period = AUTO_SAVE_PERIOD / math.max(#AutoSaveList, 1)
|
|
624
|
+
if os.clock() - LastAutoSave >= period then
|
|
625
|
+
LastAutoSave = os.clock()
|
|
626
|
+
local profile = AutoSaveList[AutoSaveIndex]
|
|
627
|
+
AutoSaveIndex += 1
|
|
628
|
+
if AutoSaveIndex > #AutoSaveList then
|
|
629
|
+
AutoSaveIndex = 1
|
|
630
|
+
end
|
|
631
|
+
if profile and profile:IsActive() then
|
|
632
|
+
task.spawn(saveProfileAsync, profile, false, "Manual")
|
|
633
|
+
end
|
|
634
|
+
end
|
|
635
|
+
end
|
|
636
|
+
end
|
|
637
|
+
end)
|
|
638
|
+
game:BindToClose(function()
|
|
639
|
+
Store.IsClosing = true
|
|
640
|
+
for _, profile in table.clone(AutoSaveList) do
|
|
641
|
+
if profile:IsActive() then
|
|
642
|
+
saveProfileAsync(profile, true, "Shutdown")
|
|
643
|
+
end
|
|
644
|
+
end
|
|
645
|
+
local deadline = os.clock() + 20
|
|
646
|
+
while (ActiveProfileSaveJobs > 0 or ActiveProfileLoadJobs > 0) and os.clock() < deadline do
|
|
647
|
+
task.wait()
|
|
648
|
+
end
|
|
649
|
+
end)
|
|
650
|
+
end
|
|
651
|
+
|
|
652
|
+
return Store
|