diff --git a/editor/src/editor/layout/inspector/script/field.tsx b/editor/src/editor/layout/inspector/script/field.tsx index f7922b343..916419a30 100644 --- a/editor/src/editor/layout/inspector/script/field.tsx +++ b/editor/src/editor/layout/inspector/script/field.tsx @@ -193,7 +193,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) { registerUndoRedo({ executeRedo: true, - action: () => props.editor.layout.preview.play.hotReloadScript(props.script.key, false), undo: () => (props.script[scriptValues][value.propertyKey].value = oldValue), redo: () => (props.script[scriptValues][value.propertyKey].value = v?.id), }); @@ -209,7 +208,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) { property="value" label={value.label ?? value.propertyKey} tooltip={value.configuration.description} - onChange={() => props.editor.layout.preview.play.hotReloadScript(props.script.key, false)} items={props.editor.layout.preview.scene.animationGroups.map((animationGroup) => ({ text: animationGroup.name, value: animationGroup.name, @@ -255,7 +253,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) { registerUndoRedo({ executeRedo: true, - action: () => props.editor.layout.preview.play.hotReloadScript(props.script.key, false), undo: () => (props.script[scriptValues][value.propertyKey].value = oldSerializedTexture), redo: () => (props.script[scriptValues][value.propertyKey].value = v?.serialize() ?? null), }); @@ -310,7 +307,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) { property="value" label={value.label ?? value.propertyKey} tooltip={value.configuration.description} - onChange={() => props.editor.layout.preview.play.hotReloadScript(props.script.key, false)} /> ); @@ -325,7 +321,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) { max={value.configuration.max} step={value.configuration.step} tooltip={value.configuration.description} - onChange={() => props.editor.layout.preview.play.hotReloadScript(props.script.key, false)} /> ); @@ -338,7 +333,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) { label={value.label ?? value.propertyKey} tooltip={value.configuration.description} multiline={(value.configuration as VisibleInInspectorDecoratorStringConfiguration).multiline} - onChange={() => props.editor.layout.preview.play.hotReloadScript(props.script.key, false)} /> ); @@ -363,7 +357,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) { const scriptCopy = cloneJSObject(props.script); props.script[scriptValues][value.propertyKey].value = tempVector.value.asArray(); - props.editor.layout.preview.play.hotReloadScript(props.script.key, false); props.script[scriptValues][value.propertyKey].value = scriptCopy[scriptValues][value.propertyKey].value; }} onFinishChange={() => { @@ -401,7 +394,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) { const scriptCopy = cloneJSObject(props.script); props.script[scriptValues][value.propertyKey].value = tempColor.value.asArray(); - props.editor.layout.preview.play.hotReloadScript(props.script.key, false); props.script[scriptValues][value.propertyKey].value = scriptCopy[scriptValues][value.propertyKey].value; }} onFinishChange={() => { @@ -425,7 +417,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) { label={value.label ?? value.propertyKey} onChange={(v) => { props.script[scriptValues][value.propertyKey].value = v; - props.editor.layout.preview.play.hotReloadScript(props.script.key, false); }} /> ); @@ -446,7 +437,6 @@ export function InspectorScriptField(props: IInspectorScriptFieldProps) { label={value.label ?? value.propertyKey} tooltip={value.configuration.description} typeRestriction={(value.configuration as VisibleInspectorDecoratorAssetConfiguration).typeRestriction} - onChange={() => props.editor.layout.preview.play.hotReloadScript(props.script.key, false)} /> ); diff --git a/editor/src/editor/layout/preview/play.tsx b/editor/src/editor/layout/preview/play.tsx index 7cd009b01..66598f952 100644 --- a/editor/src/editor/layout/preview/play.tsx +++ b/editor/src/editor/layout/preview/play.tsx @@ -10,17 +10,13 @@ import { Grid } from "react-loader-spinner"; import { IoPlay, IoStop, IoRefresh } from "react-icons/io5"; -import { IRegisteredScript } from "babylonjs-editor-tools"; -import { Node, Scene, Vector3, HavokPlugin, Sprite } from "babylonjs"; +import { Scene, Vector3, HavokPlugin } from "babylonjs"; import { ensureTemporaryDirectoryExists } from "../../../tools/project"; -import { isNode } from "../../../tools/guards/nodes"; -import { isScene } from "../../../tools/guards/scene"; -import { isSprite } from "../../../tools/guards/sprites"; +import { wait, waitNextAnimationFrame } from "../../../tools/tools"; import { compilePlayScript } from "../../../tools/scene/play/compile"; import { forceCompileAllSceneMaterials } from "../../../tools/scene/materials"; -import { cloneJSObject, wait, waitNextAnimationFrame } from "../../../tools/tools"; import { applyOverrides, restorePlayOverrides } from "../../../tools/scene/play/override"; import { exportProject } from "../../../project/export/export"; @@ -397,13 +393,7 @@ export class EditorPreviewPlayComponent extends Component { - allNodes.push(...manager.sprites); - }); - - allNodes.forEach((n) => { - const runningScripts = oldScriptExports.scriptsDictionary.get(n) as IRegisteredScript[] | undefined; - if (!runningScripts) { - return; - } - - const runningScriptsCopy = runningScripts.slice(); - - runningScriptsCopy.forEach(async (script) => { - if (script.key !== scriptKey) { - return; - } - - oldScriptExports._removeRegisteredScriptInstance(n, script); - - let sourceObject: Node | Scene | Sprite | null | undefined; - if (isScene(n)) { - sourceObject = originalScene; - } else if (isNode(n)) { - sourceObject = originalScene.getNodeById(n.id); - } else if (isSprite(n)) { - spriteLoop: for (const manager of originalScene.spriteManagers ?? []) { - for (const sprite of manager.sprites) { - if (sprite.uniqueId === n.uniqueId) { - sourceObject = sprite; - break spriteLoop; - } - } - } - } - - const sourceMetadata = sourceObject?.metadata?.scripts?.find((sourceScript) => sourceScript.key === script.key); - - if (sourceMetadata) { - n.metadata ??= {}; - n.metadata.scripts ??= []; - n.metadata.scripts.push(cloneJSObject(sourceMetadata)); - } - }); - }); - - this._compiledScriptExports._preloadScriptsAssets(this.scene, rootUrl).then(() => { - allNodes.forEach((n) => { - this._compiledScriptExports._applyScriptsForObject(this.scene!, n, this._compiledScriptExports.scriptsMap, rootUrl); - }); - }); - } } diff --git a/editor/src/project/export/assets.ts b/editor/src/project/export/assets.ts index a03992458..f9e2ce576 100644 --- a/editor/src/project/export/assets.ts +++ b/editor/src/project/export/assets.ts @@ -62,14 +62,12 @@ export async function processAssetFile(editor: Editor, file: string, options: Pr let isNewFile = false; - if (options.optimize) { - const fileStat = await stat(file); - const hash = fileStat.mtimeMs.toString(); + const fileStat = await stat(file); + const hash = fileStat.mtimeMs.toString(); - isNewFile = !options.cache[relativePath] || options.cache[relativePath] !== hash; + isNewFile = !options.cache[relativePath] || options.cache[relativePath] !== hash; - options.cache[relativePath] = hash; - } + options.cache[relativePath] = hash; const finalPath = join(options.scenePath, relativePath); const finalPathExists = await pathExists(finalPath); diff --git a/tools/src/loading/script/preload.ts b/tools/src/loading/script/preload.ts index 9a76e2208..3ce42cb6a 100644 --- a/tools/src/loading/script/preload.ts +++ b/tools/src/loading/script/preload.ts @@ -60,7 +60,7 @@ export async function _preloadScriptsAssets(rootUrl: string, scene: Scene, scrip } const obj = script.values[key]; - if (obj.type === "asset" && obj.value) { + if (obj.type === "asset" && obj.value && !scriptAssetsCache.get(obj.value)) { scriptAssetsCache.set(obj.value, null); } } diff --git a/yarn.lock b/yarn.lock index aafd20c64..bd9371237 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3949,8 +3949,9 @@ babylonjs-editor-tools@latest: resolved "https://registry.yarnpkg.com/babylonjs-editor-tools/-/babylonjs-editor-tools-5.0.0.tgz#d2e1919cc5d4defbcbcf60259a1eb73a589cf643" integrity sha512-AREjL0WjtjyOvud0EMG/II3zH73KlSif/u0HV965tPWmUZHrxr+g/4iX6eU0mIYlIjOuepfRAopaF04IYJOaHA== -"babylonjs-editor-tools@link:../../AppData/Local/Yarn/Cache/v6/npm-babylonjs-editor-5.2.4-3cce3a704dc0c4572a85041a993264060376230a-integrity/node_modules/tools": +"babylonjs-editor-tools@link:../../../Library/Caches/Yarn/v6/npm-babylonjs-editor-5.2.4-3cce3a704dc0c4572a85041a993264060376230a-integrity/node_modules/tools": version "0.0.0" + uid "" "babylonjs-editor-tools@link:tools": version "5.2.4"