This commit is contained in:
2026-06-24 20:23:12 -07:00
parent 6b704ff469
commit 37c8779d12
10 changed files with 512 additions and 399 deletions

View File

@ -727,7 +727,7 @@ _viewport_proc_build = None # Separate process tracker for viewport builds
def build_viewport(viewport_id, width=1920, height=1080):
"""Build project for viewport"""
global _viewport_build_in_progress, _viewport_pending_launches, profile_time
global _viewport_build_in_progress, _viewport_pending_launches, profile_time, scripts_mtime
wrd = bpy.data.worlds.get('Lnx')
if not wrd:
@ -769,6 +769,35 @@ def build_viewport(viewport_id, width=1920, height=1080):
state.is_publish = False
state.is_export = False
# Recompile detection (matching play() behavior)
if not wrd.lnx_cache_build or \
not os.path.isfile(krom_js_path) or \
assets.khafile_defs_last != assets.khafile_defs or \
state.last_target != state.target:
wrd.lnx_recompile = True
state.last_target = state.target
# Trait sources modified
state.mod_scripts = []
script_path = lnx.utils.get_fp() + '/Sources/' + lnx.utils.safestr(wrd.lnx_project_package)
if os.path.isdir(script_path):
new_mtime = scripts_mtime
for fn in glob.iglob(os.path.join(script_path, '**', '*.hx'), recursive=True):
mtime = os.path.getmtime(fn)
if scripts_mtime < mtime:
lnx.utils.fetch_script_props(fn)
fn = fn.split('Sources/')[1]
fn = fn[:-3] #.hx
fn = fn.replace('/', '.')
state.mod_scripts.append(fn)
wrd.lnx_recompile = True
if new_mtime < mtime:
new_mtime = mtime
scripts_mtime = new_mtime
if len(state.mod_scripts) > 0:
lnx.utils.fetch_trait_props()
log.clear(clear_warnings=True, clear_errors=True)
sdk_path = lnx.utils.get_sdk_path()
@ -817,7 +846,8 @@ def compile_viewport(assets_only=False):
if not wrd.lnx_verbose_output:
cmd.append("--quiet")
if assets_only:
krom_js_path = lnx.utils.build_dir() + '/debug/krom/krom.js'
if assets_only and os.path.exists(krom_js_path):
cmd.append('--nohaxe')
cmd.append('--noproject')
@ -856,7 +886,7 @@ def viewport_build_done():
def play_viewport(viewport_id, width=1920, height=1080):
"""Launch Krom in a viewport"""
global _viewport_build_in_progress, _viewport_pending_launches, _viewport_proc_build
global _viewport_build_in_progress, _viewport_pending_launches, _viewport_proc_build, scripts_mtime
if not viewport_id:
log.error('No viewport_id: play_viewport requires an id')
@ -895,9 +925,38 @@ def play_viewport(viewport_id, width=1920, height=1080):
os.makedirs(sources_path)
# export data same as play() but without setting state.is_play
state.is_viewport = True
state.target = 'krom'
state.is_publish = False
state.is_export = False
if not wrd.lnx_cache_build or \
not os.path.isfile(krom_js_path) or \
assets.khafile_defs_last != assets.khafile_defs or \
state.last_target != state.target:
wrd.lnx_recompile = True
state.last_target = state.target
state.mod_scripts = []
script_path = lnx.utils.get_fp() + '/Sources/' + lnx.utils.safestr(wrd.lnx_project_package)
if os.path.isdir(script_path):
new_mtime = scripts_mtime
for fn in glob.iglob(os.path.join(script_path, '**', '*.hx'), recursive=True):
mtime = os.path.getmtime(fn)
if scripts_mtime < mtime:
lnx.utils.fetch_script_props(fn)
fn = fn.split('Sources/')[1]
fn = fn[:-3] #.hx
fn = fn.replace('/', '.')
state.mod_scripts.append(fn)
wrd.lnx_recompile = True
if new_mtime < mtime:
new_mtime = mtime
scripts_mtime = new_mtime
if len(state.mod_scripts) > 0:
lnx.utils.fetch_trait_props()
export_data(fp, sdk_path)
compile_viewport(assets_only=(not wrd.lnx_recompile))