Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetContents and SetContents. #352

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 44 additions & 7 deletions plugin/rbx_dom_lua/src/customProperties.lua
@@ -1,17 +1,54 @@
local CollectionService = game:GetService("CollectionService")
local HttpService = game:GetService("HttpService")

local function getContents(localizationTable)
local array = {}
for index, entry in ipairs(localizationTable:GetEntries()) do
local newEntry = {}
for key, value in pairs(entry) do
if key == "Context" or key == "Example" then
continue
end

newEntry[string.lower(key)] = value
end

array[index] = newEntry
end

return HttpService:JSONEncode(array)
end

local function setContents(localizationTable, contents)
local newContents = {}
for index, entry in ipairs(HttpService:JSONDecode(contents)) do
local newEntry = {
Context = "",
Example = "",
}

for key, value in pairs(entry) do
newEntry[string.gsub(key, "^%a", string.upper)] = value
end

newContents[index] = newEntry
end

localizationTable:SetEntries(newContents)
end

-- Defines how to read and write properties that aren't directly scriptable.
--
-- The reflection database refers to these as having scriptability = "Custom"
return {
Instance = {
Tags = {
read = function(instance, key)
read = function(instance)
local tagList = CollectionService:GetTags(instance)

return true, table.concat(tagList, "\0")
end,
write = function(instance, key, value)
write = function(instance, _, value)
local existingTags = CollectionService:GetTags(instance)

local unseenTags = {}
Expand All @@ -35,13 +72,13 @@ return {
},
LocalizationTable = {
Contents = {
read = function(instance, key)
return true, instance:GetContents()
read = function(instance)
return true, getContents(instance)
end,
write = function(instance, key, value)
instance:SetContents(value)
write = function(instance, _, value)
setContents(instance, value)
return true
end,
},
},
}
}