@quenty/bindtocloseservice 1.0.1-canary.38bdfe3.0
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 +11 -0
- package/LICENSE.md +21 -0
- package/README.md +22 -0
- package/default.project.json +6 -0
- package/package.json +39 -0
- package/src/Server/BindToCloseService.lua +62 -0
- package/src/node_modules.project.json +7 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 1.0.1-canary.38bdfe3.0 (2022-09-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add BindToCloseService package and implement across places binding to close ([afdd829](https://github.com/Quenty/NevermoreEngine/commit/afdd829538c9d0ce2d6f51ad9fee9063f0f5bd24))
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2022 Quenty
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
## BindToCloseService
|
|
2
|
+
<div align="center">
|
|
3
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
4
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
|
|
5
|
+
</a>
|
|
6
|
+
<a href="https://discord.gg/mhtGUS8">
|
|
7
|
+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://github.com/Quenty/NevermoreEngine/actions">
|
|
10
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
|
|
11
|
+
</a>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
Service which binds to game close and allows unbinding.
|
|
15
|
+
|
|
16
|
+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/BindToCloseService">View docs →</a></div>
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
```
|
|
20
|
+
npm install @quenty/bindtocloseservice --save
|
|
21
|
+
```
|
|
22
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quenty/bindtocloseservice",
|
|
3
|
+
"version": "1.0.1-canary.38bdfe3.0",
|
|
4
|
+
"description": "Bind to game close API in a centralized location.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Roblox",
|
|
7
|
+
"Nevermore",
|
|
8
|
+
"Lua"
|
|
9
|
+
],
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/Quenty/NevermoreEngine/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/Quenty/NevermoreEngine.git",
|
|
16
|
+
"directory": "src/blend/"
|
|
17
|
+
},
|
|
18
|
+
"funding": {
|
|
19
|
+
"type": "patreon",
|
|
20
|
+
"url": "https://www.patreon.com/quenty"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"contributors": [
|
|
24
|
+
"Quenty"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@quenty/loader": "5.0.1",
|
|
31
|
+
"@quenty/promise": "5.1.2-canary.38bdfe3.0",
|
|
32
|
+
"@quenty/symbol": "2.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@quenty/contentproviderutils": "5.1.2-canary.38bdfe3.0",
|
|
36
|
+
"@quenty/playerthumbnailutils": "5.2.2-canary.38bdfe3.0"
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "38bdfe3721bddf1d272628b1104b1d8e0abaf24f"
|
|
39
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
Allows unregisterable BindToClose callbacks. This is important because you can't unbind
|
|
3
|
+
:BindToClose calls normally, so we need to provide another place to guarantee clean shutdowns.
|
|
4
|
+
|
|
5
|
+
@class BindToCloseService
|
|
6
|
+
]=]
|
|
7
|
+
|
|
8
|
+
local require = require(script.Parent.loader).load(script)
|
|
9
|
+
|
|
10
|
+
local PromiseUtils = require("PromiseUtils")
|
|
11
|
+
local Symbol = require("Symbol")
|
|
12
|
+
local Promise = require("Promise")
|
|
13
|
+
|
|
14
|
+
local BindToCloseService = {}
|
|
15
|
+
BindToCloseService.ServiceName = "BindToCloseService"
|
|
16
|
+
|
|
17
|
+
function BindToCloseService:Init(serviceBag)
|
|
18
|
+
assert(not self._serviceBag, "Already initialized")
|
|
19
|
+
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
20
|
+
|
|
21
|
+
self._subscriptions = {}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
function BindToCloseService:Start()
|
|
25
|
+
game:BindToClose(function()
|
|
26
|
+
local promises = {}
|
|
27
|
+
|
|
28
|
+
for _, caller in pairs(self._subscriptions) do
|
|
29
|
+
local promise = caller()
|
|
30
|
+
if Promise.isPromise(promise) then
|
|
31
|
+
table.insert(promises, promise)
|
|
32
|
+
else
|
|
33
|
+
warn("[BindToCloseService.BindToClose] - Bad promise returned from close callback.")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
local ok, err = PromiseUtils.all(promises):Yield()
|
|
38
|
+
if not ok then
|
|
39
|
+
warn(err)
|
|
40
|
+
end
|
|
41
|
+
end)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
--[=[
|
|
45
|
+
Binds the promise to call on close. Can be unregistered
|
|
46
|
+
|
|
47
|
+
@param saveCallback function
|
|
48
|
+
@return function -- Call to unregister callback
|
|
49
|
+
]=]
|
|
50
|
+
function BindToCloseService:RegisterPromiseOnCloseCallback(saveCallback)
|
|
51
|
+
assert(type(saveCallback) == "function", "Bad saveCallback")
|
|
52
|
+
|
|
53
|
+
local id = Symbol.named("savingCallbackId")
|
|
54
|
+
|
|
55
|
+
self._subscriptions[id] = saveCallback
|
|
56
|
+
|
|
57
|
+
return function()
|
|
58
|
+
self._subscriptions[id] = nil
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
return BindToCloseService
|