Notação do fórum do Scratch (scratchblocks): exportar e importar scripts
- Nova library tinyblocks-scratchblocks: converte uma aba (TbBpTab da
blueprint) para o texto do fórum e de volta. Blocos com equivalente no
Scratch saem em inglês ("when flag clicked", "repeat (10)", "set [x v]
to (0)", "if <> then ... else ... end", listas, operadores, sensores);
os do TinyBlocks usam o rótulo em português com "::categoria". A
importação aceita as duas formas, comentários "//", "::categoria",
escapes e as tags [scratchblocks]. Forma, tipo dos campos e categoria
vêm por callbacks (a library não conhece o editor).
- Editor: "Exportar scratchblocks" no menu Exportar (aba atual -> .txt);
"Abrir" aceita .txt/.sb e cria uma aba com os scripts.
- test-scratchblocks + cenário de ida e volta no harness.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
649ae14fb3
commit
d842890b0b
11 files changed
+1255
-38
No files matched your search
+40
-3
@@ -460,7 +460,7 @@ int main(void) {
|
||||
mkdir(fdir, 0755);
|
||||
snprintf(fp, sizeof(fp), "%s/sub", fdir);
|
||||
mkdir(fp, 0755);
|
||||
snprintf(fp, sizeof(fp), "%s/nota.txt", fdir);
|
||||
snprintf(fp, sizeof(fp), "%s/nota.md", fdir);
|
||||
FILE* tf = fopen(fp, "wb");
|
||||
if (tf) { fputs("oi", tf); fclose(tf); }
|
||||
snprintf(fp, sizeof(fp), "%s/proj.json", fdir);
|
||||
@@ -477,7 +477,7 @@ int main(void) {
|
||||
type(fdir);
|
||||
key(TB_KEY_RETURN, 0, 0);
|
||||
CHECK(find("proj.json", R_ANY, 0, &x, &y) && find("sub", R_ANY, 0, &x, &y)
|
||||
&& !find("nota.txt", R_ANY, 0, &x, &y),
|
||||
&& !find("nota.md", R_ANY, 0, &x, &y),
|
||||
"explorador lista pastas + .json e filtra o resto");
|
||||
if (need("proj.json", R_ANY, 0, &x, &y)) { click(x, y); click(x, y); }
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
@@ -501,7 +501,7 @@ int main(void) {
|
||||
CHECK(!find("Abrir projeto", R_ANY, 0, &x, &y), "Esc fecha o explorador");
|
||||
|
||||
remove(fp);
|
||||
snprintf(fp, sizeof(fp), "%s/nota.txt", fdir); remove(fp);
|
||||
snprintf(fp, sizeof(fp), "%s/nota.md", fdir); remove(fp);
|
||||
snprintf(fp, sizeof(fp), "%s/sub", fdir); rmdir(fp);
|
||||
rmdir(fdir);
|
||||
}
|
||||
@@ -950,6 +950,43 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
/* 24. Notação do fórum (scratchblocks): Abrir .txt cria aba; Exportar gera o texto */
|
||||
{
|
||||
const char* src = "/tmp/tb_harness_sb.txt";
|
||||
const char* dst = "/tmp/tb_harness_sb_out.txt";
|
||||
const char* script =
|
||||
"when flag clicked\n"
|
||||
"set [x v] to (0)\n"
|
||||
"repeat (3)\n"
|
||||
" change [x v] by (1)\n"
|
||||
"end\n"
|
||||
"say (x)\n";
|
||||
FILE* f = fopen(src, "wb");
|
||||
if (f) { fputs(script, f); fclose(f); }
|
||||
remove(dst);
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y);
|
||||
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
||||
type(src);
|
||||
key(TB_KEY_RETURN, 0, 0);
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
CHECK(any_has("Importado: 1 script"), "Abrir um .txt em scratchblocks cria aba com o script");
|
||||
CHECK(any_has("de tb_harness_sb.txt"), "aba nova recebe o nome do arquivo");
|
||||
CHECK(find("repita", R_WS, 0, &x, &y) || ws_has("repita"), "blocos importados aparecem (repita)");
|
||||
if (need("Exportar", R_FLY, 0, &x, &y)) click(x, y);
|
||||
if (need("Exportar scratchblocks", R_ANY, 0, &x, &y)) click(x, y);
|
||||
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
||||
type(dst);
|
||||
key(TB_KEY_RETURN, 0, 0);
|
||||
frame(0, 0, 0, 0, 0, 0, NULL);
|
||||
char got[512] = "";
|
||||
f = fopen(dst, "rb");
|
||||
if (f) { size_t n = fread(got, 1, sizeof(got) - 1, f); got[n] = 0; fclose(f); }
|
||||
CHECK(!strcmp(got, script), "Exportar scratchblocks gera o mesmo texto");
|
||||
if (strcmp(got, script)) printf("---- exportado:\n%s----\n", got);
|
||||
remove(src); remove(dst);
|
||||
}
|
||||
|
||||
printf("comandos de desenho no último frame: %u\n", ncmd);
|
||||
tinyblocks_deinit(&rt);
|
||||
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
||||
|
||||
Reference in new issue
Block a user