diff --git a/js/data/update_var_val_boolean.ts b/js/data/update_var_val_boolean.ts new file mode 100644 index 00000000..c6850f21 --- /dev/null +++ b/js/data/update_var_val_boolean.ts @@ -0,0 +1,5 @@ +import { update_var_val } from "../shared.ts"; + +export function update_var_val_boolean(val: boolean, id: string) { + update_var_val(id, val); +} diff --git a/js/data/update_var_val_float.ts b/js/data/update_var_val_float.ts new file mode 100644 index 00000000..1874843e --- /dev/null +++ b/js/data/update_var_val_float.ts @@ -0,0 +1,5 @@ +import { update_var_val } from "../shared.ts"; + +export function update_var_val_float(val: number, id: string) { + update_var_val(id, val); +} diff --git a/js/data/update_var_val_int.ts b/js/data/update_var_val_int.ts new file mode 100644 index 00000000..f7acc710 --- /dev/null +++ b/js/data/update_var_val_int.ts @@ -0,0 +1,5 @@ +import { update_var_val } from "../shared.ts"; + +export function update_var_val_int(val: number, id: string) { + update_var_val(id, val); +} diff --git a/js/data/update_var_val_string.ts b/js/data/update_var_val_string.ts new file mode 100644 index 00000000..3e367056 --- /dev/null +++ b/js/data/update_var_val_string.ts @@ -0,0 +1,5 @@ +import { update_var_val } from "../shared.ts"; + +export function update_var_val_string(val: string, id: string) { + update_var_val(id, val); +} diff --git a/js/data/update_var_visible.ts b/js/data/update_var_visible.ts new file mode 100644 index 00000000..df84d28a --- /dev/null +++ b/js/data/update_var_visible.ts @@ -0,0 +1,5 @@ +import { update_var_visible as update_var_visibility } from "../shared.ts"; + +export function update_var_visible(id: string, visible: boolean) { + update_var_visibility(id, visible); +} diff --git a/js/looks/switchbackdropto.ts b/js/looks/switchbackdropto.ts new file mode 100644 index 00000000..7783782e --- /dev/null +++ b/js/looks/switchbackdropto.ts @@ -0,0 +1,8 @@ +import { renderer, costumes, target_skins, stageIndex } from "../shared"; + +export function switchbackdropto(costume_num: number) { + console.log("switch backdrop to", costume_num); + console.log(stageIndex(), costumes()); + const costume = costumes()[stageIndex()][costume_num]; + renderer().getSkin(target_skins()[stageIndex()][0]).setSVG(costume.data); +} diff --git a/js/sensing/queue_ask.ts b/js/sensing/queue_ask.ts new file mode 100644 index 00000000..a3644c60 --- /dev/null +++ b/js/sensing/queue_ask.ts @@ -0,0 +1,3 @@ +import { queue_question } from "../shared"; + +export const queue_ask = queue_question; diff --git a/js/shared.ts b/js/shared.ts index bab55bec..014df406 100644 --- a/js/shared.ts +++ b/js/shared.ts @@ -5,18 +5,40 @@ let _renderer: object; let _pen_skin: number; let _target_skins: Array<[number, number]>; let _costumes: Array>; +let _queue_question: (question: string, struct: object) => void = () => {}; +let _stageIndex: number; +let _update_var_val: (id: string, val: any) => void = () => {}; +let _update_var_visible: (id: string, visible: boolean) => void = () => {}; type Costume = { data: string; dataFormat: string; }; +export function unsetup() { + _target_names = null; + _target_bubbles = null; + _renderer = null; + _pen_skin = null; + _target_skins = null; + _costumes = null; + _queue_question = () => {}; + _stageIndex = null; + _update_var_val = () => {}; + _update_var_visible = () => {}; + _setup = false; +} + export function setup( target_names: Array, renderer: object, pen_skin: number, target_skins: Array<[number, number]>, costumes: Array>, + queue_question: (question: string, struct: object) => void, + stageIndex: number, + update_var_val: (id: string, val: any) => void, + update_var_visible: (id: string, visible: boolean) => void, ) { _target_names = target_names; _target_bubbles = _target_names.map((_) => null); @@ -25,6 +47,10 @@ export function setup( _pen_skin = pen_skin; _target_skins = target_skins; _costumes = costumes; + _queue_question = queue_question; + _stageIndex = stageIndex; + _update_var_val = update_var_val; + _update_var_visible = update_var_visible; _setup = true; } @@ -63,13 +89,18 @@ export function costumes(): Array> { return _costumes; } +export function stageIndex(): number { + check_setup(); + return _stageIndex; +} + export function update_bubble( target_index: number, verb: "say" | "think", text: string, ) { check_setup(); - if (!_target_bubbles[target_index]) { + if (!_target_bubbles[target_index] && text !== "") { _target_bubbles[target_index] = _renderer.createSkin( "text", "sprite", @@ -77,6 +108,11 @@ export function update_bubble( text, false, ); + } else if (text == "") { + if (!_target_bubbles[target_index]) return; + _renderer.destroyDrawable(_target_bubbles[target_index][1], "sprite"); + _renderer.destroySkin(_target_bubbles[target_index][0]); + _target_bubbles[target_index] = null; } else { _renderer.updateTextSkin( _target_bubbles[target_index][0], @@ -86,3 +122,18 @@ export function update_bubble( ); } } + +export function queue_question(question: string, struct: object) { + check_setup(); + _queue_question(question, struct); +} + +export function update_var_val(id: string, val: any) { + check_setup(); + _update_var_val(id, val); +} + +export function update_var_visible(id: string, visible: boolean) { + check_setup(); + _update_var_visible(id, visible); +} diff --git a/opcodes.mjs b/opcodes.mjs index fe046a78..34e8f7a0 100644 --- a/opcodes.mjs +++ b/opcodes.mjs @@ -7,6 +7,11 @@ const opcodes = [ .match(/BlockOpcode::[a-zA-Z_0-9]+? (?==>)/g) .map((op) => op.replace("BlockOpcode::", "").trim()), ), + "event_whenflagclicked", + "event_whenbroadcastreceived", + "event_whenthisspriteclicked", + "event_whenstageclicked", + "procedures_definition", ].sort(); await writeFile( "/tmp/hq-build/js/opcodes.js", diff --git a/playground/App.vue b/playground/App.vue index 841fd90a..eb26016e 100644 --- a/playground/App.vue +++ b/playground/App.vue @@ -50,6 +50,7 @@ main { position: sticky; top: 5px; background-color: var(--color-background); + z-index: 999; } diff --git a/playground/components/ProjectPlayer.vue b/playground/components/ProjectPlayer.vue index 677b74cd..0ae953c1 100644 --- a/playground/components/ProjectPlayer.vue +++ b/playground/components/ProjectPlayer.vue @@ -20,7 +20,41 @@ - +
+ +
+ + {{ sprite }}: {{ name }} + + {{ value }} +
+
+
+ {{ queued_questions[0]?.[0] }} +
+
+ + +
+
+

Instructions

@@ -37,15 +71,11 @@