-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inherent Types and Arbitrary Properties
Instead of having a column for type that applies to a property column, this update makes the property have the type inside itself. Much better UX and smaller sheets. Once we no longer need a typing column, then we don't need to enforce a specific sheet structure. This update includes the ability to put any amount of arbitrary properties per Value. This update also moves the type transformers into a separate file for maintainability and adds a few more types.
- Loading branch information
1 parent
30e2585
commit d283f72
Showing
2 changed files
with
257 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
--[[ | ||
TypeTransformers are functions that take in a entry of the CSV as a string, | ||
and then transform it into the desired datatype. | ||
Note that dict keys in here must be entirely lowercase. | ||
]] | ||
|
||
return { | ||
["string"] = function(v) | ||
return tostring(v) | ||
end, | ||
["number"] = function(v) | ||
return tonumber(v) | ||
end, | ||
["boolean"] = function(v) | ||
return string.lower(v)=="true" and true or false | ||
end, | ||
["array"] = function(v) | ||
return string.split(v,",") | ||
end, | ||
["dictionary"] = function(v) | ||
local values = string.split(v,",") | ||
local dict = table.create(#values) | ||
|
||
for _,value in ipairs(values) do | ||
local components = string.split(value,"=") | ||
dict[string.gsub(string.gsub(components[1],"^ ","")," $","")] = string.gsub(components[2],"^ ","") | ||
end | ||
|
||
return dict | ||
end, | ||
["vector3"] = function(v) | ||
local comps = string.split(v,",") | ||
return Vector3.new( | ||
tonumber(comps[1]) or 0, | ||
tonumber(comps[2]) or 0, | ||
tonumber(comps[3]) or 0 | ||
) | ||
end, | ||
["vector2"] = function(v) | ||
local comps = string.split(v,",") | ||
return Vector2.new( | ||
tonumber(comps[1]) or 0, | ||
tonumber(comps[2]) or 0 | ||
) | ||
end, | ||
["udim2"] = function(v) | ||
local comps = string.split(v,",") | ||
return UDim2.new( | ||
tonumber(comps[1]) or 0, | ||
tonumber(comps[2]) or 0, | ||
tonumber(comps[3]) or 0, | ||
tonumber(comps[4]) or 0 | ||
) | ||
end, | ||
["udim"] = function(v) | ||
local comps = string.split(v,",") | ||
return UDim.new( | ||
tonumber(comps[1]) or 0, | ||
tonumber(comps[2]) or 0 | ||
) | ||
end, | ||
["color3"] = function(v) | ||
local comps = string.split(v,",") | ||
return Color3.new( | ||
tonumber(comps[1]) or 0, | ||
tonumber(comps[2]) or 0, | ||
tonumber(comps[3]) or 0 | ||
) | ||
end, | ||
["brickcolor"] = function(v) | ||
return BrickColor.new(v) | ||
end, | ||
["rgb"] = function(v) | ||
local comps = string.split(v,",") | ||
return Color3.fromRGB( | ||
tonumber(comps[1]) or 0, | ||
tonumber(comps[2]) or 0, | ||
tonumber(comps[3]) or 0 | ||
) | ||
end, | ||
["cframe"] = function(v) | ||
local comps = string.split(v,",") | ||
return CFrame.new( | ||
tonumber(comps[1]) or 0, | ||
tonumber(comps[2]) or 0, | ||
tonumber(comps[3]) or 0 | ||
) | ||
end, | ||
["enum"] = function(v) | ||
local comps = string.split(v,".") | ||
return Enum[comps[1]][comps[2]] | ||
end, | ||
["rect"] = function(v) | ||
local comps = string.split(v,",") | ||
return Rect.new( | ||
tonumber(comps[1]) or 0, | ||
tonumber(comps[2]) or 0, | ||
tonumber(comps[3]) or 0, | ||
tonumber(comps[4]) or 0 | ||
) | ||
end, | ||
} |
Oops, something went wrong.