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()
|
previewTimer:start()
|
||||||
|
|
||||||
local pvStaLastVersion = 0 -- track sprite version to detect edits
|
local pvStaLastFile = ""
|
||||||
local pvStaLastFrame = 0
|
local pvStaLastFrame = 0
|
||||||
|
local pvStaTickCount = 0
|
||||||
|
|
||||||
pvRefreshTimer = Timer{
|
pvRefreshTimer = Timer{
|
||||||
interval = 0.5,
|
interval = 0.5,
|
||||||
ontick = function()
|
ontick = function()
|
||||||
refreshLockFile()
|
refreshLockFile()
|
||||||
if S.previewMode == "static" then
|
if S.previewMode == "static" then
|
||||||
-- Only refresh source and repaint when sprite actually changed
|
-- Detect file or frame change cheaply
|
||||||
local curVer = app.sprite and app.sprite.version or 0
|
local curFile = app.sprite and app.sprite.filename or ""
|
||||||
local curFrame = app.frame and app.frame.frameNumber or 0
|
local curFrame = app.frame and app.frame.frameNumber or 0
|
||||||
if curVer ~= pvStaLastVersion or curFrame ~= pvStaLastFrame then
|
local changed = (curFile ~= pvStaLastFile or curFrame ~= pvStaLastFrame)
|
||||||
pvStaLastVersion = curVer
|
pvStaLastFile = curFile
|
||||||
pvStaLastFrame = curFrame
|
pvStaLastFrame = curFrame
|
||||||
|
-- Also refresh every 5 ticks (2.5s) to catch edits
|
||||||
|
pvStaTickCount = pvStaTickCount + 1
|
||||||
|
if changed or pvStaTickCount >= 5 then
|
||||||
|
pvStaTickCount = 0
|
||||||
refreshSource()
|
refreshSource()
|
||||||
pcall(function() previewDlg:repaint() end)
|
pcall(function() previewDlg:repaint() end)
|
||||||
end
|
end
|
||||||
|
|
@ -1617,6 +1622,20 @@ openPreviewWindow = function()
|
||||||
if presetForFile ~= S.currentPreset then
|
if presetForFile ~= S.currentPreset then
|
||||||
loadPreset(presetForFile)
|
loadPreset(presetForFile)
|
||||||
S.currentPreset = 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)
|
-- Refresh UI if main dialog is open (don't touch preview - avoids repositioning)
|
||||||
if mainDlg then
|
if mainDlg then
|
||||||
pcall(function() mainDlg:close() end)
|
pcall(function() mainDlg:close() end)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue