Editor/core: resolve caminhos relativos pela pasta do projeto

Blocos que abrem arquivo (carregue o PNG, Image.Load, FS.*) passam a
resolver caminhos relativos contra o diretorio-base do projeto, definido
pelo editor ao abrir um .sb. Assim exemplos acham atlas.png etc. mesmo
quando o editor roda de outro cwd (ex.: AppImage aberto pelo menu), sem
mudar o cwd global (que quebrava "Ver codigo-fonte" e o harness).

- tb_path_set_base / tb_path_resolve, na API publica (src/tinyblocks.c)
- editor: project_set_dir no project_load (sem chdir)
- tb_png, tb_fs e tb_imglib usam o resolvedor
- MAX_USER_BLOCKS 16 -> 8192 (documentado em docs/editor.md)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5 committed 2026-10-29 02:03:18 -03:00
1 parent e165e07e02
commit 85bd6f7cf4
9 files changed
+70 -5

No files matched your search

@@ -3639,7 +3639,21 @@ static bool has_ext(const char* path, const char* ext) {
return n > e && !strcasecmp(path + n - e, ext);
}
/* Define o diretorio-base do projeto aberto, para que caminhos relativos
(imagens, FS.ReadText...) achem os arquivos do exemplo mesmo quando o
editor roda de outro cwd (ex.: AppImage aberto pelo menu). Nao muda o cwd. */
static void project_set_dir(const char* path) {
char buf[1024];
if (!path || !path[0] || strlen(path) >= sizeof(buf)) return;
strcpy(buf, path);
char* slash = strrchr(buf, '/');
if (!slash) return;
*slash = '\0';
if (buf[0]) tb_path_set_base(buf);
}
bool project_load(Ed* ed, const char* path) {
project_set_dir(path);
if (has_ext(path, ".txt") || has_ext(path, ".sb") || has_ext(path, ".scratchblocks"))
return sb_import_file(ed, path); /* notacao de texto do forum do Scratch */
char err[160] = "";