-
-
Save Ashp116/ffacfd7ed7ceaede1dad1807ab3e17bb to your computer and use it in GitHub Desktop.
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
type Properties = { | |
[string] : any, | |
Parent: Instance, | |
Attributes: {[string] : string | boolean | number | UDim | UDim2 | BrickColor | Color3 | Vector2 | Vector3 | NumberSequence | ColorSequence | NumberRange | Rect}, | |
Children: {Instance} | |
} | |
local ValueBases = { | |
["string"] = "String", | |
["number"] = "number", | |
["Int"] = "Int", | |
["boolean"] = "Bool", | |
["BrickColor"]= "BrickColor", | |
["CFrame"] = "CFrame", | |
["Color3"] = "Color3", | |
["Object"] = "Object", | |
["Ray"] = "Ray", | |
["Vector3"] = "Vector3" | |
} | |
local Edit = function(Object: Instance, Properties: Properties) | |
Properties = Properties or {} | |
local _parent = (typeof(Properties.Parent) == "Instance" and Properties.Parent) or nil | |
local _attributes = Properties.Attributes or {} | |
local _children = Properties.Children or {} | |
Properties.Parent = nil | |
Properties.Attributes = nil | |
Properties.Children = nil | |
for _propertyName, _value in pairs(Properties) do | |
local _property = Object[_propertyName] | |
--[[ | |
This if-statement for RBXScriptSignal was from https://github.com/Zyrakia/altmake | |
]] | |
if typeof(_property) == "RBXScriptSignal" then | |
_property:Connect(_value) | |
elseif typeof(_property) == "function" then | |
if typeof(_property(Object, table.unpack(_value.args))) == "RBXScriptSignal" then | |
_property(Object, table.unpack(_value.args)):Connect(function() | |
_value.callback(Object) | |
end) | |
else | |
_property(Object, table.unpack(_value.args)) | |
end | |
else | |
Object[_propertyName] = _value | |
end | |
end | |
for _attributeName, _attributeValue in pairs(_attributes) do | |
Object:SetAttribute(_attributeName, _attributeValue) | |
end | |
for _, _child in pairs(_children) do | |
_child.Parent = Object | |
end | |
Object.Parent = (not Object.Parent and _parent) or Object.Parent | |
return Object | |
end | |
local Create = function(ClassName: string, Properties: Properties) | |
local Object = Instance.new(ClassName) | |
return Edit(Object, Properties) | |
end | |
local CreateValueBase = function(Value: any, Properties: Properties?) | |
if ValueBases[typeof(Value)] then | |
if typeof(Value) == "number" then | |
Properties.Value = Value | |
if Value == math.round(Value) then | |
return Create("IntValue", Properties) | |
else | |
return Create("NumberValue", Properties) | |
end | |
else | |
Properties.Value = Value | |
return Create( ValueBases[typeof(Value)].."Value", Properties) | |
end | |
end | |
end | |
return {Create = Create, Edit = Edit, CreateValueBase = CreateValueBase} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment