drag n drop editor images
This commit is contained in:
parent
55d5133414
commit
a8ee53ec33
|
@ -542,7 +542,7 @@ var editor = {
|
|||
viewasset(path) {
|
||||
Log.info(path);
|
||||
var fn = function(x) { return path.endsWith(x); };
|
||||
if (images.any(fn)) {
|
||||
if (Resources.images.any(fn)) {
|
||||
var newtex = Object.copy(texgui, { path: path });
|
||||
this.addpanel(newtex);
|
||||
}
|
||||
|
@ -608,6 +608,23 @@ var editor = {
|
|||
}
|
||||
|
||||
editor.inputs = {};
|
||||
editor.inputs.drop = function(str) {
|
||||
if (!Resources.is_image(str)) {
|
||||
console.warn("NOT AN IMAGE");
|
||||
return;
|
||||
}
|
||||
if (this.sel_comp?.comp === 'sprite') {
|
||||
this.sel_comp.path = str;
|
||||
return;
|
||||
}
|
||||
|
||||
var mg = physics.pos_query(Mouse.worldpos,10);
|
||||
if (!mg) return;
|
||||
var img = mg.get_comp_by_name('sprite');
|
||||
if (!img) return;
|
||||
img[0].path = str;
|
||||
}
|
||||
|
||||
editor.inputs.f9 = function() {
|
||||
Log.warn("CAPTURING");
|
||||
cmd(173, "capture.bmp", 0, 0, 500, 500);
|
||||
|
@ -1882,11 +1899,8 @@ var gen_notify = function(val, fn) {
|
|||
return panel;
|
||||
};
|
||||
|
||||
var scripts = ["js"];
|
||||
var images = ["png", "jpg", "jpeg"];
|
||||
var sounds = ["wav", "mp3"];
|
||||
var allfiles = [];
|
||||
allfiles.push(scripts, images, sounds);
|
||||
allfiles.push(Resources.scripts, Resources.images, Resources.sounds);
|
||||
allfiles = allfiles.flat();
|
||||
|
||||
var assetexplorer = Object.copy(openlevelpanel, {
|
||||
|
|
|
@ -56,6 +56,14 @@ actor.remaster = function(to){
|
|||
};
|
||||
|
||||
var gameobject = {
|
||||
get_comp_by_name(name) {
|
||||
var comps = [];
|
||||
for (var c of Object.values(this.components))
|
||||
if (c.comp === name) comps.push(c);
|
||||
|
||||
if (comps.length) return comps;
|
||||
return undefined;
|
||||
},
|
||||
check_dirty() {
|
||||
this._ed.urdiff = this.json_obj();
|
||||
this._ed.dirty = !this._ed.urdiff.empty;
|
||||
|
|
|
@ -17,6 +17,19 @@ OS.exec = function(s)
|
|||
cmd(143, s);
|
||||
}
|
||||
|
||||
var Resources = {};
|
||||
Resources.images = ["png", "jpg", "jpeg", "gif"];
|
||||
Resources.sounds = ["wav", "mp3", "flac"];
|
||||
Resources.scripts = "js";
|
||||
Resources.is_image = function(path) {
|
||||
var ext = path.ext();
|
||||
return Resources.images.any(x => x === ext);
|
||||
}
|
||||
Resources.is_sound = function(path) {
|
||||
var ext = path.ext();
|
||||
return Resources.sounds.any(x => x === ext);
|
||||
}
|
||||
|
||||
var Log = {
|
||||
set level(x) { cmd(92,x); },
|
||||
get level() { return cmd(93); },
|
||||
|
|
|
@ -401,8 +401,5 @@ void draw_drawmodel(struct drawmodel *dm)
|
|||
draw_model(dm->model, rst);
|
||||
}
|
||||
|
||||
void free_drawmodel(struct drawmodel *dm)
|
||||
{
|
||||
free(dm);
|
||||
}
|
||||
void free_drawmodel(struct drawmodel *dm) { free(dm); }
|
||||
|
||||
|
|
|
@ -351,7 +351,7 @@ void draw_line(HMM_Vec2 *points, int n, struct rgba color, float seg_len, float
|
|||
|
||||
uint16_t idxs[i_c];
|
||||
for (int i = 0, d = 0; i < n-1; i++, d+=2) {
|
||||
idxs[d] = i + line_v;
|
||||
idxs[d] = i + line_v + line_sv;
|
||||
idxs[d+1] = idxs[d]+1;
|
||||
}
|
||||
|
||||
|
@ -368,9 +368,7 @@ void draw_line(HMM_Vec2 *points, int n, struct rgba color, float seg_len, float
|
|||
sg_append_buffer(line_bind.vertex_buffers[0], &vr);
|
||||
sg_append_buffer(line_bind.index_buffer, &ir);
|
||||
|
||||
YughWarn("Drew %d line segments with %d verts and %d indexes, starting at %d and %d.", n-1, n, i_c, line_v, line_c);
|
||||
|
||||
line_c += i_c+1;
|
||||
line_c += i_c;
|
||||
line_v += n;
|
||||
}
|
||||
|
||||
|
@ -434,12 +432,10 @@ void draw_edge(HMM_Vec2 *points, int n, struct rgba color, int thickness, int fl
|
|||
{
|
||||
int closed = 0;
|
||||
if (thickness <= 1) {
|
||||
draw_line(points,n,color,0,0);
|
||||
draw_line(points,n,line_color,0,0);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
/* todo: should be dashed, and filled. use a texture. */
|
||||
/* draw polygon outline */
|
||||
if (HMM_EqV2(points[0], points[n-1])) {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <ctype.h>
|
||||
#include <wchar.h>
|
||||
#include "resources.h"
|
||||
#include "jsffi.h"
|
||||
|
||||
static int mouse_states[3] = {INPUT_UP};
|
||||
static int key_states[512] = {INPUT_UP};
|
||||
|
@ -185,6 +186,18 @@ void register_gamepad(struct callee c) {
|
|||
gamepad_callee = c;
|
||||
}
|
||||
|
||||
void input_dropped_files(int n)
|
||||
{
|
||||
|
||||
JSValue argv[4];
|
||||
argv[0] = jstr("emacs");
|
||||
argv[1] = jstr("drop");
|
||||
argv[2] = jstr("pressed");
|
||||
argv[3] = str2js(sapp_get_dropped_file_path(0));
|
||||
script_callee(pawn_callee, 4, argv);
|
||||
JS_FreeValue(js,argv[3]);
|
||||
}
|
||||
|
||||
static void pawn_call_keydown(int key) {
|
||||
JSValue argv[4];
|
||||
argv[0] = jstr("input");
|
||||
|
|
|
@ -29,6 +29,8 @@ void input_mouse_scroll(float x, float y, uint32_t mod);
|
|||
void input_btn(int btn, int state, uint32_t mod);
|
||||
void input_key(uint32_t key, uint32_t mod);
|
||||
|
||||
void input_dropped_files(int n);
|
||||
|
||||
const char *keyname_extd(int key);
|
||||
int action_down(int key);
|
||||
|
||||
|
|
|
@ -222,6 +222,11 @@ void c_event(const sapp_event *e)
|
|||
case SAPP_EVENTTYPE_QUIT_REQUESTED:
|
||||
window_quit();
|
||||
break;
|
||||
|
||||
case SAPP_EVENTTYPE_FILES_DROPPED:
|
||||
input_mouse_move(e->mouse_x, e->mouse_y, e->mouse_dx, e->mouse_dy, e->modifiers);
|
||||
input_dropped_files(sapp_get_num_dropped_files());
|
||||
break;
|
||||
}
|
||||
|
||||
if (editor_mode)
|
||||
|
|
Loading…
Reference in a new issue