@quenty/badgeutils 3.6.0 → 4.0.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/package.json +4 -4
- package/src/Shared/BadgeUtils.lua +74 -0
- package/src/Server/BadgeUtils.lua +0 -38
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/badgeutils@3.6.0...@quenty/badgeutils@4.0.0) (2022-03-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Move BadgeUtils to shared, add API to get badge info ([f9fc12d](https://github.com/Quenty/NevermoreEngine/commit/f9fc12d9d465dbbb9345d216789a8faf98430172))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [3.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/badgeutils@3.5.1...@quenty/badgeutils@3.6.0) (2022-01-17)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/badgeutils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/badgeutils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Utility functions involving badges on Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/loader": "^
|
|
29
|
-
"@quenty/promise": "^
|
|
28
|
+
"@quenty/loader": "^4.0.0",
|
|
29
|
+
"@quenty/promise": "^4.0.0"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "dd428cab58282c975a4c082957dc8f58e3186905"
|
|
35
35
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
Utility functions involving badges on Roblox
|
|
3
|
+
@class BadgeUtils
|
|
4
|
+
]=]
|
|
5
|
+
|
|
6
|
+
local BadgeService = game:GetService("BadgeService")
|
|
7
|
+
|
|
8
|
+
local require = require(script.Parent.loader).load(script)
|
|
9
|
+
|
|
10
|
+
local Promise = require("Promise")
|
|
11
|
+
|
|
12
|
+
local BadgeUtils = {}
|
|
13
|
+
|
|
14
|
+
--[=[
|
|
15
|
+
@interface BadgeInfoDictionary
|
|
16
|
+
.Name string -- The name of the badge.
|
|
17
|
+
.Description string -- The description of the badge.
|
|
18
|
+
.IconImageId int64 -- The asset ID of the image for the badge.
|
|
19
|
+
.IsEnabled bool -- Indicates whether the badge is available to be awarded.
|
|
20
|
+
@within BadgeUtils
|
|
21
|
+
]=]
|
|
22
|
+
|
|
23
|
+
--[=[
|
|
24
|
+
Tries to reward a player to a badge inside of a promise.
|
|
25
|
+
|
|
26
|
+
@server
|
|
27
|
+
@param player Player
|
|
28
|
+
@param badgeId number
|
|
29
|
+
@return Promise
|
|
30
|
+
]=]
|
|
31
|
+
function BadgeUtils.promiseAwardBadge(player, badgeId)
|
|
32
|
+
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
33
|
+
assert(type(badgeId) == "number", "Bad badgeId")
|
|
34
|
+
|
|
35
|
+
return Promise.spawn(function(resolve, reject)
|
|
36
|
+
local ok, err = pcall(function()
|
|
37
|
+
BadgeService:AwardBadge(player.UserId, badgeId)
|
|
38
|
+
end)
|
|
39
|
+
|
|
40
|
+
if not ok then
|
|
41
|
+
return reject(err)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
return resolve(true)
|
|
45
|
+
end)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
--[=[
|
|
49
|
+
Gets the badge info for the given badgeId.
|
|
50
|
+
|
|
51
|
+
@param badgeId number
|
|
52
|
+
@return Promise<BadgeInfoDictionary>
|
|
53
|
+
]=]
|
|
54
|
+
function BadgeUtils.promiseBadgeInfo(badgeId)
|
|
55
|
+
assert(type(badgeId) == "number", "Bad badgeId")
|
|
56
|
+
|
|
57
|
+
return Promise.spawn(function(resolve, reject)
|
|
58
|
+
local data
|
|
59
|
+
local ok, err = pcall(function()
|
|
60
|
+
data = BadgeService:GetBadgeInfoAsync(badgeId)
|
|
61
|
+
end)
|
|
62
|
+
|
|
63
|
+
if not ok then
|
|
64
|
+
return reject(err)
|
|
65
|
+
end
|
|
66
|
+
if not type(data) == "table" then
|
|
67
|
+
return reject("Failed to get a table of data of badgeInfo")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
return resolve(data)
|
|
71
|
+
end)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
return BadgeUtils
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
--[=[
|
|
2
|
-
Utility functions involving badges on Roblox
|
|
3
|
-
@class BadgeUtils
|
|
4
|
-
]=]
|
|
5
|
-
|
|
6
|
-
local BadgeService = game:GetService("BadgeService")
|
|
7
|
-
|
|
8
|
-
local require = require(script.Parent.loader).load(script)
|
|
9
|
-
|
|
10
|
-
local Promise = require("Promise")
|
|
11
|
-
|
|
12
|
-
local BadgeUtils = {}
|
|
13
|
-
|
|
14
|
-
--[=[
|
|
15
|
-
Tries to reward a player to a badge inside of a promise.
|
|
16
|
-
|
|
17
|
-
@param player Player
|
|
18
|
-
@param badgeId number
|
|
19
|
-
@return Promise
|
|
20
|
-
]=]
|
|
21
|
-
function BadgeUtils.promiseAwardBadge(player, badgeId)
|
|
22
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
23
|
-
assert(type(badgeId) == "number", "Bad badgeId")
|
|
24
|
-
|
|
25
|
-
return Promise.spawn(function(resolve, reject)
|
|
26
|
-
local ok, err = pcall(function()
|
|
27
|
-
BadgeService:AwardBadge(player.UserId, badgeId)
|
|
28
|
-
end)
|
|
29
|
-
|
|
30
|
-
if not ok then
|
|
31
|
-
return reject(err)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
return resolve(true)
|
|
35
|
-
end)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
return BadgeUtils
|