Carpet

Carpet

2M Downloads

[Suggestion] Abstract core functionality of draw app into a library

altrisi opened this issue ยท 2 comments

commented

With the rise of world editing software since the recent changes in other software, there are suggestions of developing and integrating new methods of doing the same as the draw (beta) app inside other, bigger apps.

Therefore, my suggestion here would be to make the draw command app just a wrapper for a more generic library that would contain the shape processing code, that could then also be included in other apps, instead of having duplicated code.

My suggestion would be to separate every shape building method from the app into the library, and then following the next format to be called:

draw_[shape]([...params], set_handler);

//# Example set_handler implementation
set_handler(pos)-> (
    existing = block(pos);
    if (global_block != existing && (!global_replacement || _block_matches(existing, global_replacement) ),
        global_positions += bool(set(existing, global_block))
    )
);

//# Example call
import('shapes','draw_sphere');

global_replacement = 'dirt';
global_block = 'iron_block';
global_positions = 0;

draw_sphere([100,60,100], 25, true, 'set_handler'); //# draw_sphere(pos, radius, hollow, set_handler)
print('Affected '+global_positions+' blocks');

Relates to Ghoulboy78/Scarpet-edit#4

commented

isn't that 'just' because draw is a subset of we?

commented

Yes, but I prefer using general terms, since that would also allow other apps to use those shapes in an efficient way (supposing it's implemented efficiently) in case they need those shapes for anything (doesn't really need to be drawing them, the library would just come back with the positions somehow, maybe instead of a function handler returning them as a list?)