annotate Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.ts @ 496:8b6ceae45ba0 bgo-commands-codegen

Finished (untested) C++, html, typescript, tsc & browserify production.
author bgo-osimis
date Sat, 23 Feb 2019 15:04:29 +0100
parents
children 6d62fc8a6988
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
1 export var SendMessageToStoneApplication: Function = null;
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
2
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
3 function SelectTool(toolName: string) {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
4 var command = {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
5 command: "selectTool:" + toolName,
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
6 commandType: "generic-no-arg-command",
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
7 args: {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
8 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
9 };
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
10 SendMessageToStoneApplication(JSON.stringify(command));
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
11 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
12
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
13 (<any> window).StoneFrameworkModule = {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
14 preRun: [
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
15 function() {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
16 console.log('Loading the Stone Framework using WebAssembly');
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
17 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
18 ],
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
19 postRun: [
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
20 function() {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
21 // This function is called by ".js" wrapper once the ".wasm"
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
22 // WebAssembly module has been loaded and compiled by the
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
23 // browser
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
24 console.log('WebAssembly is ready');
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
25 SendMessageToStoneApplication = (<any> window).StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
26 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
27 ],
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
28 print: function(text : string) {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
29 console.log(text);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
30 },
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
31 printErr: function(text : string) {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
32 console.error(text);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
33 },
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
34 totalDependencies: 0
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
35 };
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
36
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
37 // install "SelectTool" handlers
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
38 document.querySelectorAll("[tool-selector]").forEach((e) => {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
39 (e as HTMLButtonElement).addEventListener("click", () => {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
40 SelectTool(e.attributes["tool-selector"].value);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
41 });
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
42 });
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
43
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
44 // this method is called "from the C++ code" when the StoneApplication is updated.
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
45 // it can be used to update the UI of the application
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
46 function UpdateWebApplication(statusUpdateMessageString: string) {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
47 console.log("updating web application: ", statusUpdateMessageString);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
48 let statusUpdateMessage = JSON.parse(statusUpdateMessageString);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
49
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
50 if ("event" in statusUpdateMessage)
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
51 {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
52 let eventName = statusUpdateMessage["event"];
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
53 if (eventName == "appStatusUpdated")
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
54 {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
55 //ui.onAppStatusUpdated(statusUpdateMessage["data"]);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
56 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
57 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
58 }