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:
1 parent
e165e07e02
commit
85bd6f7cf4
9 files changed
+70
-5
No files matched your search
@@ -45,10 +45,11 @@ static int64_t in_int(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
|
||||
static void eval_open(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = tb_block_input_text(self, rt, 0);
|
||||
char rpath[1100];
|
||||
int slot = fs_slot();
|
||||
int64_t handle = 0;
|
||||
if (slot >= 0 && path[0]) {
|
||||
FILE* f = fopen(path, "rb");
|
||||
FILE* f = fopen(tb_path_resolve(path, rpath, sizeof(rpath)), "rb");
|
||||
if (f) { s_files[slot] = f; handle = slot + 1; }
|
||||
}
|
||||
tb_block_set_output(self, 0, tb_value_integer(handle));
|
||||
@@ -80,9 +81,10 @@ static void eval_read(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
|
||||
static void eval_readtext(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = tb_block_input_text(self, rt, 0);
|
||||
char rpath[1100];
|
||||
char* buf = NULL;
|
||||
if (path[0]) {
|
||||
FILE* f = fopen(path, "rb");
|
||||
FILE* f = fopen(tb_path_resolve(path, rpath, sizeof(rpath)), "rb");
|
||||
if (f) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
long end = ftell(f);
|
||||
@@ -109,8 +111,9 @@ static void eval_write(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
static void eval_append(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = tb_block_input_text(self, rt, 0);
|
||||
const char* text = tb_block_input_text(self, rt, 1);
|
||||
char rpath[1100];
|
||||
if (path[0]) {
|
||||
FILE* f = fopen(path, "ab");
|
||||
FILE* f = fopen(tb_path_resolve(path, rpath, sizeof(rpath)), "ab");
|
||||
if (f) { fwrite(text, 1, strlen(text), f); fclose(f); }
|
||||
}
|
||||
self->dirty = false;
|
||||
|
||||
Reference in new issue
Block a user