Fix sprite.version crash and stale anim name on preset switch
- Remove app.sprite.version (doesn't exist in Aseprite API), use filename + frame number + periodic refresh every 2.5s for edits - Clamp previewSingleIdx and update pvAnimName label when switching presets, so One mode doesn't show names from another preset
This commit is contained in:
parent
ca3f760d87
commit
df9a2a3dcf
|
|
@ -1586,20 +1586,25 @@ openPreviewWindow = function()
|
|||
}
|
||||
previewTimer:start()
|
||||
|
||||
local pvStaLastVersion = 0 -- track sprite version to detect edits
|
||||
local pvStaLastFile = ""
|
||||
local pvStaLastFrame = 0
|
||||
local pvStaTickCount = 0
|
||||
|
||||
pvRefreshTimer = Timer{
|
||||
interval = 0.5,
|
||||
ontick = function()
|
||||
refreshLockFile()
|
||||
if S.previewMode == "static" then
|
||||
-- Only refresh source and repaint when sprite actually changed
|
||||
local curVer = app.sprite and app.sprite.version or 0
|
||||
-- Detect file or frame change cheaply
|
||||
local curFile = app.sprite and app.sprite.filename or ""
|
||||
local curFrame = app.frame and app.frame.frameNumber or 0
|
||||
if curVer ~= pvStaLastVersion or curFrame ~= pvStaLastFrame then
|
||||
pvStaLastVersion = curVer
|
||||
pvStaLastFrame = curFrame
|
||||
local changed = (curFile ~= pvStaLastFile or curFrame ~= pvStaLastFrame)
|
||||
pvStaLastFile = curFile
|
||||
pvStaLastFrame = curFrame
|
||||
-- Also refresh every 5 ticks (2.5s) to catch edits
|
||||
pvStaTickCount = pvStaTickCount + 1
|
||||
if changed or pvStaTickCount >= 5 then
|
||||
pvStaTickCount = 0
|
||||
refreshSource()
|
||||
pcall(function() previewDlg:repaint() end)
|
||||
end
|
||||
|
|
@ -1617,6 +1622,20 @@ openPreviewWindow = function()
|
|||
if presetForFile ~= S.currentPreset then
|
||||
loadPreset(presetForFile)
|
||||
S.currentPreset = presetForFile
|
||||
-- Clamp previewSingleIdx to new preset's anims
|
||||
if #S.animNames == 0 then
|
||||
S.previewSingleIdx = 1
|
||||
elseif S.previewSingleIdx > #S.animNames then
|
||||
S.previewSingleIdx = #S.animNames
|
||||
end
|
||||
-- Update preview label for One mode
|
||||
pcall(function()
|
||||
local name = ""
|
||||
if S.previewSingleIdx >= 1 and S.previewSingleIdx <= #S.animNames then
|
||||
name = S.animNames[S.previewSingleIdx]
|
||||
end
|
||||
previewDlg:modify{ id = "pvAnimName", text = name }
|
||||
end)
|
||||
-- Refresh UI if main dialog is open (don't touch preview - avoids repositioning)
|
||||
if mainDlg then
|
||||
pcall(function() mainDlg:close() end)
|
||||
|
|
|
|||
Loading…
Reference in New Issue