Adiciona tinyblocks-blueprint e libraries json/xml/csv; abrir/salvar/exportar projeto
- tinyblocks-blueprint: dona do estado de edicao (abas, pool de blocos, vinculos parent/prel/next/sub/args, blocos compostos e variaveis) e da serializacao. JSON nativo (to/from) usando a AST JSON do core e export JSON/XML/CSV. Testado com round-trip (test-blueprint). - tinyblocks-json: lexer + parser + emissor JSON independentes. - tinyblocks-xml: lexer + parser de XML -> AST JSON do core + emissor. - tinyblocks-csv: divisor de linhas/campos + parser/emissor sobre a AST JSON. - Editor: botoes Abrir / Salvar / Exportar JSON XML CSV no menu; converte Ed <-> TbBlueprint; barra de caminho com modo; .json pode ser arrastado. - Variaveis: tb_variables_clear e tb_variables_set_text. - Harness: teste de salvar/abrir projeto; tests/blueprint_test.c.
This commit is contained in:
1 parent
dc23b92d15
commit
1199d2d7c7
39 files changed
+3462
-24
No files matched your search
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* TinyBlocks - tinyblocks-blueprint / include/blueprint.h
|
||||
*
|
||||
* TbBlueprint e o modelo de um "projeto" do editor (estilo Scratch):
|
||||
* - abas (TbBpTab) com um pool estavel de blocos (TbBpBlock);
|
||||
* - vinculos entre blocos por indice: parent/prel, next, sub[2], args[];
|
||||
* - definicoes de blocos compostos (TbBpUserBlock);
|
||||
* - variaveis (TbBpVar).
|
||||
*
|
||||
* A library e dona do estado de edicao e da logica de serializacao:
|
||||
* converter para/de JSON (formato nativo) e exportar JSON/XML/CSV.
|
||||
*
|
||||
* A AST usada na serializacao e a do core (TinyBlocks_JsonValue).
|
||||
*/
|
||||
#ifndef TB_BLUEPRINT_H
|
||||
#define TB_BLUEPRINT_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <tinyblocks/tb_json_block.h>
|
||||
|
||||
#define TB_BP_MAX_WS 256
|
||||
#define TB_BP_MAX_INPUTS 16
|
||||
#define TB_BP_MAX_TABS 8
|
||||
#define TB_BP_MAX_UBLOCKS 16
|
||||
#define TB_BP_MAX_UPARTS 16
|
||||
#define TB_BP_MAX_USLOTS 8
|
||||
#define TB_BP_MAX_VARS 64
|
||||
#define TB_BP_LIT_CAP 512
|
||||
|
||||
/* Formatos de serializacao */
|
||||
enum { TB_BP_FMT_JSON, TB_BP_FMT_XML, TB_BP_FMT_CSV };
|
||||
|
||||
/* Relacao de um bloco com o pai (identica ao editor) */
|
||||
#define TB_BP_REL_NONE (-1)
|
||||
#define TB_BP_REL_NEXT 0
|
||||
#define TB_BP_REL_SUB0 1
|
||||
#define TB_BP_REL_ARG0 3
|
||||
|
||||
/* -- Blocos e abas --- */
|
||||
typedef struct {
|
||||
bool used;
|
||||
char type[64]; /* "Events.WhenRun", "User.X", ... */
|
||||
float x, y;
|
||||
int parent, prel;
|
||||
int next;
|
||||
int sub[2];
|
||||
int args[TB_BP_MAX_INPUTS];
|
||||
char in_text[TB_BP_MAX_INPUTS][64];
|
||||
char lit[TB_BP_LIT_CAP];
|
||||
} TbBpBlock;
|
||||
|
||||
typedef struct {
|
||||
TbBpBlock blocks[TB_BP_MAX_WS];
|
||||
int top[TB_BP_MAX_WS];
|
||||
int top_n;
|
||||
float ws_sx, ws_sy;
|
||||
char name[48];
|
||||
bool composite;
|
||||
int comp_id; /* indice em user_blocks, ou -1 */
|
||||
int color_idx;
|
||||
} TbBpTab;
|
||||
|
||||
/* -- Blocos compostos (protótipo) --- */
|
||||
typedef enum { TB_BP_PARAM_NUM, TB_BP_PARAM_BOOL, TB_BP_PARAM_LABEL } TbBpParamKind;
|
||||
typedef struct { TbBpParamKind kind; char name[32]; } TbBpParam;
|
||||
|
||||
typedef struct {
|
||||
char name[48];
|
||||
int input_count, output_count;
|
||||
char input_names[TB_BP_MAX_USLOTS][32];
|
||||
char output_names[TB_BP_MAX_USLOTS][32];
|
||||
TbBpParam parts[TB_BP_MAX_UPARTS];
|
||||
int part_n;
|
||||
int color_idx;
|
||||
int tab_idx;
|
||||
} TbBpUserBlock;
|
||||
|
||||
/* -- Variaveis --- */
|
||||
typedef enum { TB_BP_VAL_INT, TB_BP_VAL_REAL, TB_BP_VAL_TEXT } TbBpValueKind;
|
||||
typedef struct {
|
||||
char name[32];
|
||||
TbBpValueKind kind;
|
||||
double num;
|
||||
char text[128];
|
||||
} TbBpVar;
|
||||
|
||||
/* -- Documento --- */
|
||||
typedef struct {
|
||||
TbBpTab tabs[TB_BP_MAX_TABS];
|
||||
int tab_count;
|
||||
TbBpUserBlock user_blocks[TB_BP_MAX_UBLOCKS];
|
||||
int user_block_n;
|
||||
TbBpVar vars[TB_BP_MAX_VARS];
|
||||
int var_n;
|
||||
int cur_tab;
|
||||
} TbBlueprint;
|
||||
|
||||
/* -- Ciclo de vida / edicao --- */
|
||||
TbBlueprint* tb_blueprint_new(void);
|
||||
void tb_blueprint_free(TbBlueprint* bp);
|
||||
void tb_blueprint_clear(TbBlueprint* bp);
|
||||
|
||||
/* Cria uma aba; devolve o indice ou -1. */
|
||||
int tb_blueprint_add_tab(TbBlueprint* bp, const char* name, bool composite);
|
||||
TbBpTab* tb_blueprint_tab(TbBlueprint* bp, int i);
|
||||
|
||||
/* Aloca um bloco no pool da aba; devolve o indice ou -1. */
|
||||
int tb_blueprint_alloc_block(TbBpTab* t);
|
||||
/* Liga child ao pai na relacao rel (child < 0 desliga). */
|
||||
void tb_blueprint_link(TbBpTab* t, int parent, int rel, int child);
|
||||
void tb_blueprint_top_add(TbBpTab* t, int bi);
|
||||
|
||||
/* Variaveis */
|
||||
void tb_blueprint_var_set_text(TbBlueprint* bp, const char* name, const char* value);
|
||||
|
||||
/* -- Serializacao --- */
|
||||
/* Formato nativo (JSON). to_json devolve ref nova; from_json nao consome 'root'. */
|
||||
TinyBlocks_JsonValue* tb_blueprint_to_json(const TbBlueprint* bp);
|
||||
TbBlueprint* tb_blueprint_from_json(const TinyBlocks_JsonValue* root);
|
||||
|
||||
/* Serializa para texto no formato pedido (malloc; libere com free). */
|
||||
char* tb_blueprint_serialize(const TbBlueprint* bp, int fmt, bool pretty);
|
||||
/* Le do texto. Suporta o formato nativo (JSON). */
|
||||
TbBlueprint* tb_blueprint_parse(const char* text, int fmt, char* err, size_t errcap);
|
||||
|
||||
/* Arquivos */
|
||||
bool tb_blueprint_save_file(const TbBlueprint* bp, const char* path, int fmt, bool pretty);
|
||||
TbBlueprint* tb_blueprint_load_file(const char* path, char* err, size_t errcap);
|
||||
const char* tb_blueprint_format_name(int fmt); /* "json"/"xml"/"csv" */
|
||||
|
||||
#endif /* TB_BLUEPRINT_H */
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* TinyBlocks - tb_blueprint.h
|
||||
* Library tinyblocks-blueprint: modelo de edicao (blueprint) e serializacao.
|
||||
*/
|
||||
#ifndef TINYBLOCKS_BLUEPRINT_H
|
||||
#define TINYBLOCKS_BLUEPRINT_H
|
||||
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include "blueprint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
TB_API const TinyBlocks_LibraryDescriptor* tb_blueprint_get_library(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TINYBLOCKS_BLUEPRINT_H */
|
||||
Reference in new issue
Block a user