mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-29 11:26:35 -05:00
Merge pull request #448 from GriffinRichards/handle-collision
Various minor API improvements
This commit is contained in:
@@ -350,6 +350,7 @@ bool Map::getBlock(int x, int y, Block *out) {
|
||||
}
|
||||
|
||||
void Map::setBlock(int x, int y, Block block, bool enableScriptCallback) {
|
||||
if (!isWithinBounds(x, y)) return;
|
||||
int i = y * getWidth() + x;
|
||||
if (i < layout->blockdata.size()) {
|
||||
Block prevBlock = layout->blockdata.at(i);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
palette(0)
|
||||
{ }
|
||||
|
||||
Tile::Tile(int tileId, bool xflip, bool yflip, int palette) :
|
||||
Tile::Tile(uint16_t tileId, uint16_t xflip, uint16_t yflip, uint16_t palette) :
|
||||
tileId(tileId),
|
||||
xflip(xflip),
|
||||
yflip(yflip),
|
||||
|
||||
@@ -120,6 +120,12 @@ QList<QRgb> Tileset::getPalette(int paletteId, Tileset *primaryTileset, Tileset
|
||||
? primaryTileset
|
||||
: secondaryTileset;
|
||||
auto palettes = useTruePalettes ? tileset->palettes : tileset->palettePreviews;
|
||||
|
||||
if (paletteId < 0 || paletteId >= palettes.length()){
|
||||
logError(QString("Invalid tileset palette id '%1' requested.").arg(paletteId));
|
||||
return paletteTable;
|
||||
}
|
||||
|
||||
for (int i = 0; i < palettes.at(paletteId).length(); i++) {
|
||||
paletteTable.append(palettes.at(paletteId).at(i));
|
||||
}
|
||||
|
||||
@@ -1075,7 +1075,7 @@ QString Editor::getMovementPermissionText(uint16_t collision, uint16_t elevation
|
||||
} else if (collision == 0) {
|
||||
message = QString("Collision: Passable, Elevation: %1").arg(elevation);
|
||||
} else {
|
||||
message = QString("Collision: Impassable, Elevation: %1").arg(elevation);
|
||||
message = QString("Collision: Impassable (%1), Elevation: %2").arg(collision).arg(elevation);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -55,10 +55,18 @@ void MainWindow::tryCommitMapChanges(bool commitChanges) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setBlock(int x, int y, int tile, int collision, int elevation, bool forceRedraw, bool commitChanges) {
|
||||
void MainWindow::setBlock(int x, int y, int metatileId, int collision, int elevation, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return;
|
||||
this->editor->map->setBlock(x, y, Block(tile, collision, elevation));
|
||||
this->editor->map->setBlock(x, y, Block(metatileId, collision, elevation));
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
this->tryRedrawMapArea(forceRedraw);
|
||||
}
|
||||
|
||||
void MainWindow::setBlock(int x, int y, int rawValue, bool forceRedraw, bool commitChanges) {
|
||||
if (!this->editor || !this->editor->map)
|
||||
return;
|
||||
this->editor->map->setBlock(x, y, Block(static_cast<uint16_t>(rawValue)));
|
||||
this->tryCommitMapChanges(commitChanges);
|
||||
this->tryRedrawMapArea(forceRedraw);
|
||||
}
|
||||
@@ -1073,6 +1081,22 @@ void MainWindow::setMetatileBehavior(int metatileId, int behavior) {
|
||||
this->saveMetatileAttributesByMetatileId(metatileId);
|
||||
}
|
||||
|
||||
int MainWindow::getMetatileAttributes(int metatileId) {
|
||||
Metatile * metatile = this->getMetatile(metatileId);
|
||||
if (!metatile)
|
||||
return -1;
|
||||
return metatile->getAttributes(projectConfig.getBaseGameVersion());
|
||||
}
|
||||
|
||||
void MainWindow::setMetatileAttributes(int metatileId, int attributes) {
|
||||
Metatile * metatile = this->getMetatile(metatileId);
|
||||
uint32_t u_attributes = static_cast<uint32_t>(attributes);
|
||||
if (!metatile)
|
||||
return;
|
||||
metatile->setAttributes(u_attributes, projectConfig.getBaseGameVersion());
|
||||
this->saveMetatileAttributesByMetatileId(metatileId);
|
||||
}
|
||||
|
||||
int MainWindow::calculateTileBounds(int * tileStart, int * tileEnd) {
|
||||
int maxNumTiles = this->getNumTilesInMetatile();
|
||||
if (*tileEnd >= maxNumTiles || *tileEnd < 0)
|
||||
|
||||
@@ -275,17 +275,17 @@ QJSValue Scripting::position(int x, int y) {
|
||||
}
|
||||
|
||||
Tile Scripting::toTile(QJSValue obj) {
|
||||
if (!obj.hasProperty("tileId")
|
||||
|| !obj.hasProperty("xflip")
|
||||
|| !obj.hasProperty("yflip")
|
||||
|| !obj.hasProperty("palette")) {
|
||||
return Tile();
|
||||
}
|
||||
Tile tile = Tile();
|
||||
tile.tileId = obj.property("tileId").toInt();
|
||||
tile.xflip = obj.property("xflip").toBool();
|
||||
tile.yflip = obj.property("yflip").toBool();
|
||||
tile.palette = obj.property("palette").toInt();
|
||||
|
||||
if (obj.hasProperty("tileId"))
|
||||
tile.tileId = obj.property("tileId").toInt();
|
||||
if (obj.hasProperty("xflip"))
|
||||
tile.xflip = obj.property("xflip").toBool();
|
||||
if (obj.hasProperty("yflip"))
|
||||
tile.yflip = obj.property("yflip").toBool();
|
||||
if (obj.hasProperty("palette"))
|
||||
tile.palette = obj.property("palette").toInt();
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ QImage getCollisionMetatileImage(Block block) {
|
||||
}
|
||||
|
||||
QImage getCollisionMetatileImage(int collision, int elevation) {
|
||||
int x = collision * 16;
|
||||
int x = (collision != 0) * 16;
|
||||
int y = elevation * 16;
|
||||
QPixmap collisionImage = QPixmap(":/images/collisions.png").copy(x, y, 16, 16);
|
||||
return collisionImage.toImage();
|
||||
@@ -66,13 +66,13 @@ QImage getMetatileImage(
|
||||
tile = metatile->tiles.value(tileOffset + (l * 4));
|
||||
} else {
|
||||
// "Vanilla" metatiles only have 8 tiles, but render 12.
|
||||
// The remaining 4 tiles are rendered either as tile 0 or 0x3014 (invalid) depending on layer type.
|
||||
// The remaining 4 tiles are rendered either as tile 0 or 0x3014 (tile 20, palette 3) depending on layer type.
|
||||
switch (layerType)
|
||||
{
|
||||
default:
|
||||
case METATILE_LAYER_MIDDLE_TOP:
|
||||
if (l == 0)
|
||||
tile = Tile(0x3014, false, false, 0);
|
||||
tile = Tile(0x3014);
|
||||
else // Tiles are on layers 1 and 2
|
||||
tile = metatile->tiles.value(tileOffset + ((l - 1) * 4));
|
||||
break;
|
||||
|
||||
@@ -16,7 +16,7 @@ uint16_t MovementPermissionsSelector::getSelectedElevation() {
|
||||
}
|
||||
|
||||
void MovementPermissionsSelector::select(uint16_t collision, uint16_t elevation) {
|
||||
SelectablePixmapItem::select(collision, elevation, 0, 0);
|
||||
SelectablePixmapItem::select(collision != 0, elevation, 0, 0);
|
||||
}
|
||||
|
||||
void MovementPermissionsSelector::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||
|
||||
@@ -26,9 +26,11 @@ void OverlayImage::render(QPainter *painter, int x, int y) {
|
||||
void Overlay::renderItems(QPainter *painter) {
|
||||
if (this->hidden) return;
|
||||
|
||||
qreal oldOpacity = painter->opacity();
|
||||
painter->setOpacity(this->opacity);
|
||||
for (auto item : this->items)
|
||||
item->render(painter, this->x, this->y);
|
||||
painter->setOpacity(oldOpacity);
|
||||
}
|
||||
|
||||
void Overlay::clearItems() {
|
||||
|
||||
Reference in New Issue
Block a user