Пример #1
0
        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);
        }
Пример #2
0
    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;
    }
Пример #3
0
 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);
 }
Пример #4
0
    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));
    }
Пример #5
0
 public IPhaserSpriteInterop Crop(double x, double y, double width, double height)
 {
     _jsRuntime.InvokeVoid("setSpriteCrop", _sceneName, _spriteName, x, y, width, height);
     return(this);
 }
Пример #6
0
 public void Dispose() =>
 _jsRuntime.InvokeVoid(
     PhaserConstants.Functions.DestroyText,
     Key);
Пример #7
0
 public void CreateEditor(string elementId, string initialCode, string language, bool readOnly = false) => Runtime.InvokeVoid("monacoInterop.createEditor", elementId, initialCode, language, readOnly);
Пример #8
0
        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);
        }
Пример #10
0
    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");
 }
Пример #12
0
 public void Alert(string message) =>
 _jsInProcessRuntime.InvokeVoid("alert", message);
Пример #13
0
 public void ScrollTo(int x, int y) => jsRuntime.InvokeVoid("window.scrollTo", x, y);
Пример #14
0
 private void ResetDomMaps()
 {
     jsRuntime.InvokeVoid("xquery.resetdommaps");
 }
Пример #15
0
 private void InitializeEditor(string method, bool readOnly)
 {
     _js.InvokeVoid(method, _id, readOnly);
 }
Пример #16
0
 public void Log(string s)
 {
     JsRuntime.InvokeVoid("Proteus.log", s);
 }
Пример #17
0
 /// <summary>
 ///
 /// </summary>
 public void Dispose()
 {
     _jsRuntime.InvokeVoid("Sample.BlazorWasm.TextEditor.JSObjectReference.dispose", Id);
 }
Пример #18
0
 public void Info(string title, string message) => _jsInProcessRuntime.InvokeVoid("toastr.info", message, title);
Пример #19
0
 public IPhaserTextInterop Value(string text)
 {
     _jsRuntime.InvokeVoid("setTextValue", _sceneName, _textName, text);
     return(this);
 }
Пример #20
0
 public void RegisterScene(Scene scene)
 {
     _jSRuntime.InvokeVoid("registerScene", scene.GetName(), DotNetObjectReference.Create(scene));
 }
Пример #21
0
 public void DrawLines(IEnumerable <Line> lines, int lineWidth, int color) =>
 _jsInProcessRuntime.InvokeVoid(
     PhaserConstants.Functions.DrawLines,
     lines,
     lineWidth,
     color);
Пример #22
0
 public void Dispose() =>
 _jsRuntime.InvokeVoid(PhaserConstants.Functions.Resume);
 public void Init()
 {
     _jsRuntime.InvokeVoid("BlazorPWA.init", _dotNetObjectReference);
 }
Пример #24
0
 protected void InvokeCustomVoid(string jsFunction, params object[] args)
 {
     jsRuntime.InvokeVoid($"window.UIComponents.{jsFunction}", args);
 }
Пример #25
0
 public static void WriteSessionStorage(this IJSInProcessRuntime js, string name, string value)
 => js.InvokeVoid("Shipwreck.ViewModelUtils.writeSessionStorage", name, value);