diff --git a/sources/engine/Stride.ClearScript/ClearScriptSystem.cs b/sources/engine/Stride.ClearScript/ClearScriptSystem.cs index 2ebee1cbb9..f4a33936bb 100644 --- a/sources/engine/Stride.ClearScript/ClearScriptSystem.cs +++ b/sources/engine/Stride.ClearScript/ClearScriptSystem.cs @@ -45,7 +45,7 @@ public void Initialize() engine.DocumentSettings.Loader = loader; engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading; - engine.AddHostType("Console", typeof(Console)); + engine.AddHostType("MSConsole", typeof(Console)); } public object Execute() @@ -70,11 +70,12 @@ public async Task loadFile(string fileName) try { string source = await streamReader.ReadToEndAsync(); + var path = Path.GetDirectoryName(fileName)+Path.DirectorySeparatorChar; + var doc = new DocumentInfo(new Uri(@"\\js"+path)); - var script= engine.Evaluate(new DocumentInfo (){ - Category = ModuleCategory.Standard - }, source); - Console.WriteLine("------javascript c={0}", script.c); + doc.Category = ModuleCategory.Standard; + var script = engine.Evaluate(doc, source); + // Console.WriteLine("------javascript c={0}", script.c); }catch(Exception e) { Console.WriteLine(e.Message); @@ -83,19 +84,19 @@ public async Task loadFile(string fileName) } } - public object CreatePromiseForTask(Task task) - { - return engine.CreatePromiseForTask(task); - } + //public object CreatePromiseForTask(Task task) + //{ + // return engine.CreatePromiseForTask(task); + //} - public object CreatePromiseForTask(Task task) - { - return engine.CreatePromiseForTask(task); - } + //public object CreatePromiseForTask(Task task) + //{ + // return engine.CreatePromiseForTask(task); + //} - public Task CreateTaskForPromise(object promise) - { - return engine.CreateTaskForPromise(promise); - } + //public Task CreateTaskForPromise(object promise) + //{ + // return engine.CreateTaskForPromise(promise); + //} } } diff --git a/sources/engine/Stride.ClearScript/Components/ClearScriptComponent.cs b/sources/engine/Stride.ClearScript/Components/ClearScriptComponent.cs index f313704adf..9970c82fa1 100644 --- a/sources/engine/Stride.ClearScript/Components/ClearScriptComponent.cs +++ b/sources/engine/Stride.ClearScript/Components/ClearScriptComponent.cs @@ -31,28 +31,28 @@ namespace Stride.ClearScript [AllowMultipleComponents] [ComponentOrder(1000)] [ComponentCategory("ClearScripts")] - public class ClearScriptComponent: EntityComponent, ICollectorHolder - { - public const uint LiveScriptingMask = 128; + public class ClearScriptComponent : EntityComponent, ICollectorHolder + { + public const uint LiveScriptingMask = 128; - /// - /// The global profiling key for scripts. Activate/deactivate this key to activate/deactivate profiling for all your scripts. - /// - public static readonly ProfilingKey ScriptGlobalProfilingKey = new ProfilingKey("Script"); + /// + /// The global profiling key for scripts. Activate/deactivate this key to activate/deactivate profiling for all your scripts. + /// + public static readonly ProfilingKey ScriptGlobalProfilingKey = new ProfilingKey("Script"); - private static readonly Dictionary ScriptToProfilingKey = new Dictionary(); + private static readonly Dictionary ScriptToProfilingKey = new Dictionary(); - private ProfilingKey profilingKey; + private ProfilingKey profilingKey; - //private IGraphicsDeviceService graphicsDeviceService; - private Logger logger; + //private IGraphicsDeviceService graphicsDeviceService; + private Logger logger; private dynamic scriptObj; - protected ClearScriptComponent() - { - - } + protected ClearScriptComponent() + { + + } internal void Initialize(IServiceRegistry registry) { @@ -80,120 +80,124 @@ internal void Initialize(IServiceRegistry registry) }; scriptObj.Initialize(args); } - catch(Exception e) + catch (Exception e) { } - - } + + } protected Entity entity; - public Entity Entity { get=>entity; internal set { + public Entity Entity + { + get => entity; internal set + { entity = value; scriptObj.Entity = value; - } } + } + } /// /// Gets the profiling key to activate/deactivate profiling for the current script class. /// [DataMemberIgnore] - public ProfilingKey ProfilingKey - { - get + public ProfilingKey ProfilingKey { - if (profilingKey != null) - return profilingKey; - - var scriptType = GetType(); - if (!ScriptToProfilingKey.TryGetValue(scriptType, out profilingKey)) + get { - profilingKey = new ProfilingKey(ScriptGlobalProfilingKey, scriptType.FullName); - ScriptToProfilingKey[scriptType] = profilingKey; - } + if (profilingKey != null) + return profilingKey; - return profilingKey; + var scriptType = GetType(); + if (!ScriptToProfilingKey.TryGetValue(scriptType, out profilingKey)) + { + profilingKey = new ProfilingKey(ScriptGlobalProfilingKey, scriptType.FullName); + ScriptToProfilingKey[scriptType] = profilingKey; + } + + return profilingKey; + } } - } - - /// - /// Gets the streaming system. - /// - /// The streaming system. - [DataMemberIgnore] - public StreamingManager Streaming { get; private set; } + + /// + /// Gets the streaming system. + /// + /// The streaming system. + [DataMemberIgnore] + public StreamingManager Streaming { get; private set; } [DataMemberIgnore] public IClearScriptSystem ScriptSystem { get; private set; } [DataMemberIgnore] - protected Logger Log - { - get + protected Logger Log { - if (logger != null) + get { + if (logger != null) + { + return logger; + } + + var className = GetType().FullName; + logger = GlobalLogger.GetLogger(className); return logger; } - - var className = GetType().FullName; - logger = GlobalLogger.GetLogger(className); - return logger; } - } - private int priority; + private int priority; - /// - /// The priority this script will be scheduled with (compared to other scripts). - /// - /// The execution priority for this script. It applies to async, sync and startup scripts. Lower values mean earlier execution. - [DefaultValue(0)] - [DataMember(10000)] - public int Priority - { - get { return priority; } - set { priority = value; PriorityUpdated(); } - } + /// + /// The priority this script will be scheduled with (compared to other scripts). + /// + /// The execution priority for this script. It applies to async, sync and startup scripts. Lower values mean earlier execution. + [DefaultValue(0)] + [DataMember(10000)] + public int Priority + { + get { return priority; } + set { priority = value; PriorityUpdated(); } + } - /// - /// Determines whether the script is currently undergoing live reloading. - /// - public bool IsLiveReloading { get; internal set; } + /// + /// Determines whether the script is currently undergoing live reloading. + /// + public bool IsLiveReloading { get; internal set; } - /// - /// The object collector associated with this script. - /// - [DataMemberIgnore] - public ObjectCollector Collector - { - get + /// + /// The object collector associated with this script. + /// + [DataMemberIgnore] + public ObjectCollector Collector { - collector.EnsureValid(); - return collector; + get + { + collector.EnsureValid(); + return collector; + } } - } - private ObjectCollector collector; + private ObjectCollector collector; - - /// - /// Called when the script's update loop is canceled. - /// - public void Cancel() - { - scriptObj.Cancel(); - collector.Dispose(); - } - public void Start() + /// + /// Called when the script's update loop is canceled. + /// + public void Cancel() + { + scriptObj.Cancel(); + collector.Dispose(); + } + + public void Start() { scriptObj.Start(); } - internal PriorityQueueNode UpdateSchedulerNode; + // internal PriorityQueueNode UpdateSchedulerNode; public bool hasProperty(string propertyName) { @@ -204,7 +208,7 @@ public bool hasProperty(string propertyName) /// /// Called every frame. /// - public void Update() + public void Update() { scriptObj.Update(); } @@ -224,10 +228,10 @@ public void Update() /// Called once, as a microthread /// /// - public Task Execute() - { + //public Task Execute() + //{ - } + //} protected internal void PriorityUpdated() { diff --git a/sources/engine/Stride.ClearScript/Processors/ClearScriptSystem.cs b/sources/engine/Stride.ClearScript/Processors/ClearScriptSystem.cs index 99d39706db..1c41eec099 100644 --- a/sources/engine/Stride.ClearScript/Processors/ClearScriptSystem.cs +++ b/sources/engine/Stride.ClearScript/Processors/ClearScriptSystem.cs @@ -1,266 +1,266 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Stride.Core; -using Stride.Core.Diagnostics; -using Stride.Core.MicroThreading; -using Stride.Games; - -namespace Stride.ClearScript.Processors -{ - public sealed class ClearScriptSystem : GameSystemBase - { - private const long UpdateBit = 1L << 32; - - internal static readonly Logger Log = GlobalLogger.GetLogger("ScriptSystem"); - - /// - /// Contains all currently executed scripts - /// - private readonly HashSet registeredScripts = new HashSet(); - private readonly HashSet scriptsToStart = new HashSet(); - private readonly HashSet syncScripts = new HashSet(); - private readonly List scriptsToStartCopy = new List(); - private readonly List syncScriptsCopy = new List(); - - /// - /// Gets the scheduler. - /// - /// The scheduler. - public Scheduler Scheduler { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// The registry. - /// The GameSystem is expecting the following services to be registered: and . - public ClearScriptSystem(IServiceRegistry registry) - : base(registry) - { - Enabled = true; - Scheduler = new Scheduler(); - Scheduler.ActionException += Scheduler_ActionException; - } - - protected override void Destroy() - { - Scheduler.ActionException -= Scheduler_ActionException; - Scheduler = null; - - Services.RemoveService(); - - base.Destroy(); - } - - public override void Update(GameTime gameTime) - { - // Copy scripts to process (so that scripts added during this frame don't affect us) - // TODO: How to handle scripts that we want to start during current frame? - scriptsToStartCopy.AddRange(scriptsToStart); - scriptsToStart.Clear(); - syncScriptsCopy.AddRange(syncScripts); - - // Schedule new scripts: StartupScript.Start() and AsyncScript.Execute() - foreach (var script in scriptsToStartCopy) - { - // Start the script - var startupScript = script; - if (startupScript != null) - { - startupScript.StartSchedulerNode = Scheduler.Add(startupScript.Start, startupScript.Priority, startupScript, startupScript.ProfilingKey); - } - else - { - // Start a microthread with execute method if it's an async script - var asyncScript = script as AsyncScript; - if (asyncScript != null) - { - asyncScript.MicroThread = AddTask(asyncScript.Execute, asyncScript.Priority | UpdateBit); - asyncScript.MicroThread.ProfilingKey = asyncScript.ProfilingKey; - } - } - } - - // Schedule existing scripts: SyncScript.Update() - foreach (var syncScript in syncScriptsCopy) - { - // Update priority - var updateSchedulerNode = syncScript.UpdateSchedulerNode; - updateSchedulerNode.Value.Priority = syncScript.Priority | UpdateBit; - - // Schedule - Scheduler.Schedule(updateSchedulerNode, ScheduleMode.Last); - } - - // Run current micro threads - Scheduler.Run(); - - // Flag scripts as not being live reloaded after starting/executing them for the first time - foreach (var script in scriptsToStartCopy) - { - // Remove the start node after it got executed - var startupScript = script;//as StartupScript; - if (startupScript != null) - { - startupScript.StartSchedulerNode = null; - } - - if (script.IsLiveReloading) - script.IsLiveReloading = false; - } - - scriptsToStartCopy.Clear(); - syncScriptsCopy.Clear(); - } - - /// - /// Allows to wait for next frame. - /// - /// ChannelMicroThreadAwaiter<System.Int32>. - public ChannelMicroThreadAwaiter NextFrame() - { - return Scheduler.NextFrame(); - } - - /// - /// Adds the specified micro thread function. - /// - /// The micro thread function. - /// MicroThread. - public MicroThread AddTask(Func microThreadFunction, long priority = 0) - { - var microThread = Scheduler.Create(); - microThread.Priority = priority; - microThread.Start(microThreadFunction); - return microThread; - } - - /// - /// Waits all micro thread finished their task completion. - /// - /// The micro threads. - /// Task. - public async Task WhenAll(params MicroThread[] microThreads) - { - await Scheduler.WhenAll(microThreads); - } - - /// - /// Add the provided script to the script system. - /// - /// The script to add - public void Add(ClearScriptComponent script) - { - script.Initialize(Services); - registeredScripts.Add(script); - - // Register script for Start() and possibly async Execute() - scriptsToStart.Add(script); - - // If it's a synchronous script, add it to the list as well - // var syncScript = script;//as SyncScript; - if (script.hasProperty("Update")) - { - script.UpdateSchedulerNode = Scheduler.Create(script.Update, script.Priority | UpdateBit); - script.UpdateSchedulerNode.Value.Token = script; - script.UpdateSchedulerNode.Value.ProfilingKey = script.ProfilingKey; - syncScripts.Add(script); - } - } - - /// - /// Remove the provided script from the script system. - /// - /// The script to remove - public void Remove(ClearScriptComponent script) - { - // Make sure it's not registered in any pending list - var startWasPending = scriptsToStart.Remove(script); - var wasRegistered = registeredScripts.Remove(script); - - if (!startWasPending && wasRegistered) - { - // Cancel scripts that were already started - try - { - script.Cancel(); - } - catch (Exception e) - { - HandleSynchronousException(script, e); - } - - var asyncScript = script;// as AsyncScript; - asyncScript.MicroThread?.Cancel(); - } - - // Remove script from the scheduler, in case it was removed during scheduler execution - var startupScript = script;//as StartupScript; - if (startupScript != null) - { - if (startupScript.StartSchedulerNode != null) - { - Scheduler?.Unschedule(startupScript.StartSchedulerNode); - startupScript.StartSchedulerNode = null; - } - - //var syncScript = script as SyncScript; - if (script.hasProperty("Update")) - { - syncScripts.Remove(script); - Scheduler?.Unschedule(script.UpdateSchedulerNode); - script.UpdateSchedulerNode = null; - } - } - } - - /// - /// Called by a live scripting debugger to notify the ScriptSystem about reloaded scripts. - /// - /// The old script - /// The new script - public void LiveReload(ClearScriptComponent oldScript, ClearScriptComponent newScript) - { - // Set live reloading mode for the rest of it's lifetime - oldScript.IsLiveReloading = true; - - // Set live reloading mode until after being started - newScript.IsLiveReloading = true; - } - - private void Scheduler_ActionException(Scheduler scheduler, SchedulerEntry schedulerEntry, Exception e) - { - HandleSynchronousException((ClearScriptComponent)schedulerEntry.Token, e); - } - - private void HandleSynchronousException(ClearScriptComponent script, Exception e) - { - Log.Error("Unexpected exception while executing a script.", e); - - // Only crash if live scripting debugger is not listening - if (Scheduler.PropagateExceptions) - ExceptionDispatchInfo.Capture(e).Throw(); - - // Remove script from all lists - //var syncScript = script as SyncScript; - if (script.hasProperty("Update")) - { - syncScripts.Remove(script); - } - - registeredScripts.Remove(script); - } - - private class PriorityScriptComparer : IComparer - { - public static readonly PriorityScriptComparer Default = new PriorityScriptComparer(); - - public int Compare(ClearScriptComponent x, ClearScriptComponent y) - { - return x.Priority.CompareTo(y.Priority); - } - } - } -} +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; +//using Stride.Core; +//using Stride.Core.Diagnostics; +//using Stride.Core.MicroThreading; +//using Stride.Games; + +//namespace Stride.ClearScript.Processors +//{ +// public sealed class ClearScriptSystem : GameSystemBase +// { +// private const long UpdateBit = 1L << 32; + +// internal static readonly Logger Log = GlobalLogger.GetLogger("ScriptSystem"); + +// /// +// /// Contains all currently executed scripts +// /// +// private readonly HashSet registeredScripts = new HashSet(); +// private readonly HashSet scriptsToStart = new HashSet(); +// private readonly HashSet syncScripts = new HashSet(); +// private readonly List scriptsToStartCopy = new List(); +// private readonly List syncScriptsCopy = new List(); + +// /// +// /// Gets the scheduler. +// /// +// /// The scheduler. +// public Scheduler Scheduler { get; private set; } + +// /// +// /// Initializes a new instance of the class. +// /// +// /// The registry. +// /// The GameSystem is expecting the following services to be registered: and . +// public ClearScriptSystem(IServiceRegistry registry) +// : base(registry) +// { +// Enabled = true; +// Scheduler = new Scheduler(); +// Scheduler.ActionException += Scheduler_ActionException; +// } + +// protected override void Destroy() +// { +// Scheduler.ActionException -= Scheduler_ActionException; +// Scheduler = null; + +// Services.RemoveService(); + +// base.Destroy(); +// } + +// public override void Update(GameTime gameTime) +// { +// // Copy scripts to process (so that scripts added during this frame don't affect us) +// // TODO: How to handle scripts that we want to start during current frame? +// scriptsToStartCopy.AddRange(scriptsToStart); +// scriptsToStart.Clear(); +// syncScriptsCopy.AddRange(syncScripts); + +// // Schedule new scripts: StartupScript.Start() and AsyncScript.Execute() +// foreach (var script in scriptsToStartCopy) +// { +// // Start the script +// var startupScript = script; +// if (startupScript != null) +// { +// startupScript.StartSchedulerNode = Scheduler.Add(startupScript.Start, startupScript.Priority, startupScript, startupScript.ProfilingKey); +// } +// else +// { +// // Start a microthread with execute method if it's an async script +// var asyncScript = script as AsyncScript; +// if (asyncScript != null) +// { +// asyncScript.MicroThread = AddTask(asyncScript.Execute, asyncScript.Priority | UpdateBit); +// asyncScript.MicroThread.ProfilingKey = asyncScript.ProfilingKey; +// } +// } +// } + +// // Schedule existing scripts: SyncScript.Update() +// foreach (var syncScript in syncScriptsCopy) +// { +// // Update priority +// var updateSchedulerNode = syncScript.UpdateSchedulerNode; +// updateSchedulerNode.Value.Priority = syncScript.Priority | UpdateBit; + +// // Schedule +// Scheduler.Schedule(updateSchedulerNode, ScheduleMode.Last); +// } + +// // Run current micro threads +// Scheduler.Run(); + +// // Flag scripts as not being live reloaded after starting/executing them for the first time +// foreach (var script in scriptsToStartCopy) +// { +// // Remove the start node after it got executed +// var startupScript = script;//as StartupScript; +// if (startupScript != null) +// { +// startupScript.StartSchedulerNode = null; +// } + +// if (script.IsLiveReloading) +// script.IsLiveReloading = false; +// } + +// scriptsToStartCopy.Clear(); +// syncScriptsCopy.Clear(); +// } + +// /// +// /// Allows to wait for next frame. +// /// +// /// ChannelMicroThreadAwaiter<System.Int32>. +// public ChannelMicroThreadAwaiter NextFrame() +// { +// return Scheduler.NextFrame(); +// } + +// /// +// /// Adds the specified micro thread function. +// /// +// /// The micro thread function. +// /// MicroThread. +// public MicroThread AddTask(Func microThreadFunction, long priority = 0) +// { +// var microThread = Scheduler.Create(); +// microThread.Priority = priority; +// microThread.Start(microThreadFunction); +// return microThread; +// } + +// /// +// /// Waits all micro thread finished their task completion. +// /// +// /// The micro threads. +// /// Task. +// public async Task WhenAll(params MicroThread[] microThreads) +// { +// await Scheduler.WhenAll(microThreads); +// } + +// /// +// /// Add the provided script to the script system. +// /// +// /// The script to add +// public void Add(ClearScriptComponent script) +// { +// script.Initialize(Services); +// registeredScripts.Add(script); + +// // Register script for Start() and possibly async Execute() +// scriptsToStart.Add(script); + +// // If it's a synchronous script, add it to the list as well +// // var syncScript = script;//as SyncScript; +// if (script.hasProperty("Update")) +// { +// script.UpdateSchedulerNode = Scheduler.Create(script.Update, script.Priority | UpdateBit); +// script.UpdateSchedulerNode.Value.Token = script; +// script.UpdateSchedulerNode.Value.ProfilingKey = script.ProfilingKey; +// syncScripts.Add(script); +// } +// } + +// /// +// /// Remove the provided script from the script system. +// /// +// /// The script to remove +// public void Remove(ClearScriptComponent script) +// { +// // Make sure it's not registered in any pending list +// var startWasPending = scriptsToStart.Remove(script); +// var wasRegistered = registeredScripts.Remove(script); + +// if (!startWasPending && wasRegistered) +// { +// // Cancel scripts that were already started +// try +// { +// script.Cancel(); +// } +// catch (Exception e) +// { +// HandleSynchronousException(script, e); +// } + +// var asyncScript = script;// as AsyncScript; +// asyncScript.MicroThread?.Cancel(); +// } + +// // Remove script from the scheduler, in case it was removed during scheduler execution +// var startupScript = script;//as StartupScript; +// if (startupScript != null) +// { +// if (startupScript.StartSchedulerNode != null) +// { +// Scheduler?.Unschedule(startupScript.StartSchedulerNode); +// startupScript.StartSchedulerNode = null; +// } + +// //var syncScript = script as SyncScript; +// if (script.hasProperty("Update")) +// { +// syncScripts.Remove(script); +// Scheduler?.Unschedule(script.UpdateSchedulerNode); +// script.UpdateSchedulerNode = null; +// } +// } +// } + +// /// +// /// Called by a live scripting debugger to notify the ScriptSystem about reloaded scripts. +// /// +// /// The old script +// /// The new script +// public void LiveReload(ClearScriptComponent oldScript, ClearScriptComponent newScript) +// { +// // Set live reloading mode for the rest of it's lifetime +// oldScript.IsLiveReloading = true; + +// // Set live reloading mode until after being started +// newScript.IsLiveReloading = true; +// } + +// private void Scheduler_ActionException(Scheduler scheduler, SchedulerEntry schedulerEntry, Exception e) +// { +// HandleSynchronousException((ClearScriptComponent)schedulerEntry.Token, e); +// } + +// private void HandleSynchronousException(ClearScriptComponent script, Exception e) +// { +// Log.Error("Unexpected exception while executing a script.", e); + +// // Only crash if live scripting debugger is not listening +// if (Scheduler.PropagateExceptions) +// ExceptionDispatchInfo.Capture(e).Throw(); + +// // Remove script from all lists +// //var syncScript = script as SyncScript; +// if (script.hasProperty("Update")) +// { +// syncScripts.Remove(script); +// } + +// registeredScripts.Remove(script); +// } + +// private class PriorityScriptComparer : IComparer +// { +// public static readonly PriorityScriptComparer Default = new PriorityScriptComparer(); + +// public int Compare(ClearScriptComponent x, ClearScriptComponent y) +// { +// return x.Priority.CompareTo(y.Priority); +// } +// } +// } +//} diff --git a/sources/engine/Stride.ClearScript/StrideJavaScriptLoader.cs b/sources/engine/Stride.ClearScript/StrideJavaScriptLoader.cs index 3a75543897..3e9e2be780 100644 --- a/sources/engine/Stride.ClearScript/StrideJavaScriptLoader.cs +++ b/sources/engine/Stride.ClearScript/StrideJavaScriptLoader.cs @@ -21,8 +21,6 @@ public static IEnumerable ToEnumerable(this T element) yield return element; } - - public static IEnumerable ExcludeIndices(this IEnumerable names) { foreach (var name in names) @@ -71,7 +69,7 @@ public static byte[] ReadToEnd(this Stream stream) } } } - internal class StrideJavaScriptLoader : DocumentLoader + internal class StrideJavaScriptLoader : DocumentLoader { private static readonly IReadOnlyCollection relativePrefixes = new List { @@ -136,14 +134,14 @@ private static bool TryCombineSearchUri(Uri searchUri, string specifier, out Uri private async Task IsCandidateUriAsync(DocumentSettings settings, Uri uri) { return uri.IsFile ? - settings.AccessFlags.HasFlag(DocumentAccessFlags.EnableFileLoading) && await FileDocumentExistsAsync(uri.LocalPath).ConfigureAwait(false) : + settings.AccessFlags.HasFlag(DocumentAccessFlags.EnableFileLoading) && await FileDocumentExistsAsync(uri.AbsolutePath).ConfigureAwait(false) : settings.AccessFlags.HasFlag(DocumentAccessFlags.EnableWebLoading) && await WebDocumentExistsAsync(uri).ConfigureAwait(false); } private Task FileDocumentExistsAsync(string path) { Interlocked.Increment(ref fileCheckCount); - return Task.FromResult(File.Exists(path)); + return Task.FromResult(VirtualFileSystem.FileExists(path)); } private Task WebDocumentExistsAsync(Uri uri) @@ -205,14 +203,15 @@ private static IEnumerable GetRawUris(DocumentSettings settings, DocumentIn // yield return uri; //} - using (var process = Process.GetCurrentProcess()) - { - var module = process.MainModule; - if ((module != null) && Uri.TryCreate(module.FileName, UriKind.Absolute, out baseUri) && Uri.TryCreate(baseUri, specifier, out uri)) - { - yield return uri; - } - } + + //using (var process = Process.GetCurrentProcess()) + //{ + // var module = process.MainModule; + // if ((module != null) && Uri.TryCreate(module.FileName, UriKind.Absolute, out baseUri) && Uri.TryCreate(baseUri, specifier, out uri)) + // { + // yield return uri; + // } + //} } private static IEnumerable ApplyExtensions(DocumentInfo? sourceInfo, Uri uri, string extensions) @@ -323,10 +322,9 @@ private async Task LoadDocumentAsync(DocumentSettings settings, Uri ur if (uri.IsFile) { - using (var reader = new StreamReader(uri.LocalPath)) - { - contents = await reader.ReadToEndAsync().ConfigureAwait(false); - } + using var stream = VirtualFileSystem.OpenStream(uri.AbsolutePath, VirtualFileMode.Open, VirtualFileAccess.Read); + using var streamReader = new StreamReader(stream); + contents = await streamReader.ReadToEndAsync(); } else { diff --git a/sources/engine/Stride.Engine.Tests/ClearScriptTest.cs b/sources/engine/Stride.Engine.Tests/ClearScriptTest.cs index bce74a0ac7..7a73006a78 100644 --- a/sources/engine/Stride.Engine.Tests/ClearScriptTest.cs +++ b/sources/engine/Stride.Engine.Tests/ClearScriptTest.cs @@ -22,7 +22,8 @@ public void Constructor1Tests() scriptSystem = new ClearScriptSystem(Services); scriptSystem.Initialize(); - scriptSystem.loadFile("/local/src/main.js"); + scriptSystem.loadFile("/local/src/demo/testModule.js"); + //scriptSystem.loadFile("//local/src/modules/add.js"); } @@ -32,7 +33,8 @@ protected override async Task LoadContent() scriptSystem = new ClearScriptSystem(Services); scriptSystem.Initialize(); - scriptSystem.loadFile("/local/src/main.js"); + //scriptSystem.loadFile("/local/src/main.js"); + scriptSystem.loadFile("//local/src/modules/add.js"); } [Fact] diff --git a/tsProj/tsSrc/Stride/dotNet.ts b/tsProj/tsSrc/Stride/dotNet.ts index 67d575986c..88ef531fca 100644 --- a/tsProj/tsSrc/Stride/dotNet.ts +++ b/tsProj/tsSrc/Stride/dotNet.ts @@ -5,4 +5,9 @@ declare class Guid{ -} \ No newline at end of file +} + +interface IMSConsole{ + WriteLine(str:string,...args:any[]):void +} +declare let MSConsole:IMSConsole \ No newline at end of file diff --git a/tsProj/tsSrc/demo/testModule.ts b/tsProj/tsSrc/demo/testModule.ts new file mode 100644 index 0000000000..715111fc4d --- /dev/null +++ b/tsProj/tsSrc/demo/testModule.ts @@ -0,0 +1,4 @@ +import { add } from "../modules/add"; + +let c=add(4,5); +MSConsole.WriteLine("-------c={0}",c); \ No newline at end of file diff --git a/tsProj/tsSrc/modules/add.ts b/tsProj/tsSrc/modules/add.ts new file mode 100644 index 0000000000..80d4ac4a7e --- /dev/null +++ b/tsProj/tsSrc/modules/add.ts @@ -0,0 +1,3 @@ +export function add(a:int,b:int){ + return a+b; +} \ No newline at end of file diff --git a/tsProj/tsconfig.json b/tsProj/tsconfig.json index b584a75568..caae81cec9 100644 --- a/tsProj/tsconfig.json +++ b/tsProj/tsconfig.json @@ -2,8 +2,8 @@ "compilerOptions": { /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */