MCPcopy
hub / github.com/jabbany/CommentCoreLibrary / BridgedSandbox

Class BridgedSandbox

src/scripting/host/BridgedSandbox.ts:12–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12export class BridgedSandbox implements ISandbox {
13 private _scripter:IScripter;
14 private _scriptingContext:IScriptingContext;
15 private _stage:StageElement;
16 private _player:IPlayer;
17 private _worker:OOAPIWorker;
18 private _queue:SmartQueue<SandboxEvent>;
19
20 private _isAvailable:boolean = false;
21
22 constructor(scripter:IScripter, stage:StageElement, player:IPlayer) {
23 this._scripter = scripter;
24 this._scriptingContext = KagerouScripting.getContext(stage);
25 this._stage = stage;
26 this._player = player;
27 this._worker = new OOAPIWorker(this._scripter.getWorker());
28 this._queue = new SmartQueue<SandboxEvent>();
29
30 this._bind();
31 }
32
33 get isAvailable():boolean {
34 return this._isAvailable;
35 }
36
37 set isAvailable(b:boolean) {
38 throw new Error('BridgedSandbox.isAvailable is read-only');
39 }
40
41 private _getDimensionsMessage():OOAPIMessage {
42 return {
43 'channel': 'Update:DimensionUpdate',
44 'payload': {
45 'stageWidth':this._stage.offsetWidth,
46 'stageHeight':this._stage.offsetHeight,
47 'screenWidth':window.screen.width,
48 'screenHeight':window.screen.height
49 }
50 };
51 }
52
53 private _bind():void {
54 // Handle all malformed packets by throwing them into the logger
55 this._worker.setMalformedEventHandler(((e) => {
56 if (e.stack) {
57 this._scripter.logger.error(e.stack);
58 } else {
59 this._scripter.logger.error(e);
60 }
61 }).bind(this));
62
63 // Add the default listener to catch all messages that are not caught and
64 // throw them into the logger
65 this._worker.setDefaultChannelListener(((m:OOAPIMessage) => {
66 this._scripter.logger.warn('Got message for non-existant channel "' +
67 m.channel + '".');
68 }).bind(this));
69

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected