Separate CustomEntity global positions internally

This makes it so that `CustomEntity`s, at least internally, do not use
global tile position. Instead, they will use room-x and room-y
coordinates, which will be separate from their x- and y- positions.

This makes it much easier to deal with `CustomEntity`s, because you
don't have to divide and modulo everywhere to use them.

Since editorclass::add_entity and editorclass::get_entity_at expect
global tile position in their arguments, I've added room-x and room-y
arguments to these functions too.

Of course, due to compatibility reasons, the XML files will still have
to use global tile position. For the same reason, warp token
destinations are still using global tile position too.
This commit is contained in:
Misa
2023-03-29 00:18:42 -07:00
parent 98feeade02
commit 71dbe95dcb
5 changed files with 75 additions and 70 deletions

View File

@@ -942,12 +942,10 @@ void customlevelclass::findstartpoint(void)
else
{
//Start point spawn
int tx=customentities[testeditor].x/40;
int ty=customentities[testeditor].y/30;
game.edsavex = ((customentities[testeditor].x%40)*8)-4;
game.edsavey = (customentities[testeditor].y%30)*8;
game.edsaverx = 100+tx;
game.edsavery = 100+ty;
game.edsavex = (customentities[testeditor].x * 8) - 4;
game.edsavey = customentities[testeditor].y * 8;
game.edsaverx = 100 + customentities[testeditor].rx;
game.edsavery = 100 + customentities[testeditor].ry;
game.edsavegc = 0;
game.edsavey++;
game.edsavedir=1-customentities[testeditor].p1;
@@ -1151,6 +1149,8 @@ bool customlevelclass::load(std::string _path)
{
CustomEntity entity = CustomEntity();
const char* text = edEntityEl->GetText();
int global_x = 0;
int global_y = 0;
if (text != NULL)
{
@@ -1195,8 +1195,12 @@ bool customlevelclass::load(std::string _path)
entity.scriptname = std::string(text, len);
}
edEntityEl->QueryIntAttribute("x", &entity.x);
edEntityEl->QueryIntAttribute("y", &entity.y);
edEntityEl->QueryIntAttribute("x", &global_x);
edEntityEl->QueryIntAttribute("y", &global_y);
entity.rx = global_x / SCREEN_WIDTH_TILES;
entity.x = global_x % SCREEN_WIDTH_TILES;
entity.ry = global_y / SCREEN_HEIGHT_TILES;
entity.y = global_y % SCREEN_HEIGHT_TILES;
edEntityEl->QueryIntAttribute("t", &entity.t);
edEntityEl->QueryIntAttribute("p1", &entity.p1);
@@ -1537,8 +1541,10 @@ bool customlevelclass::save(const std::string& _path)
for(size_t i = 0; i < customentities.size(); i++)
{
tinyxml2::XMLElement *edentityElement = doc.NewElement( "edentity" );
edentityElement->SetAttribute( "x", customentities[i].x);
edentityElement->SetAttribute( "y", customentities[i].y);
const int global_x = customentities[i].rx * SCREEN_WIDTH_TILES + customentities[i].x;
const int global_y = customentities[i].ry * SCREEN_HEIGHT_TILES + customentities[i].y;
edentityElement->SetAttribute("x", global_x);
edentityElement->SetAttribute("y", global_y);
edentityElement->SetAttribute( "t", customentities[i].t);
edentityElement->SetAttribute( "p1", customentities[i].p1);
edentityElement->SetAttribute( "p2", customentities[i].p2);