private static void AppWorker_OnMessage(Worker.DataEvent dataEvent) { string msg = (string)dataEvent.Data; if (msg.Length < 5) { progressBar.Value = int.Parse(msg); } else { Mesh current = display.Mesh; Mesh newMesh = new Mesh(0, 0, current.MeshType); newMesh.LoadFromText(msg.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)); display.Mesh = newMesh; progressBar.Remove(); progressBar = null; generateButton.Disabled = false; start = DateTime.UtcNow; } }
private static void OnClick(MouseEvent <HTMLButtonElement> mouseEvent) { MeshType type; if (typePicker.SelectedIndex < 0) { type = MeshType.Square; } else { type = MeshTypeFromString(typePicker.Value); } int width; int height; if (!ParseSize(sizeInput.Value, type, out width, out height)) { return; } Mesh mesh = MakeMesh(width, height, type, difficultyPicker.SelectedIndex); display.Mesh = mesh; worker = new Worker(Extensions.Window().URL.createObjectURL(new Blob(new BlobDataObject[] { @" self.onmessage = function(e) { if (e.data.href) { try { importScripts(e.data.href); } catch (error) { console.log(e.data.href); console.log(error); } } else { TwistNTurnBridge.WorkerSpawn.WorkerSpawn_OnMessage(e); } }" }, new BlobPropertyBag() { Type = "text/javascript" }))); progressBar = Document.CreateElement <HTMLProgressElement>("progress"); progressBar.Max = mesh.Intersections.Count; progressBar.Style.Position = Position.Absolute; progressBar.Style.Margin = "auto"; progressBar.Style.Top = "0"; progressBar.Style.Bottom = "0"; progressBar.Style.Left = "0"; progressBar.Style.Right = "0"; progressBar.Style.ZIndex = "100"; progressBar.Style.BackgroundColor = "white"; displayHost.AppendChild(progressBar); generateButton.Disabled = true; worker.OnMessage += AppWorker_OnMessage; string to_load = Window.Location.Href.Substring(0, Window.Location.Href.LastIndexOf('/') + 1) + "bridge.min.js"; worker.PostMessage(new InitialReuqest() { href = to_load }); to_load = Window.Location.Href.Substring(0, Window.Location.Href.LastIndexOf('/') + 1) + "bridge.console.min.js"; worker.PostMessage(new InitialReuqest() { href = to_load }); to_load = Window.Location.Href.Substring(0, Window.Location.Href.LastIndexOf('/') + 1) + "bridge.meta.min.js"; worker.PostMessage(new InitialReuqest() { href = to_load }); to_load = Window.Location.Href.Substring(0, Window.Location.Href.LastIndexOf('/') + 1) + "newtonsoft.json.min.js"; worker.PostMessage(new InitialReuqest() { href = to_load }); to_load = Window.Location.Href.Substring(0, Window.Location.Href.LastIndexOf('/') + 1) + "TwistNTurnBridge.min.js"; worker.PostMessage(new InitialReuqest() { href = to_load }); to_load = Window.Location.Href.Substring(0, Window.Location.Href.LastIndexOf('/') + 1) + "TwistNTurnBridge.meta.min.js"; worker.PostMessage(new InitialReuqest() { href = to_load }); worker.PostMessage(JsonConvert.SerializeObject(new GenerateRequest() { Width = width, Height = height, Type = type, Difficulty = difficultyPicker.SelectedIndex })); }