Nova atividade em app/src/atividades/programacao/padroes/, seguindo o padrão arquitetural das demais (BaseGameScene + Blockly + interpretador): - Cena Phaser (PadroesScene), blocos customizados, API do interpretador, validador e UI com painéis ENTRADA/SAÍDA. - Fase 1 (teste): loop "enquanto" que verifica se a ENTRADA contém apenas letras de A-Z (caso "ABC123" -> "INVÁLIDO"). - Registro em gameRegistry.js, rota em App.jsx e ajuste do teste do registry (EXPECTED_IDS -> 10 jogos).
69 lines
2.0 KiB
JavaScript
69 lines
2.0 KiB
JavaScript
/**
|
|
* @fileoverview Ponte entre o js-interpreter (sandbox) e a cena Phaser do
|
|
* jogo Padrões. Expõe as funções que o código gerado pelos blocos chama.
|
|
*
|
|
* @module games.padroes.hooks.interpreterSetup
|
|
*/
|
|
|
|
import { ApiHelpers } from "../../../../interpreters/ApiHelpers.js";
|
|
|
|
/**
|
|
* Configura a API disponível ao interpretador para o jogo Padrões.
|
|
* @param {Object} scene - Instância da cena Phaser (PadroesScene)
|
|
* @param {Object} [config] - Opções (ex.: `animationSpeed`)
|
|
* @returns {Function} Função de init com assinatura (interpreter, globalScope)
|
|
*/
|
|
export const setupPadroesAPI = (scene, config = {}) => {
|
|
const animationDelay = config.animationSpeed ?? 150;
|
|
|
|
return (interpreter, globalScope) => {
|
|
// Ações (assíncronas — pausam o interpretador para feedback visual)
|
|
ApiHelpers.registerFunction(
|
|
interpreter,
|
|
globalScope,
|
|
"definirSaida",
|
|
ApiHelpers.createActionWrapper(scene, "definirSaida", animationDelay),
|
|
true,
|
|
);
|
|
ApiHelpers.registerFunction(
|
|
interpreter,
|
|
globalScope,
|
|
"definirContador",
|
|
ApiHelpers.createActionWrapper(scene, "definirContador", animationDelay),
|
|
true,
|
|
);
|
|
|
|
// Condições (síncronas — retornam valor imediatamente)
|
|
ApiHelpers.registerFunction(
|
|
interpreter,
|
|
globalScope,
|
|
"obterEntrada",
|
|
ApiHelpers.createConditionWrapper(scene, "obterEntrada"),
|
|
false,
|
|
);
|
|
ApiHelpers.registerFunction(
|
|
interpreter,
|
|
globalScope,
|
|
"obterSaida",
|
|
ApiHelpers.createConditionWrapper(scene, "obterSaida"),
|
|
false,
|
|
);
|
|
ApiHelpers.registerFunction(
|
|
interpreter,
|
|
globalScope,
|
|
"obterContador",
|
|
ApiHelpers.createConditionWrapper(scene, "obterContador"),
|
|
false,
|
|
);
|
|
|
|
// Highlight visual dos blocos durante a execução
|
|
ApiHelpers.registerFunction(
|
|
interpreter,
|
|
globalScope,
|
|
"highlightBlock",
|
|
ApiHelpers.createHighlightWrapper(scene),
|
|
false,
|
|
);
|
|
};
|
|
};
|