{"ObjectStates":[{"GUID":"c3537f","Name":"BlockSquare","Nickname":"KT Studio Importer","Description":"","Transform":{"posX":0,"posY":2,"posZ":0,"rotX":0,"rotY":180,"rotZ":0,"scaleX":1,"scaleY":1,"scaleZ":1},"ColorDiffuse":{"r":0.08,"g":0.09,"b":0.09},"Locked":false,"Grid":false,"Snap":false,"Autoraise":true,"Sticky":false,"Tooltip":true,"Hands":false,"LuaScript":"-- KT Studio Importer. Installed once; subsequent imports only need a Studio URL.\nlocal origin = \"https://ktcompanion.ru\"\nlocal busy = false\n\nlocal function message(color, text)\n    broadcastToColor(text, color, {1, 0.55, 0.15})\nend\n\nlocal function arrivalPosition()\n    local base = self.getPosition()\n    local objects = getAllObjects()\n    for _, offset in ipairs({{0,-6},{6,-6},{-6,-6},{6,0},{-6,0},{0,6},{6,6},{-6,6}}) do\n        local position = base + Vector(offset[1],3,offset[2])\n        local clear = true\n        for _, object in ipairs(objects) do\n            if object ~= self then\n                local other = object.getPosition()\n                if math.abs(other.x-position.x) < 3 and math.abs(other.z-position.z) < 3 then clear = false; break end\n            end\n        end\n        if clear then return position end\n    end\n    return base + Vector(0,5,-9)\nend\n\nfunction onLoad()\n    self.setName(\"KT Studio Importer\")\n    self.setDescription(\"Import cards and tokens from \" .. origin .. \"/studio\")\n    self.createButton({label=\"IMPORT TEAM\", click_function=\"chooseLink\", function_owner=self,\n        position={0,0.55,0}, rotation={0,0,0}, width=1800, height=480, font_size=210,\n        color={1,0.28,0.03}, font_color={0.05,0.05,0.05}})\nend\n\nfunction chooseLink(_, color)\n    if busy then message(color, \"An import is already running.\"); return end\n    Player[color].showInputDialog(\"Paste the TTS link from KT Studio\", \"\", function(value)\n        if not value or value:gsub(\"%s\", \"\") == \"\" then return end\n        importTeam(value, color)\n    end)\nend\n\nfunction importTeam(value, color)\n    if busy then return end\n    if type(value) ~= \"string\" then return end\n    local url = value:gsub(\"^%s+\", \"\"):gsub(\"%s+$\", \"\")\n    local prefix = origin .. \"/api/studio/tts/exports/\"\n    local id = url:sub(#prefix + 1, #prefix + 36)\n    if url:sub(1,#prefix) ~= prefix or url:sub(#prefix + 37) ~= \"/manifest\" or #id ~= 36 or id:find(\"[^0-9a-f%-]\") then\n        message(color, \"Use a TTS export link from \" .. origin .. \"/studio\"); return\n    end\n    busy = true\n    message(color, \"Loading team...\")\n    local requestId = {}\n    local active = requestId\n    Wait.time(function()\n        if active == requestId then active = nil; busy = false; message(color, \"The server did not respond. Try again.\") end\n    end, 60)\n    WebRequest.get(url, function(response)\n        if active ~= requestId then return end\n        active = nil; busy = false\n        if response.is_error or response.response_code ~= 200 then\n            message(color, \"Could not load the export. Check the link and server. Deleted links cannot be imported.\"); return\n        end\n        local ok, pack = pcall(JSON.decode, response.text)\n        if not ok or type(pack) ~= \"table\" or pack.format ~= \"kt-studio-tts-v1\" or type(pack.object) ~= \"table\" or pack.object.Name ~= \"Bag\" then\n            message(color, \"This is not a supported KT Studio export.\"); return\n        end\n        local position = arrivalPosition()\n        local success, object = pcall(spawnObjectData, {data=pack.object, position=position, rotation={0,180,0}})\n        if not success or not object then message(color, \"TTS could not create the team box.\"); return end\n        message(color, \"Imported \" .. tostring(pack.teamName) .. \". Use PLACE on the bag to unpack it.\")\n    end)\nend\n","LuaScriptState":"","XmlUI":""}]}