Skip to content

Commit

Permalink
Fixed storing template instance size when overriding the tile
Browse files Browse the repository at this point in the history
When the new tile that is set on the template instance causes the object
to be resized, we should remember that we have also overridden the
template's size.

Also changed the sandbox2.tmx example to actually use the objs.tsx
fileset instead of having an internal copy.

Closes #2889
  • Loading branch information
bjorn committed Nov 6, 2020
1 parent eee8cd4 commit e96d6f7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 218 deletions.
225 changes: 13 additions & 212 deletions examples/sticker-knight/map/sandbox2.tmx
Original file line number Diff line number Diff line change
@@ -1,194 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="80" height="31" tilewidth="32" tileheight="32" backgroundcolor="#35495e" nextobjectid="385">
<tileset firstgid="1" name="objs" tilewidth="384" tileheight="332" tilecount="62" columns="0">
<tile id="0">
<image width="160" height="192" source="alter.png"/>
</tile>
<tile id="1">
<image width="96" height="64" source="blobBlue.png"/>
</tile>
<tile id="2">
<image width="96" height="64" source="blobGreen.png"/>
</tile>
<tile id="3">
<image width="64" height="64" source="blue.png"/>
</tile>
<tile id="4">
<image width="96" height="128" source="bombStroked.png"/>
</tile>
<tile id="5">
<image width="64" height="64" source="castleWall.png"/>
</tile>
<tile id="6">
<image width="384" height="128" source="cloud.png"/>
</tile>
<tile id="7">
<image width="128" height="192" source="column1.png"/>
</tile>
<tile id="8">
<image width="128" height="192" source="column2.png"/>
</tile>
<tile id="9">
<image width="160" height="192" source="doorBlueStroked.png"/>
</tile>
<tile id="10">
<image width="160" height="192" source="doorGreenStroke.png"/>
</tile>
<tile id="11">
<image width="160" height="192" source="doorRedStroked.png"/>
</tile>
<tile id="12">
<image width="160" height="192" source="doorStroked.png"/>
</tile>
<tile id="13">
<image width="64" height="64" source="earthWall.png"/>
</tile>
<tile id="14">
<image width="160" height="192" source="exit.png"/>
</tile>
<tile id="15">
<image width="192" height="192" source="flare.png"/>
</tile>
<tile id="16">
<image width="64" height="64" source="gemBlueStroked.png"/>
</tile>
<tile id="17">
<image width="64" height="64" source="gemRedStroked.png"/>
</tile>
<tile id="18">
<image width="224" height="32" source="grassLarge.png"/>
</tile>
<tile id="19">
<image width="160" height="32" source="grassSmall.png"/>
</tile>
<tile id="20">
<image width="64" height="64" source="grey.png"/>
</tile>
<tile id="21">
<image width="128" height="160" source="hero.png"/>
</tile>
<tile id="22">
<image width="96" height="64" source="keyGreenStroked.png"/>
</tile>
<tile id="23">
<image width="96" height="64" source="keyRedStroked.png"/>
</tile>
<tile id="24">
<image width="96" height="64" source="keyYellowStroked.png"/>
</tile>
<tile id="25">
<image width="192" height="64" source="platform1.png"/>
</tile>
<tile id="26">
<image width="192" height="64" source="platform2.png"/>
</tile>
<tile id="27">
<image width="192" height="64" source="platform3.png"/>
</tile>
<tile id="28">
<image width="192" height="64" source="platform4.png"/>
</tile>
<tile id="29">
<image width="256" height="96" source="platformBase1.png"/>
</tile>
<tile id="30">
<image width="256" height="96" source="platformBase2.png"/>
</tile>
<tile id="31">
<image width="256" height="96" source="platformBase3.png"/>
</tile>
<tile id="32">
<image width="256" height="96" source="platformBase4.png"/>
</tile>
<tile id="33">
<image width="128" height="96" source="platformBlock1.png"/>
</tile>
<tile id="34">
<image width="128" height="96" source="platformBlock2.png"/>
</tile>
<tile id="35">
<image width="128" height="96" source="platformBlock3.png"/>
</tile>
<tile id="36">
<image width="128" height="96" source="platformBlock4.png"/>
</tile>
<tile id="37">
<image width="96" height="64" source="platformConnector1.png"/>
</tile>
<tile id="38">
<image width="96" height="64" source="platformConnector2.png"/>
</tile>
<tile id="39">
<image width="96" height="64" source="platformConnector3.png"/>
</tile>
<tile id="40">
<image width="96" height="64" source="platformConnector4.png"/>
</tile>
<tile id="41">
<image width="96" height="96" source="pushBlock1.png"/>
</tile>
<tile id="42">
<image width="96" height="96" source="pushBlock2.png"/>
</tile>
<tile id="43">
<image width="96" height="96" source="pushBlock3.png"/>
</tile>
<tile id="44">
<image width="64" height="64" source="shadow.png"/>
</tile>
<tile id="45">
<image width="93" height="93" source="shieldStroked.png"/>
</tile>
<tile id="46">
<image width="160" height="128" source="sign.png"/>
</tile>
<tile id="48">
<image width="192" height="96" source="swordStroked.png"/>
</tile>
<tile id="49">
<image width="96" height="96" source="torch.png"/>
</tile>
<tile id="50">
<image width="128" height="32" source="trap.png"/>
</tile>
<tile id="51">
<image width="128" height="96" source="wallDecor1.png"/>
</tile>
<tile id="52">
<image width="128" height="96" source="wallDecor2.png"/>
</tile>
<tile id="53">
<image width="160" height="128" source="wallDecor3.png"/>
</tile>
<tile id="54">
<image width="65" height="64" source="window1.png"/>
</tile>
<tile id="55">
<image width="64" height="64" source="window2.png"/>
</tile>
<tile id="56">
<image width="56" height="59" source="window3.png"/>
</tile>
<tile id="57">
<image width="135" height="115" source="backgroundArch.png"/>
</tile>
<tile id="58">
<image width="380" height="140" source="backgroundMountain.png"/>
</tile>
<tile id="59">
<image width="129" height="332" source="backgroundTower.png"/>
</tile>
<tile id="60">
<image width="109" height="177" source="backgroundTree.png"/>
</tile>
<tile id="61">
<image width="64" height="64" source="earthWall2.png"/>
</tile>
<tile id="62">
<image width="133" height="160" source="skeleton.png"/>
</tile>
</tileset>
<objectgroup name="background">
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="80" height="31" tilewidth="32" tileheight="32" infinite="0" backgroundcolor="#35495e" nextlayerid="9" nextobjectid="387">
<tileset firstgid="1" source="objs.tsx"/>
<objectgroup id="1" name="background">
<object id="193" gid="6" x="0" y="1184" width="1280" height="416"/>
<object id="284" gid="15" x="192" y="450" width="160" height="192"/>
<object id="287" gid="54" x="704" y="448" width="160" height="128"/>
Expand All @@ -211,7 +24,7 @@
<object id="373" gid="6" x="1792" y="1184" width="800" height="352"/>
<object id="374" gid="6" x="1152" y="1184" width="800" height="160"/>
</objectgroup>
<objectgroup name="ground">
<objectgroup id="2" name="ground">
<object id="196" gid="28" x="2120" y="416" width="192" height="64">
<properties>
<property name="bodyType" value="static"/>
Expand Down Expand Up @@ -418,7 +231,7 @@
</object>
<object id="384" type="coin" gid="18" x="1536" y="320" width="64" height="64"/>
</objectgroup>
<objectgroup name="castledeco">
<objectgroup id="3" name="castledeco">
<object id="220" gid="37" x="184" y="1016" width="128" height="96"/>
<object id="221" gid="36" x="1832" y="1024" width="128" height="96"/>
<object id="227" gid="55" x="1184" y="968" width="65" height="64"/>
Expand All @@ -434,48 +247,36 @@
<object id="369" gid="56" x="2392" y="464" width="64" height="64"/>
<object id="370" gid="56" x="272" y="624" width="64" height="64"/>
</objectgroup>
<objectgroup name="shading" opacity="0.16">
<objectgroup id="4" name="shading" opacity="0.16">
<object id="112" gid="45" x="2496" y="1184" width="456" height="1472"/>
<object id="334" gid="45" x="-384" y="1184" width="448" height="1472"/>
</objectgroup>
<objectgroup name="light" opacity="0.5">
<objectgroup id="5" name="light" opacity="0.5">
<object id="335" gid="16" x="2224" y="280" width="192" height="192"/>
<object id="336" gid="16" x="1840" y="280" width="192" height="192"/>
<object id="337" gid="16" x="1248" y="320" width="192" height="192"/>
<object id="338" gid="16" x="336" y="336" width="192" height="192"/>
<object id="339" gid="16" x="48" y="336" width="192" height="192"/>
<object id="340" gid="16" x="864" y="600" width="192" height="192"/>
</objectgroup>
<objectgroup name="game">
<object id="58" name="hero" type="hero" gid="22" x="288" y="448" width="128" height="160"/>
<object id="111" name="block" gid="44" x="2245" y="340" width="96" height="96">
<properties>
<property name="bodyType" value="dynamic"/>
<property name="density" type="float" value="2"/>
<property name="friction" type="float" value="0.45"/>
</properties>
</object>
<objectgroup id="6" name="game">
<object id="58" template="templates/hero.tx" x="288" y="448"/>
<object id="111" template="templates/block.tx" x="2245" y="340"/>
<object id="161" name="hey" type="blob" gid="3" x="464" y="768" width="96" height="64"/>
<object id="160" type="blob" gid="2" x="846" y="756" width="96" height="64"/>
<object id="189" type="enemy" gid="2147483711" x="2412" y="754" width="133" height="160"/>
<object id="190" type="coin" gid="17" x="96" y="736" width="64" height="64"/>
<object id="192" type="coin" gid="17" x="96" y="416" width="64" height="64"/>
<object id="231" name="block" gid="44" x="488" y="448" width="96" height="96">
<properties>
<property name="bodyType" value="dynamic"/>
<property name="density" type="float" value="2"/>
<property name="friction" type="float" value="0.45"/>
</properties>
</object>
<object id="231" template="templates/block.tx" x="488" y="448"/>
<object id="285" type="coin" gid="17" x="1536" y="576" width="64" height="64"/>
</objectgroup>
<objectgroup name="above">
<objectgroup id="7" name="above">
<object id="379" type="spikes" gid="51" x="1280" y="995" width="128" height="32"/>
<object id="380" type="spikes" gid="51" x="1408" y="995" width="128" height="32"/>
<object id="381" type="spikes" gid="51" x="1536" y="995" width="128" height="32"/>
<object id="382" type="spikes" gid="51" x="1664" y="995" width="128" height="32"/>
</objectgroup>
<objectgroup name="bounds" visible="0">
<objectgroup id="8" name="bounds" visible="0">
<object id="375" x="-32" y="-64" width="32" height="896">
<properties>
<property name="bodyType" value="static"/>
Expand Down
1 change: 1 addition & 0 deletions src/libtiled/mapobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,4 @@ inline void MapObject::markAsTemplateBase()

Q_DECLARE_METATYPE(Tiled::MapObject::Shape)
Q_DECLARE_METATYPE(Tiled::MapObject*)
Q_DECLARE_OPERATORS_FOR_FLAGS(Tiled::MapObject::ChangedProperties);
12 changes: 8 additions & 4 deletions src/tiled/changemapobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ ChangeMapObjectsTile::ChangeMapObjectsTile(Document *document,
// Update the size if the object's tile is valid and the sizes match
mUpdateSize.append(tile && object->size() == tile->size());

mOldChangeStates.append(object->propertyChanged(MapObject::CellProperty));
mOldChangedProperties.append(object->changedProperties());
}
}

Expand Down Expand Up @@ -154,10 +154,11 @@ void ChangeMapObjectsTile::restoreTiles()
{
for (int i = 0; i < mMapObjects.size(); ++i) {
setObjectCell(mMapObjects[i], mOldCells[i], mUpdateSize[i]);
mMapObjects[i]->setPropertyChanged(MapObject::CellProperty, mOldChangeStates[i]);
mMapObjects[i]->setChangedProperties(mOldChangedProperties[i]);
}

emit mDocument->changed(MapObjectsChangeEvent(mMapObjects, MapObject::CellProperty));
emit mDocument->changed(MapObjectsChangeEvent(mMapObjects,
MapObject::CellProperty | MapObject::SizeProperty));
}

void ChangeMapObjectsTile::changeTiles()
Expand All @@ -167,9 +168,12 @@ void ChangeMapObjectsTile::changeTiles()
cell.setTile(mTile);
setObjectCell(mMapObjects[i], cell, mUpdateSize[i]);
mMapObjects[i]->setPropertyChanged(MapObject::CellProperty);
if (mUpdateSize[i])
mMapObjects[i]->setPropertyChanged(MapObject::SizeProperty);
}

emit mDocument->changed(MapObjectsChangeEvent(mMapObjects, MapObject::CellProperty));
emit mDocument->changed(MapObjectsChangeEvent(mMapObjects,
MapObject::CellProperty | MapObject::SizeProperty));
}

DetachObjects::DetachObjects(Document *document,
Expand Down
3 changes: 1 addition & 2 deletions src/tiled/changemapobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

namespace Tiled {

class MapObject;
class ObjectTemplate;
class Tile;

Expand Down Expand Up @@ -107,7 +106,7 @@ class ChangeMapObjectsTile : public QUndoCommand
Tile * const mTile;
QVector<Cell> mOldCells;
QVector<bool> mUpdateSize;
QVector<bool> mOldChangeStates;
QVector<MapObject::ChangedProperties> mOldChangedProperties;
};

class DetachObjects : public QUndoCommand
Expand Down

0 comments on commit e96d6f7

Please sign in to comment.