public void SetItem(string key, object data) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException(nameof(key)); } if (_jSInProcessRuntime == null) { throw new InvalidOperationException("IJSInProcessRuntime not available"); } var e = RaiseOnChangingSync(key, data); if (e.Cancel) { return; } if (data is string) { _jSInProcessRuntime.InvokeVoid("localStorage.setItem", key, data); } else { _jSInProcessRuntime.InvokeVoid("localStorage.setItem", key, JsonSerializer.Serialize(data, _jsonOptions)); } RaiseOnChanged(key, e.OldValue, data); }
public async Task MoveAsync( Point target, double duration, Action onUpdate, CancellationToken cancellationToken) { // MoveAsync uses a Phaser tween to change the x/y position of the // sprite. Use a TaskCompletionSource to wait until the tween is // done. var tcs = new TaskCompletionSource(); // When the tween has updated the sprite, check if cancellation // is requested, and inform the caller of the new position. var onUpdateHandler = new PhaserCallback <Point, bool>( pointerPosition => { Position = pointerPosition; onUpdate(); return(!cancellationToken.IsCancellationRequested); }); // When the tween has completed, set the result on the // TaskCompletionSource to allow this method to run to completion. var onCompleteHandler = new PhaserCallback <Point>( pointerPosition => { Position = pointerPosition; tcs.SetResult(); }); // Create DotNetObjectReference instances for the callbacks. These // need to be disposed once we're done with them. using var onUpdateRef = DotNetObjectReference.Create(onUpdateHandler); using var onCompleteRef = DotNetObjectReference.Create(onCompleteHandler); // Start the tween. _jsRuntime.InvokeVoid( PhaserConstants.Functions.MoveSprite, Key, target.X, target.Y, duration, onUpdateRef, onCompleteRef); // Wait for tween to complete. await tcs.Task; }
private void Init(IJSInProcessRuntime runtime, ElementReference?element, PoseNetOptions options, DetectionType?type) { Runtime = runtime; DotNetObjectRef = DotNetObjectReference.Create(this); Hash = PoseNetHash++; runtime.InvokeVoid("poseNetML5", Hash.ToString(), DotNetObjectRef, element, options, type); }
public static IText Create( string text, Point position, TextOptions options, IJSInProcessRuntime jsRuntime) { var textKey = Guid.NewGuid().ToString(); jsRuntime.InvokeVoid( PhaserConstants.Functions.AddText, textKey, position, text, options); return(new PhaserText( textKey, position, jsRuntime)); }
public IPhaserSpriteInterop Crop(double x, double y, double width, double height) { _jsRuntime.InvokeVoid("setSpriteCrop", _sceneName, _spriteName, x, y, width, height); return(this); }
public void Dispose() => _jsRuntime.InvokeVoid( PhaserConstants.Functions.DestroyText, Key);
public void CreateEditor(string elementId, string initialCode, string language, bool readOnly = false) => Runtime.InvokeVoid("monacoInterop.createEditor", elementId, initialCode, language, readOnly);
private void Init(IEnumerable <Row> rows) { var tableModel = BuildTableDataModel(rows, _rowDefinition); _js.InvokeVoid("tabulator.init10", _id, tableModel, ErrorsAndWarningsColumnInfo); }
public IPhaserSceneInterop AddSprite(string name, string imageName, double x, double y, Action <IPhaserSpriteInterop> options) { _jsRuntime.InvokeVoid("addSprite", _scene.GetName(), name, imageName, x, y, 1); if (options != null) { options(new PhaserSpriteInterop(_jsRuntime, _scene.GetName(), name)); } return(this); }
public async Task <IGraphics> CreateAsync( GameManifest manifest, int width, int height, Action <Point> onDraw, string containerElementId) { TaskCompletionSource <IGraphics> tcs = new(); List <IDisposable> disposables = new(); // When the Phaser scene preloads, load the sprite atlasses from the // game manifest. var onPreloadHandler = new PhaserCallback( () => { foreach (var atlas in manifest.Spec.Atlasses) { _jsInProcessRuntime.InvokeVoid( PhaserConstants.Functions.LoadAtlas, atlas.Key, manifest.BasePath + atlas.Value.TextureUrl, manifest.BasePath + atlas.Value.AtlasUrl); } }); // When the Phaser scene is created, complete the task by setting // a new PhaserGraphics as the task result. var onCreateHandler = new PhaserCallback( () => { var graphics = new PhaserGraphics( width, height, disposables, _jsInProcessRuntime); tcs.SetResult(graphics); }); var onUpdateHandler = new PhaserCallback <Point>(onDraw); // Create DotNetObjectReference instances for the callbacks. These // need to be disposed once we're done with them. using var onPreloadRef = DotNetObjectReference.Create(onPreloadHandler); using var onCreateRef = DotNetObjectReference.Create(onCreateHandler); // We cannot dispose the onUpdate callback yet, it will be used until // the PhaserGraphics object is disposed. var onUpdateRef = DotNetObjectReference.Create(onUpdateHandler); disposables.Add(onUpdateRef); _jsInProcessRuntime.InvokeVoid( PhaserConstants.Functions.StartPhaser, containerElementId, width, height, onPreloadRef, onCreateRef, onUpdateRef); return(await tcs.Task); }
public void Clear() { CheckForInProcessRuntime(); _jSInProcessRuntime.InvokeVoid("localStorage.clear"); }
public void Alert(string message) => _jsInProcessRuntime.InvokeVoid("alert", message);
public void ScrollTo(int x, int y) => jsRuntime.InvokeVoid("window.scrollTo", x, y);
private void ResetDomMaps() { jsRuntime.InvokeVoid("xquery.resetdommaps"); }
private void InitializeEditor(string method, bool readOnly) { _js.InvokeVoid(method, _id, readOnly); }
public void Log(string s) { JsRuntime.InvokeVoid("Proteus.log", s); }
/// <summary> /// /// </summary> public void Dispose() { _jsRuntime.InvokeVoid("Sample.BlazorWasm.TextEditor.JSObjectReference.dispose", Id); }
public void Info(string title, string message) => _jsInProcessRuntime.InvokeVoid("toastr.info", message, title);
public IPhaserTextInterop Value(string text) { _jsRuntime.InvokeVoid("setTextValue", _sceneName, _textName, text); return(this); }
public void RegisterScene(Scene scene) { _jSRuntime.InvokeVoid("registerScene", scene.GetName(), DotNetObjectReference.Create(scene)); }
public void DrawLines(IEnumerable <Line> lines, int lineWidth, int color) => _jsInProcessRuntime.InvokeVoid( PhaserConstants.Functions.DrawLines, lines, lineWidth, color);
public void Dispose() => _jsRuntime.InvokeVoid(PhaserConstants.Functions.Resume);
public void Init() { _jsRuntime.InvokeVoid("BlazorPWA.init", _dotNetObjectReference); }
protected void InvokeCustomVoid(string jsFunction, params object[] args) { jsRuntime.InvokeVoid($"window.UIComponents.{jsFunction}", args); }
public static void WriteSessionStorage(this IJSInProcessRuntime js, string name, string value) => js.InvokeVoid("Shipwreck.ViewModelUtils.writeSessionStorage", name, value);