paint: add --api and --script args
This commit is contained in:
+58
-7
@@ -13,6 +13,16 @@ bool args_export_mesh = false;
|
||||
char *args_export_mesh_path = "";
|
||||
bool args_export_material = false;
|
||||
char *args_export_material_path = "";
|
||||
bool args_api = false;
|
||||
bool args_script = false;
|
||||
char *args_script_path = "";
|
||||
|
||||
static char *args_path(char *path) {
|
||||
if (data_is_abs(path) || data_is_up(path) || starts_with(path, "./")) {
|
||||
return string_copy(path);
|
||||
}
|
||||
return string("./%s", path);
|
||||
}
|
||||
|
||||
void args_parse() {
|
||||
if (iron_get_arg_count() > 1) {
|
||||
@@ -24,7 +34,7 @@ void args_parse() {
|
||||
char *current_arg = iron_get_arg(i);
|
||||
|
||||
if (path_is_project(current_arg)) {
|
||||
g_project->_->filepath = string_copy(current_arg);
|
||||
g_project->_->filepath = args_path(current_arg);
|
||||
}
|
||||
else if (string_equals(current_arg, "--background")) {
|
||||
args_background = true;
|
||||
@@ -33,7 +43,7 @@ void args_parse() {
|
||||
args_player = true;
|
||||
}
|
||||
else if (path_is_texture(current_arg)) {
|
||||
args_asset_path = string_copy(current_arg);
|
||||
args_asset_path = args_path(current_arg);
|
||||
}
|
||||
else if (string_equals(current_arg, "--export-textures") && (i + 3) <= iron_get_arg_count()) {
|
||||
args_export_textures = true;
|
||||
@@ -42,7 +52,7 @@ void args_parse() {
|
||||
++i;
|
||||
args_export_textures_preset = string_copy(iron_get_arg(i));
|
||||
++i;
|
||||
args_export_textures_path = string_copy(iron_get_arg(i));
|
||||
args_export_textures_path = args_path(iron_get_arg(i));
|
||||
}
|
||||
else if (string_equals(current_arg, "--reload-mesh")) {
|
||||
args_reimport_mesh = true;
|
||||
@@ -50,15 +60,24 @@ void args_parse() {
|
||||
else if (string_equals(current_arg, "--export-mesh") && (i + 1) <= iron_get_arg_count()) {
|
||||
args_export_mesh = true;
|
||||
++i;
|
||||
args_export_mesh_path = string_copy(iron_get_arg(i));
|
||||
args_export_mesh_path = args_path(iron_get_arg(i));
|
||||
}
|
||||
else if (path_is_mesh(current_arg) || iron_is_directory(current_arg)) {
|
||||
args_asset_path = string_copy(current_arg);
|
||||
args_asset_path = args_path(current_arg);
|
||||
}
|
||||
else if (string_equals(current_arg, "--export-material") && (i + 1) <= iron_get_arg_count()) {
|
||||
args_export_material = true;
|
||||
++i;
|
||||
args_export_material_path = string_copy(iron_get_arg(i));
|
||||
args_export_material_path = args_path(iron_get_arg(i));
|
||||
}
|
||||
else if (string_equals(current_arg, "--script") && (i + 1) < iron_get_arg_count()) {
|
||||
args_script = true;
|
||||
++i;
|
||||
args_script_path = args_path(iron_get_arg(i));
|
||||
}
|
||||
else if (string_equals(current_arg, "--api")) {
|
||||
args_api = true;
|
||||
args_background = true;
|
||||
}
|
||||
else if (string_equals(current_arg, "--help")) {
|
||||
printf("Usage: armorpaint [options] [file]\n");
|
||||
@@ -70,6 +89,9 @@ void args_parse() {
|
||||
printf(" --export-mesh <path> Export mesh to path\n");
|
||||
printf(" --export-material <path> Export material to path\n");
|
||||
printf(" --reload-mesh Reimport mesh on startup\n");
|
||||
printf(" --script <path> Run script on the opened project\n");
|
||||
printf(" --api Print the scripting API reference\n");
|
||||
printf(" Contents of the opened project are included\n");
|
||||
printf(" --player Run in player mode\n");
|
||||
printf(" --help Show this help message\n");
|
||||
exit(1);
|
||||
@@ -83,6 +105,29 @@ void args_run_export_queue(void *_) {
|
||||
export_texture_run(args_export_textures_path, false);
|
||||
}
|
||||
|
||||
void args_run_api(void *_) {
|
||||
printf("%s", text_to_text_node_reference());
|
||||
iron_stop();
|
||||
}
|
||||
|
||||
void args_run_script_stop(void *_) {
|
||||
iron_stop();
|
||||
}
|
||||
|
||||
void args_run_script(void *_) {
|
||||
buffer_t *b = iron_load_blob(args_script_path);
|
||||
if (b == NULL) {
|
||||
iron_log(tr("Invalid script path"));
|
||||
}
|
||||
else {
|
||||
minic_eval(sys_buffer_to_string(b));
|
||||
iron_delete_blob(b);
|
||||
}
|
||||
if (args_background) {
|
||||
sys_notify_on_next_frame(&args_run_script_stop, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void args_run_on_next_frame(void *_) {
|
||||
if (!string_equals(g_project->_->filepath, "")) {
|
||||
import_arm_run_project(g_project->_->filepath);
|
||||
@@ -160,7 +205,13 @@ void args_run_on_next_frame(void *_) {
|
||||
export_arm_run_material(args_export_material_path);
|
||||
}
|
||||
|
||||
if (args_background) {
|
||||
if (args_api) {
|
||||
sys_notify_on_next_frame(&args_run_api, NULL);
|
||||
}
|
||||
else if (args_script) {
|
||||
sys_notify_on_next_frame(&args_run_script, NULL);
|
||||
}
|
||||
else if (args_background) {
|
||||
iron_stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,6 +436,7 @@ void script_quit(void);
|
||||
void script_project_new(void);
|
||||
void script_project_open(char *path);
|
||||
void script_import_asset(char *path, bool hdr_as_envmap);
|
||||
void script_append_mesh(char *path);
|
||||
void script_export_mesh(char *path);
|
||||
void script_export_material(char *path);
|
||||
void script_paint(f32 x, f32 y);
|
||||
@@ -912,6 +913,7 @@ void image_to_pbr_node_init();
|
||||
void text_to_image_node_init();
|
||||
void texture_mesh_node_init();
|
||||
void text_to_text_node_clear();
|
||||
char *text_to_text_node_reference();
|
||||
void text_to_text_node_run(char *prompt, void (*done)(char *));
|
||||
char *minic_api_header_generate();
|
||||
char *neural_node_vector(ui_node_t *node, ui_node_socket_t *socket);
|
||||
|
||||
@@ -256,6 +256,13 @@ void text_to_text_node_clear(void) {
|
||||
iron_delete_file(string("%s%sprompt.txt", gdir, PATH_SEP));
|
||||
}
|
||||
|
||||
char *text_to_text_node_reference(void) {
|
||||
char *api = minic_api_header_generate();
|
||||
char *nodes = text_to_text_node_nodes_reference();
|
||||
char *contents = text_to_text_node_project_contents();
|
||||
return string("%s\n%s\n%s\n%s\n", api, nodes, contents, text_to_text_node_guide);
|
||||
}
|
||||
|
||||
void text_to_text_node_run(char *prompt, void (*done)(char *)) {
|
||||
char *dir = neural_node_dir();
|
||||
if (string_equals(file_read_directory(dir)->buffer[0], "")) {
|
||||
@@ -263,14 +270,9 @@ void text_to_text_node_run(char *prompt, void (*done)(char *)) {
|
||||
}
|
||||
text_to_text_node_backend = g_config->console_model;
|
||||
|
||||
char *api = minic_api_header_generate();
|
||||
char *nodes = text_to_text_node_nodes_reference();
|
||||
char *contents = text_to_text_node_project_contents();
|
||||
char *reference = string("%s\n%s\n%s\n%s\n", api, nodes, contents, text_to_text_node_guide);
|
||||
|
||||
string_array_t *argv;
|
||||
if (text_to_text_node_backend == CONSOLE_MODEL_CLAUDE) {
|
||||
iron_file_save_bytes(string("%s%sapi.h", dir, PATH_SEP), sys_string_to_buffer(reference), 0);
|
||||
iron_file_save_bytes(string("%s%sapi.h", dir, PATH_SEP), sys_string_to_buffer(text_to_text_node_reference()), 0);
|
||||
argv = text_to_text_node_claude_args(dir, prompt);
|
||||
}
|
||||
else if (text_to_text_node_backend == CONSOLE_MODEL_GROK) {
|
||||
@@ -278,15 +280,15 @@ void text_to_text_node_run(char *prompt, void (*done)(char *)) {
|
||||
if (string_equals(file_read_directory(gdir)->buffer[0], "")) {
|
||||
iron_create_directory(gdir);
|
||||
}
|
||||
char *rules = string("%s\n%s\n", api, text_to_text_node_guide);
|
||||
char *rules = string("%s\n%s\n", minic_api_header_generate(), text_to_text_node_guide);
|
||||
iron_file_save_bytes(string("%s%sAGENTS.md", gdir, PATH_SEP), sys_string_to_buffer(rules), 0);
|
||||
|
||||
char *full = string("%s\n%s\n\n%s", contents, prompt, text_to_text_node_guide);
|
||||
char *full = string("%s\n%s\n\n%s", text_to_text_node_project_contents(), prompt, text_to_text_node_guide);
|
||||
iron_file_save_bytes(string("%s%sprompt.txt", gdir, PATH_SEP), sys_string_to_buffer(full), 0);
|
||||
argv = text_to_text_node_grok_args(gdir);
|
||||
}
|
||||
else {
|
||||
char *full = string("%s%s", reference, prompt);
|
||||
char *full = string("%s%s", text_to_text_node_reference(), prompt);
|
||||
iron_file_save_bytes(string("%s%sprompt.txt", dir, PATH_SEP), sys_string_to_buffer(full), 0);
|
||||
argv = text_to_text_node_qwen_args(dir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user