Skip to content

Commit 80463b3

Browse files
authored
Merge pull request #23 from metrik-tech/feature/ENG-104
feature/eng 104: Implement 'Array' argument type.
2 parents 61a95da + e564811 commit 80463b3

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

Src/API/ActionBuilder.luau

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function ActionBuilder.Prototype.AddArgument(self: ActionBuilder, argumentName:
7474
Type = argumentMetadata and string.upper(argumentMetadata.Type or "STRING"),
7575
Description = argumentMetadata and argumentMetadata.Description or "",
7676
Required = argumentMetadata and argumentMetadata.Required or false,
77-
Default = argumentMetadata and argumentMetadata.Default or ""
77+
Default = argumentMetadata and argumentMetadata.Default or "",
78+
IsArray = argumentMetadata and argumentMetadata.IsArray or false
7879
}
7980

8081
table.insert(self.Prototype.ArgumentOrderedList, filteredArgumentName)
@@ -115,6 +116,7 @@ export type ArgumentMetadata = typeof(Action.Prototype) & {
115116
Type: ("string" | "number" | "boolean")?,
116117
Description: string?,
117118
Required: boolean?,
119+
IsArray: boolean?,
118120
Default: any,
119121
}
120122

Src/Services/ActionService.luau

+36-8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,35 @@ ActionService.Reporter = Console.new(`{script.Name}`)
2626

2727
ActionService.Actions = {}
2828

29+
function ActionService.ParseArgument(self: ActionService, argumentData: any, serverArgumentData: any)
30+
if serverArgumentData.array then
31+
local arrayObject = {}
32+
local jsonDecoded = HttpService:JSONDecode(serverArgumentData.value)
33+
34+
for _, value in jsonDecoded do
35+
-- fixme: this is not nice, look into cleaning this code
36+
37+
table.insert(arrayObject, self:ParseArgument({
38+
Type = argumentData.Type
39+
}, {
40+
value = value
41+
}))
42+
end
43+
end
44+
45+
if
46+
argumentData.Type == ArgumentType.String
47+
or argumentData.Type == ArgumentType.Number
48+
or argumentData.Type == ArgumentType.Boolean
49+
then
50+
return serverArgumentData.value
51+
elseif argumentData.Type == ArgumentType.Player then
52+
return Players:GetPlayerByUserId(serverArgumentData.value)
53+
end
54+
55+
return
56+
end
57+
2958
function ActionService.RegisterActionAsync(self: ActionService, action: any)
3059
local requestBody = {}
3160

@@ -44,6 +73,7 @@ function ActionService.RegisterActionAsync(self: ActionService, action: any)
4473
argumentBody.description = argumentObject.Description
4574
argumentBody.required = argumentObject.Required
4675
argumentBody.default = argumentObject.Default
76+
argumentBody.array = argumentObject.IsArray
4777
argumentBody.type = string.upper(argumentObject.Type)
4878

4979
table.insert(requestBody.arguments, argumentBody)
@@ -135,16 +165,14 @@ function ActionService.OnStart(self: ActionService)
135165
return
136166
end
137167

138-
if
139-
argumentData.Type == ArgumentType.String
140-
or argumentData.Type == ArgumentType.Number
141-
or argumentData.Type == ArgumentType.Boolean
142-
then
143-
argumentValue = serverArgumentData.value
144-
elseif argumentData.Type == ArgumentType.Player then
145-
argumentValue = Players:GetPlayerByUserId(serverArgumentData.value)
168+
if serverArgumentData.array ~= argumentData.IsArray then
169+
self.Reporter:Warn(`Argument '{argumentName}' has invalid types! Dropping Action request!`)
170+
171+
return
146172
end
147173

174+
argumentValue = self:ParseArgument(argumentData, serverArgumentData)
175+
148176
table.insert(sanitizedArguments, argumentValue)
149177
else
150178
if argumentData.Required then

0 commit comments

Comments
 (0)