Object inspector
Инспектор объектов игры (сделан с помощью ИИ). Как использовать: 1. Нажимаем кнопку 2. Нажимаем на нужный объект 3.
local widget = require("widget")
local spyGroup = display.newGroup()
-- Функция копирования
local function copyToClipboard(text)
if text then
native.setProperty("clipboard", text)
native.showAlert("Инфо", "Данные скопированы в буфер обмена!", {"OK"})
end
end
-- Функция глубокого дампа объекта
local function getFullInfo(obj)
if not obj then return "Объект не найден" end
local lines = {}
table.insert(lines, "--- КОРЕНЬ ОБЪЕКТА ---")
table.insert(lines, "Имя: " .. tostring(obj.name or "без имени"))
table.insert(lines, "Тип: " .. tostring(obj._type or "не определен"))
table.insert(lines, "\n--- ТРАНСФОРМЫ ---")
table.insert(lines, "Координаты: X=" .. math.floor(obj.x or 0) .. " Y=" .. math.floor(obj.y or 0))
table.insert(lines, "Размеры: W=" .. math.floor(obj.width or 0) .. " H=" .. math.floor(obj.height or 0))
table.insert(lines, "Scale: X=" .. (obj.xScale or 1) .. " Y=" .. (obj.yScale or 1))
table.insert(lines, "Alpha: " .. (obj.alpha or 1))
table.insert(lines, "Rotation: " .. (obj.rotation or 0))
table.insert(lines, "\n--- ФИЗИКА (Box2D) ---")
if obj.bodyType then
table.insert(lines, "Тип тела: " .. obj.bodyType)
table.insert(lines, "Активен: " .. tostring(obj.isBodyActive))
table.insert(lines, "Сенсор: " .. tostring(obj.isSensor))
table.insert(lines, "Масса: " .. string.format("%.2f", obj.mass or 0))
local vx, vy = obj:getLinearVelocity()
table.insert(lines, "Скорость: VX=" .. math.floor(vx) .. " VY=" .. math.floor(vy))
else
table.insert(lines, "Физика отсутствует")
end
table.insert(lines, "\n--- ВСЕ ПОЛЯ (DEBUG) ---")
local customKeys = {}
for k, v in pairs(obj) do
local t = type(v)
-- Игнорируем стандартные функции и системные объекты, чтобы не засорять
if t ~= "function" and t ~= "userdata" and k ~= "_class" then
table.insert(customKeys, k .. ": " .. tostring(v))
end
end
table.sort(customKeys)
for i=1, #customKeys do table.insert(lines, customKeys[i]) end
return table.concat(lines, "\n")
end
-- Окно инспектора
local function showInspector(obj)
local infoGroup = display.newGroup()
spyGroup:insert(infoGroup)
-- Блокировщик экрана
local bkg = display.newRect(infoGroup, display.contentCenterX, display.contentCenterY, display.contentWidth*2, display.contentHeight*2)
bkg:setFillColor(0,0,0,0.8)
bkg:addEventListener("tap", function() return true end)
local frame = display.newRoundedRect(infoGroup, display.contentCenterX, display.contentCenterY, 460, 560, 20)
frame:setFillColor(0.1, 0.1, 0.15, 0.98); frame.strokeWidth = 3; frame:setStrokeColor(0, 0.8, 1)
local title = display.newText(infoGroup, "ПОЛНЫЙ ИНСПЕКТОР", frame.x, frame.y - 250, native.systemFontBold, 20)
local scrollView = widget.newScrollView({
x = frame.x, y = frame.y - 10,
width = 420, height = 420,
scrollWidth = 420, scrollHeight = 8000,
hideBackground = true, horizontalScrollDisabled = true
})
infoGroup:insert(scrollView)
local fullText = getFullInfo(obj)
local content = display.newText({
text = fullText,
x = 210, y = 0,
width = 400,
font = native.systemFont, fontSize = 14, align = "left"
})
content.anchorY = 0
content:setFillColor(0.9)
scrollView:insert(content)
-- Кнопка COPY
local btnCopy = display.newRoundedRect(infoGroup, frame.x - 100, frame.y + 240, 160, 40, 10)
btnCopy:setFillColor(0, 0.4, 0.7)
display.newText(infoGroup, "КОПИРОВАТЬ", btnCopy.x, btnCopy.y, native.systemFontBold, 16)
btnCopy:addEventListener("tap", function() copyToClipboard(fullText); return true end)
-- Кнопка CLOSE
local btnClose = display.newRoundedRect(infoGroup, frame.x + 100, frame.y + 240, 160, 40, 10)
btnClose:setFillColor(0.3, 0.1, 0.1)
display.newText(infoGroup, "ЗАКРЫТЬ", btnClose.x, btnClose.y, native.systemFontBold, 16)
btnClose:addEventListener("tap", function() infoGroup:removeSelf(); return true end)
end
-- Режим выбора (Прицел)
local function startPick()
local crosshair = display.newGroup()
local overlay = display.newRect(crosshair, display.contentCenterX, display.contentCenterY, display.contentWidth*2, display.contentHeight*2)
overlay:setFillColor(0, 1, 0.5, 0.15)
local help = display.newText(crosshair, "НАЖМИ НА ОБЪЕКТ", display.contentCenterX, 100, native.systemFontBold, 30)
overlay:addEventListener("touch", function(e)
if e.phase == "began" then
local function find(obj)
if obj and obj ~= overlay and obj.x and obj.isVisible then
local ox, oy = obj:localToContent(0,0)
local d = math.sqrt((e.x-ox)^2 + (e.y-oy)^2)
if d < 60 then return obj end
end
if obj.numChildren then
for i=obj.numChildren, 1, -1 do
local r = find(obj[i])
if r then return r end
end
end
return nil
end
local target = find(display.currentStage)
if target then
crosshair:removeSelf()
showInspector(target)
end
end
return true
end)
end
-- Маленькая плавающая кнопка "I"
local mainBtn = display.newCircle(display.contentWidth - 50, 200, 30)
mainBtn:setFillColor(0, 0.6, 0.3, 0.8); mainBtn.strokeWidth = 2; mainBtn:setStrokeColor(1)
display.newText("I", mainBtn.x, mainBtn.y, native.systemFontBold, 30)
mainBtn:addEventListener("tap", function() startPick(); return true end)