Sauerworld Forum

Simple selection commands to expand map editing possibilities in Sauer

Salatiel

  • ***
  • 110
  • +24/-1
    • Projects by Salatiel
Hello, these are 4 new functions, the goal is to expand the possibilities of map editing using cubescript.

editinview
editinview variable, if 0 the player can edit even if the selection is off the screen, if 1 edit is blocked if the selection is off screen, default is 1.

getselpos
getselpos command is based on the getcampos command, and returns the position of the current edit selection.

setselpos
setselpos command sets the position of the edit selection based on 3 int values ​​(x, y, z), if a current selection does not exist, it will be created.

movesel
movesel command moves the edit selection toward a direction.
First argument is the number of cubes to move (-1, 1).
Second argument is the direction (0 = x, 1 = y, 2 = z).
Example:
/movesel 1 2 will move the selection 1 cube up.

Code: [Select]
VARP(editinview, 0, 1, 1);
bool noedit(bool view, bool msg)
{
    if(!editmode) { if(msg) conoutf(CON_ERROR, "operation only allowed in edit mode"); return true; }
    if(view || haveselent()) return false;
    float r = 1.0f;
    vec o = sel.o.tovec(), s = sel.s.tovec();
    s.mul(float(sel.grid) / 2.0f);
    o.add(s);
    r = float(max(s.x, max(s.y, s.z)));
    bool viewable = (isvisiblesphere(r, o) != VFC_NOT_VISIBLE);
    //if(!viewable && msg) conoutf(CON_ERROR, "selection not in view");
    //return !viewable;
    if(!viewable && editinview && msg) {conoutf(CON_ERROR, "selection not in view");}
    if (editinview){return !viewable;} else {return false;}
}

ICOMMAND(getselpos, "", (),
{
    defformatstring(pos)("%s %s %s", floatstr(sel.o.x), floatstr(sel.o.y), floatstr(sel.o.z));
    result(pos);
});

void setselpos(int* posx, int* posy, int* posz)
{
    if(noedit(moving!=0)) return;
    if(!havesel){havesel = true;};
    sel.o.x = *posx - *posx % gridsize;
    sel.o.y = *posy - *posy % gridsize;
    sel.o.z = *posz - *posz % gridsize;
}
COMMAND(setselpos, "iii");

void movesel(int *dir, int *pface)
{
    if(noedit(moving!=0)) return;
    if((*pface > 2) || (*pface < 0)) return;
    int s = *dir;
    sel.o[*pface] += s*sel.grid;
}
COMMAND(movesel, "ii");


Where to install it
These commands goes somewhere after line 90 in the original file (src/engine/octaedit.cpp, before VARF(gridpower, 0, 3, 12... ).
Be careful to not multiply the bool noedit function, it already exists (line 149), you can replace it entirety.
Or you can download the octaedit.cpp file below.

feel free to leave your feedback :D
@Salatiel#5274

Salatiel

  • ***
  • 110
  • +24/-1
    • Projects by Salatiel
Re: Simple selection commands to expand map editing possibilities in Sauer
« Reply #1 on: January 10, 2020, 06:29:04 PM »
a possible new sauer release is coming and it would be nice to hear some feedback about these commands, not about their usefulness, but the way they were implemented...

Since I started playing sauerbraten I have always missed more possibilities to move the selection besides doing it manually with the mouse (and universaldelta/editface which are limited in one direction only), I feel this opens up a world of possibilities, the sauer map editor is an awesome 3D canvas just waiting for these "automatic pencils"...

I could just sit here with my modified client and play with these commands forever, but it's not fun to do so without being able to share them easily. I understand that perhaps the only reason eihrul hasn't added it to svn yet is because the commands aren't perfect, which is why I'd love to know how they can be improved :D

Edit 20/01/20
Good news, thanks to Eihrul, who reworked the commands and included them in a better way, they are now available on SVN :D
https://sourceforge.net/p/sauerbraten/code/5625/
« Last Edit: January 20, 2020, 03:53:18 AM by Salatiel »
@Salatiel#5274