paint: add util_script
This commit is contained in:
@@ -14,7 +14,6 @@
|
|||||||
#include "iron_shape.h"
|
#include "iron_shape.h"
|
||||||
#include "iron_string.h"
|
#include "iron_string.h"
|
||||||
#include "iron_sys.h"
|
#include "iron_sys.h"
|
||||||
#include "iron_tilesheet.h"
|
|
||||||
#include "iron_ui.h"
|
#include "iron_ui.h"
|
||||||
#include "minic.h"
|
#include "minic.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -366,6 +365,9 @@ project_t *script_get_project() {
|
|||||||
return g_project;
|
return g_project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void script_set_stage(char *name);
|
||||||
|
void script_set_tilesheet_anim(object_t *o, char *anim);
|
||||||
|
|
||||||
object_t *script_get_object(char *s) {
|
object_t *script_get_object(char *s) {
|
||||||
for (int i = 0; i < g_project->_->paint_objects->length; ++i) {
|
for (int i = 0; i < g_project->_->paint_objects->length; ++i) {
|
||||||
if (string_equals(g_project->_->paint_objects->buffer[i]->base->name, s)) {
|
if (string_equals(g_project->_->paint_objects->buffer[i]->base->name, s)) {
|
||||||
@@ -791,6 +793,8 @@ void minic_register_builtins() {
|
|||||||
|
|
||||||
MINIC_STRUCT(transform_t);
|
MINIC_STRUCT(transform_t);
|
||||||
MINIC_E(loc, vec4_t);
|
MINIC_E(loc, vec4_t);
|
||||||
|
MINIC_E(rot, quat_t);
|
||||||
|
MINIC_E(scale, vec4_t);
|
||||||
MINIC_F(scale_world);
|
MINIC_F(scale_world);
|
||||||
MINIC_I(dirty);
|
MINIC_I(dirty);
|
||||||
MINIC_O(object, object_t);
|
MINIC_O(object, object_t);
|
||||||
@@ -1339,6 +1343,8 @@ void minic_register_builtins() {
|
|||||||
R(script_get_config, "p()");
|
R(script_get_config, "p()");
|
||||||
R(script_get_project, "p()");
|
R(script_get_project, "p()");
|
||||||
R(script_get_object, "p(p)");
|
R(script_get_object, "p(p)");
|
||||||
|
R(script_set_stage, "v(p)");
|
||||||
|
R(script_set_tilesheet_anim, "v(p,p)");
|
||||||
R(context_set_viewport_shader, "v(p)");
|
R(context_set_viewport_shader, "v(p)");
|
||||||
R(context_set_viewport_mode, "v(i)");
|
R(context_set_viewport_mode, "v(i)");
|
||||||
R(context_set_camera_controls, "v(i)");
|
R(context_set_camera_controls, "v(i)");
|
||||||
|
|||||||
@@ -411,6 +411,7 @@ stage_t *tab_stages_get_stage();
|
|||||||
void tab_stages_apply(stage_t *stage);
|
void tab_stages_apply(stage_t *stage);
|
||||||
void tab_stages_rename_object(char *old_name, char *new_name);
|
void tab_stages_rename_object(char *old_name, char *new_name);
|
||||||
void tab_stages_rename_layer(char *old_name, char *new_name);
|
void tab_stages_rename_layer(char *old_name, char *new_name);
|
||||||
|
void script_set_stage(char *name);
|
||||||
void tab_stages_prune();
|
void tab_stages_prune();
|
||||||
void project_open();
|
void project_open();
|
||||||
void project_save(bool save_and_quit);
|
void project_save(bool save_and_quit);
|
||||||
|
|||||||
@@ -192,6 +192,7 @@
|
|||||||
#include "util/util_raycast.c"
|
#include "util/util_raycast.c"
|
||||||
#include "util/util_render.c"
|
#include "util/util_render.c"
|
||||||
#include "util/util_resize.c"
|
#include "util/util_resize.c"
|
||||||
|
#include "util/util_script.c"
|
||||||
#include "util/util_select.c"
|
#include "util/util_select.c"
|
||||||
#include "util/util_shortcut.c"
|
#include "util/util_shortcut.c"
|
||||||
#include "util/util_stage.c"
|
#include "util/util_stage.c"
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
|
||||||
|
#include "../global.h"
|
||||||
|
|
||||||
|
void script_set_stage(char *name) {
|
||||||
|
if (g_project->stages == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (i32 i = 0; i < g_project->stages->length; ++i) {
|
||||||
|
stage_t *s = g_project->stages->buffer[i];
|
||||||
|
if (string_equals(s->name, name)) {
|
||||||
|
tab_stages_selected = i;
|
||||||
|
tab_stages_apply(s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void script_set_tilesheet_anim(object_t *o, char *anim) {
|
||||||
|
mesh_object_t *mo = (mesh_object_t *)o->ext;
|
||||||
|
|
||||||
|
// Locate the material slot
|
||||||
|
i32 slot_index = tab_meshes_get_override(mo);
|
||||||
|
if (slot_index < 0) {
|
||||||
|
for (i32 i = 0; i < g_project->_->materials->length; ++i) {
|
||||||
|
if (g_project->_->materials->buffer[i]->data == mo->material) {
|
||||||
|
slot_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slot_material_t *slot = g_project->_->materials->buffer[slot_index];
|
||||||
|
|
||||||
|
// Locate the tilesheet animation node
|
||||||
|
for (i32 i = 0; i < slot->canvas->nodes->length; ++i) {
|
||||||
|
ui_node_t *node = slot->canvas->nodes->buffer[i];
|
||||||
|
if (!string_equals(node->type, "TILESHEET_ANIM")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_node_button_t *enum_but = node->buttons->buffer[4];
|
||||||
|
string_array_t *names = string_split(u8_array_to_string(enum_but->data), "\n");
|
||||||
|
for (i32 j = 0; j < (i32)names->length; ++j) {
|
||||||
|
if (!string_equals(names->buffer[j], anim)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum_but->default_value->buffer[0] = (f32)j;
|
||||||
|
make_material_parse_paint_material(true);
|
||||||
|
|
||||||
|
// Material override
|
||||||
|
for (i32 k = 0; k < g_project->_->paint_objects->length; ++k) {
|
||||||
|
mesh_object_t *po = g_project->_->paint_objects->buffer[k];
|
||||||
|
if (tab_meshes_get_override(po) == slot_index) {
|
||||||
|
tab_meshes_set_override(po, slot_index);
|
||||||
|
g_context->ddirty = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user