Advertisement
Guest User

Untitled

a guest
Dec 28th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. local function getProperties(class, disallowedTags)
  2.     local properties = { }
  3.     if not disallowedTags then
  4.         disallowedTags = { }
  5.     end
  6.     for i, v in pairs(parse(data)) do -- The Parse function works without any problems, no matter what I do, so it's not that
  7.         if v.type == "Property" then
  8.             if type(class) == "string" then
  9.                 if class == v.Class then
  10.                     local tagged = false
  11.                     for i, v in pairs(v.tags) do
  12.                         if checkIfIn(disallowedTags, i) then
  13.                             tagged = true
  14.                         end
  15.                     end
  16.                     if not tagged then
  17.                         properties[v.Name] = v
  18.                     end
  19.                 end
  20.             else
  21.                 if class:IsA(v.Class) then
  22.                     local tagged = false
  23.                     for i, v in pairs(v.tags) do
  24.                         if checkIfIn(disallowedTags, i) then
  25.                             tagged = true
  26.                         end
  27.                     end
  28.                     if not tagged then
  29.                         properties[v.Name] = v
  30.                     end
  31.                 end
  32.             end
  33.         end
  34.     end
  35.     return properties
  36. end
  37.  
  38. function getStringVersion(value, intsTab) -- TODO: Add Region3 and other minor data types
  39.     if type(value) == "string" or type(value) == "boolean" or type(value) == "number" then
  40.         if type(value) == "string" then -- String
  41.             return "\""..value.."\""
  42.         else -- Boolean, Number
  43.             return tostring(value)
  44.         end
  45.     end
  46.     if type(value) == "table" then -- Table, obviously.
  47.         local str = "{"
  48.         local num = 0
  49.         for i, v in pairs(value) do
  50.             num = num + 1
  51.             if num == 1 then
  52.                 str = str.."["..getStringVersion(i).."] = "..getStringVersion(v).."\n"
  53.             else
  54.                 str = str..", ["..getStringVersion(i).."] = "..getStringVersion(v).."\n"
  55.             end
  56.         end
  57.         str = str.."}"
  58.     end
  59.     if test(value, "X", "Y") then
  60.         if test(value, "Z") then -- Vector3
  61.             if test(value, "lookVector") then -- CFrame
  62.                 return "CFrame.new("..table.concat({value:components()}, ", ")..")"
  63.             else
  64.                 return "Vector3.new("..value.X..", "..value.Y..", "..value.Z..")"
  65.             end
  66.         elseif test(value.X, "Offset", "Scale") then -- UDim2
  67.             return "UDim2.new("..value.X.Scale..", "..value.X.Offset..", "..value.Y.Scale..", "..value.Y.Offset..")"
  68.         else -- Vector2
  69.             return "Vector2.new("..value.X..", "..value.Y..")"
  70.         end
  71.     end
  72.     if test(value, "Color", "Name", "Number") then -- BrickColor
  73.         return "BrickColor.new(\""..value.Name.."\")"
  74.     end
  75.     if test(value, "r", "b", "g") then -- Color3
  76.         return "Color3.new("..value.r..", "..value.b..", "..value.g..")"
  77.     end
  78.     if test(value, "Name", "Value") then -- Enumerator
  79.         return "\""..value.Name.."\""
  80.     end
  81.     if test(value, "Offset") then -- UDim
  82.         return "UDim.new("..value.Scale..", "..value.Offset..")"
  83.     end
  84.     if test(value, "Origin", "Direction") then -- Ray. I have no idea how to do Region3, so I'll skip that for now.
  85.         return "Ray.new("..getStringVersion(value.Origin)..", "..getStringVersion(value.Direction)..")"
  86.     end
  87.     if test(value, "Parent", "IsA") then -- Instance (I'm not entirely sure what I'm doing here!)
  88.         for i, v in pairs(intsTab) do
  89.             if v == value then
  90.                 return "obj"..i
  91.             end
  92.         end
  93.         if value ~= game then
  94.             return "game."..value:GetFullName()
  95.         else
  96.             return "game"
  97.         end
  98.     end
  99.     return "nil"
  100. end
  101.  
  102. local dTags = {"readonly", "RobloxScriptSecurity", "RobloxSecurity", "LocalUserSecurity", "writeonly", "WritePlayerSecurity", "RobloxPlaceSecurity", "backend"}
  103.  
  104. local function cmdCompile(obj)
  105.     local str = "Create(\""..obj.ClassName.."\"){\n"
  106.     local num = 0
  107.     for i, v in pairs(getProperties(obj.ClassName, dTags)) do
  108.         local strV = getStringVersion(obj[i], { })
  109.         str = str..i.." = "..strV..";\n"
  110.         num = num + 1
  111.     end
  112.     for i, v in pairs(obj:GetChildren()) do
  113.         str = str..cmdCompile(v)..";\n"
  114.     end
  115.     str = str.."}"
  116.     return str
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement