Files
armorpaint/paint/sources/args.c
T

193 lines
6.3 KiB
C
Raw Normal View History

2026-03-09 13:17:15 +01:00
#include "global.h"
2026-04-05 16:09:00 +02:00
bool args_use = false;
char *args_asset_path = "";
bool args_background = false;
bool args_export_textures = false;
char *args_export_textures_type = "";
char *args_export_textures_preset = "";
char *args_export_textures_path = "";
bool args_reimport_mesh = false;
bool args_export_mesh = false;
char *args_export_mesh_path = "";
bool args_export_material = false;
char *args_export_material_path = "";
2026-03-06 12:56:38 +01:00
void args_parse() {
if (iron_get_arg_count() > 1) {
args_use = true;
2026-03-25 22:16:09 +01:00
i32 i = 1;
2026-03-06 12:56:38 +01:00
while (i < iron_get_arg_count()) {
// Process each arg
2026-03-07 21:12:59 +01:00
char *current_arg = iron_get_arg(i);
2026-03-06 12:56:38 +01:00
if (path_is_project(current_arg)) {
gc_unroot(project_filepath);
project_filepath = string_copy(current_arg);
gc_root(project_filepath);
}
2026-03-25 22:16:09 +01:00
else if (string_equals(current_arg, "--background")) {
2026-03-06 12:56:38 +01:00
args_background = true;
}
2026-03-26 14:49:36 +01:00
else if (string_equals(current_arg, "--player")) {
args_player = true;
}
2026-03-06 12:56:38 +01:00
else if (path_is_texture(current_arg)) {
gc_unroot(args_asset_path);
args_asset_path = string_copy(current_arg);
gc_root(args_asset_path);
}
else if (string_equals(current_arg, "--export-textures") && (i + 3) <= iron_get_arg_count()) {
args_export_textures = true;
++i;
gc_unroot(args_export_textures_type);
args_export_textures_type = string_copy(iron_get_arg(i));
gc_root(args_export_textures_type);
++i;
gc_unroot(args_export_textures_preset);
args_export_textures_preset = string_copy(iron_get_arg(i));
gc_root(args_export_textures_preset);
++i;
gc_unroot(args_export_textures_path);
args_export_textures_path = string_copy(iron_get_arg(i));
gc_root(args_export_textures_path);
}
else if (string_equals(current_arg, "--reload-mesh")) {
args_reimport_mesh = true;
}
else if (string_equals(current_arg, "--export-mesh") && (i + 1) <= iron_get_arg_count()) {
args_export_mesh = true;
++i;
gc_unroot(args_export_mesh_path);
args_export_mesh_path = string_copy(iron_get_arg(i));
gc_root(args_export_mesh_path);
}
2026-03-25 22:16:09 +01:00
else if (path_is_mesh(current_arg) || iron_is_directory(current_arg)) {
2026-03-06 12:56:38 +01:00
gc_unroot(args_asset_path);
args_asset_path = string_copy(current_arg);
gc_root(args_asset_path);
}
else if (string_equals(current_arg, "--export-material") && (i + 1) <= iron_get_arg_count()) {
args_export_material = true;
++i;
gc_unroot(args_export_material_path);
args_export_material_path = string_copy(iron_get_arg(i));
gc_root(args_export_material_path);
}
2026-03-26 14:21:47 +01:00
else if (string_equals(current_arg, "--help")) {
printf("Usage: armorpaint [options] [file]\n");
printf("Options:\n");
printf(" --background Run without displaying the window\n");
printf(" --export-textures <type> <preset> <path>\n");
printf(" Export textures to path\n");
printf(" type: png, jpg, exr16, exr32\n");
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");
2026-03-26 14:49:36 +01:00
printf(" --player Run in player mode\n");
2026-03-26 14:21:47 +01:00
printf(" --help Show this help message\n");
exit(1);
}
2026-03-06 12:56:38 +01:00
++i;
}
}
}
2026-03-09 23:02:08 +01:00
void args_run_export_queue(void *_) {
2026-03-06 12:56:38 +01:00
export_texture_run(args_export_textures_path, false);
}
2026-03-09 23:02:08 +01:00
void args_run_on_next_frame(void *_) {
2026-03-06 12:56:38 +01:00
if (!string_equals(project_filepath, "")) {
import_arm_run_project(project_filepath);
}
else if (!string_equals(args_asset_path, "")) {
2026-03-07 21:12:59 +01:00
import_asset_run(args_asset_path, -1, -1, false, true, NULL);
2026-03-06 12:56:38 +01:00
if (path_is_texture(args_asset_path)) {
ui_base_show_2d_view(VIEW_2D_TYPE_ASSET);
}
}
else if (args_reimport_mesh) {
project_reimport_mesh();
}
if (args_export_textures) {
if (!path_is_folder(args_export_textures_path)) {
2026-03-15 11:37:45 +01:00
iron_log(tr("Invalid export directory"));
2026-03-06 12:56:38 +01:00
}
if (string_equals(args_export_textures_type, "png")) {
2026-04-21 10:52:27 +02:00
base_bits_handle->i = TEXTURE_BITS_BITS8;
2026-04-05 16:41:00 +02:00
g_context->format_type = TEXTURE_LDR_FORMAT_PNG;
2026-03-06 12:56:38 +01:00
}
else if (string_equals(args_export_textures_type, "jpg")) {
2026-04-21 10:52:27 +02:00
base_bits_handle->i = TEXTURE_BITS_BITS8;
2026-04-05 16:41:00 +02:00
g_context->format_type = TEXTURE_LDR_FORMAT_JPG;
2026-03-06 12:56:38 +01:00
}
else if (string_equals(args_export_textures_type, "exr16")) {
base_bits_handle->i = TEXTURE_BITS_BITS16;
}
else if (string_equals(args_export_textures_type, "exr32")) {
base_bits_handle->i = TEXTURE_BITS_BITS32;
}
else {
2026-03-15 11:37:45 +01:00
iron_log(tr("Invalid texture type"));
2026-03-06 12:56:38 +01:00
}
2026-04-05 16:41:00 +02:00
g_context->layers_export = EXPORT_MODE_VISIBLE;
2026-03-06 12:56:38 +01:00
// Get export preset and apply the correct one from args
gc_unroot(box_export_files);
2026-03-10 11:49:57 +01:00
box_export_files = file_read_directory(string("%s%sexport_presets", path_data(), PATH_SEP));
2026-03-06 12:56:38 +01:00
gc_root(box_export_files);
for (i32 i = 0; i < box_export_files->length; ++i) {
2026-03-10 11:49:57 +01:00
char *s = box_export_files->buffer[i];
2026-03-06 12:56:38 +01:00
box_export_files->buffer[i] = substring(s, 0, string_length(s) - 5); // Strip .json
}
2026-03-10 11:49:57 +01:00
char *file = string("export_presets/%s.json", box_export_files->buffer[0]);
2026-03-06 12:56:38 +01:00
for (i32 i = 0; i < box_export_files->length; ++i) {
2026-03-07 21:12:59 +01:00
char *f = box_export_files->buffer[i];
2026-03-06 12:56:38 +01:00
if (string_equals(f, args_export_textures_preset)) {
2026-03-10 11:49:57 +01:00
file = string("export_presets/%s.json", box_export_files->buffer[array_index_of(box_export_files, f)]);
2026-03-06 12:56:38 +01:00
}
}
buffer_t *blob = data_get_blob(file);
gc_unroot(box_export_preset);
box_export_preset = json_parse(sys_buffer_to_string(blob));
gc_root(box_export_preset);
2026-03-10 11:49:57 +01:00
data_delete_blob(string("export_presets/%s", file));
2026-03-06 12:56:38 +01:00
// Export queue
2026-03-09 23:02:08 +01:00
sys_notify_on_next_frame(&args_run_export_queue, NULL);
2026-03-06 12:56:38 +01:00
}
else if (args_export_mesh) {
if (!path_is_folder(args_export_mesh_path)) {
2026-03-15 11:37:45 +01:00
iron_log(tr("Invalid export directory"));
2026-03-06 12:56:38 +01:00
}
2026-03-07 21:12:59 +01:00
char *f = ui_files_filename;
2026-03-06 12:56:38 +01:00
if (string_equals(f, "")) {
2026-03-15 11:37:45 +01:00
f = string_copy(tr("untitled"));
2026-03-06 12:56:38 +01:00
}
2026-03-10 11:49:57 +01:00
export_mesh_run(string("%s%s%s", args_export_mesh_path, PATH_SEP, f), NULL, false, true);
2026-03-06 12:56:38 +01:00
}
else if (args_export_material) {
2026-04-05 16:41:00 +02:00
g_context->write_icon_on_export = true;
2026-03-06 12:56:38 +01:00
export_arm_run_material(args_export_material_path);
}
if (args_background) {
iron_stop();
}
}
2026-03-09 23:02:08 +01:00
void args_run() {
if (args_use) {
sys_notify_on_next_frame(&args_run_on_next_frame, NULL);
}
}