Pixel-Composer/scripts/__tiler_autoterrain/__tiler_autoterrain.gml

143 lines
4.8 KiB
Text
Raw Normal View History

enum AUTOTERRAIN_TYPE {
2024-10-21 11:50:45 +02:00
box9,
box25,
2024-10-21 11:50:45 +02:00
side15,
top48,
2024-10-24 12:40:14 +02:00
top55,
2024-10-21 11:50:45 +02:00
}
global.autoterrain_amount = [ 9, 16, 15, 48, 55, ];
function tiler_brush_autoterrain(_type, _index) constructor {
2024-11-01 05:57:42 +01:00
name = "autoterrain";
index = _index;
prevInd = 0;
type = -1;
2024-10-19 12:35:47 +02:00
2024-11-01 05:57:42 +01:00
mask_surface = noone;
update_surface = noone;
draw_surface_mask = noone;
target_surface = noone;
eraseMode = false;
2024-10-19 12:35:47 +02:00
2024-10-24 12:40:14 +02:00
preview_surface = noone;
preview_surface_tile = noone;
open = false;
2024-10-19 12:35:47 +02:00
2024-11-01 05:57:42 +01:00
sc_type = new scrollBox(["Simple box (3x3)", "Corner box (5x5)", "Side platform (5x3)", "Godot tile (12x4)", "Gamemaker tileset (11x5)"], function(ind) /*=>*/ { setType(ind); }, false);
sc_type.font = f_p3;
static indexMap48 = [ 8, 10, 11, 0, 1, 6, 5, 3, 2, 34, 12, 20, 33, 35, 12, 28, 30, 29, 31, 46, 21, 12, 44, 45, 47, 24, 16, 18, 17, 19, 9, 43, 40, 37, 38, 39, 36, 25, 42, 41, 27, 26, 7, 4, 13, 23, 32, 15, 14, 12 ];
2024-11-01 05:57:42 +01:00
static indexMapOld = [
[ 0, 1, 2,
11, 12, 13,
22, 23, 24 ],
[-1, 0, 1, 2, -1,
0, 28, 12, 27, 2,
11, 12, 12, 12, 13,
22, 17, 12, 16, 24,
-1, 22, 23, 24, -1 ],
[ 0, 1, 2, 16, 17,
11, 12, 13, 27, 28,
22, 23, 24, 9, 20 ],
[ 3, 4, 8, 7, 43, 6, 5, 42, 0, 30, 1, 2,
14, 48, 52, 51, 26, 28, 27, 29, 11, 20, -1, 49,
25, 37, 41, 40, 15, 17, 16, 18, 50, 12, 9, 13,
36, 33, 34, 35, 32, 39, 38, 31, 22, 23, 19, 24, ],
array_create_ext(55, function(i) /*=>*/ {return i}),
];
static setType = function(_type) {
2024-11-01 05:57:42 +01:00
if(type == _type) return;
2024-11-01 05:57:42 +01:00
if(type != -1) {
var _idMap = array_create(55, -1);
var _mapol = indexMapOld[ type];
var _mapnw = indexMapOld[_type];
for( var i = 0, n = array_length(index); i < n; i++ ) {
if(_mapol[i] != -1) _idMap[_mapol[i]] = index[i];
}
}
2024-11-01 05:57:42 +01:00
switch(_type) {
2024-12-15 12:19:48 +01:00
case 0 : index = array_verify_ext(index, 9, function() /*=>*/ {return -1}); prevInd = 0; break;
case 1 : index = array_verify_ext(index, 25, function() /*=>*/ {return -1}); prevInd = 1; break;
case 2 : index = array_verify_ext(index, 15, function() /*=>*/ {return -1}); prevInd = 0; break;
case 3 : index = array_verify_ext(index, 48, function() /*=>*/ {return -1}); prevInd = 8; break;
case 4 : index = array_verify_ext(index, 55, function() /*=>*/ {return -1}); prevInd = 0; break;
2024-11-01 05:57:42 +01:00
}
if(type != -1) {
for( var i = 0, n = array_length(index); i < n; i++ ) {
if(_mapnw[i] != -1) index[i] = _idMap[_mapnw[i]];
else index[i] = -1;
}
}
type = _type;
} setType(_type);
2024-10-19 12:35:47 +02:00
static drawing_start = function(surface, _erase = false) {
target_surface = surface;
eraseMode = _erase;
2024-11-01 05:57:42 +01:00
var _dim = surface_get_dimension(surface);
draw_surface_mask = surface_verify(draw_surface_mask, _dim[0], _dim[1], surface_r8unorm);
mask_surface = surface_verify(mask_surface, _dim[0], _dim[1], surface_r8unorm);
update_surface = surface_verify(update_surface, _dim[0], _dim[1], surface_rgba16float);
2024-10-19 12:35:47 +02:00
2024-11-01 05:57:42 +01:00
surface_clear(draw_surface_mask);
surface_clear(mask_surface);
surface_clear(update_surface);
2024-10-25 13:02:52 +02:00
2024-10-19 12:35:47 +02:00
draw_set_color(c_white);
2024-11-01 05:57:42 +01:00
surface_set_target(draw_surface_mask);
2024-10-19 12:35:47 +02:00
DRAW_CLEAR
}
static drawing_end = function() {
surface_reset_target();
// autoterrain mask
// #000000 : not part of autoterrain
// #808080 : part of autoterrain, read only
// #FFFFFF : part of autoterrain, writable
2024-10-19 12:35:47 +02:00
surface_set_shader(mask_surface, sh_tiler_autoterrain_mask);
2024-11-01 05:57:42 +01:00
shader_set_surface("drawSurface", draw_surface_mask);
2024-10-19 12:35:47 +02:00
shader_set_i("indexes", index);
shader_set_i("indexSize", array_length(index));
draw_surface(target_surface, 0, 0);
surface_reset_shader();
surface_set_shader(update_surface, sh_tiler_autoterrain_apply);
2024-11-01 05:57:42 +01:00
shader_set_2("dimension", surface_get_dimension(update_surface));
2024-10-19 12:35:47 +02:00
shader_set_surface("maskSurface", mask_surface);
shader_set_i("bitmaskType", type);
shader_set_i("indexMapper48", indexMap48);
2024-10-19 12:35:47 +02:00
shader_set_i("indexes", index);
shader_set_i("indexSize", array_length(index));
shader_set_i("erase", eraseMode);
draw_surface(target_surface, 0, 0);
surface_reset_shader();
surface_set_target(target_surface);
DRAW_CLEAR
BLEND_OVERRIDE
draw_surface(update_surface, 0, 0);
BLEND_NORMAL
surface_reset_target();
}
}