Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tilemap new weird behaviors #6957

Merged
merged 12 commits into from
Sep 17, 2024
51 changes: 34 additions & 17 deletions Extensions/TileMap/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,23 +630,38 @@ const defineSimpleTileMap = function (extension, _, gd) {

objectProperties.set(
'columnCount',
new gd.PropertyDescriptor((objectContent.columnCount || 4).toString())
new gd.PropertyDescriptor(
(typeof objectContent.columnCount === 'undefined'
? 4
: objectContent.columnCount
).toString()
)
.setType('number')
.setLabel(_('Columns'))
.setDescription(_('Number of columns.'))
.setHidden(true)
);
objectProperties.set(
'rowCount',
new gd.PropertyDescriptor((objectContent.rowCount || 4).toString())
new gd.PropertyDescriptor(
(typeof objectContent.rowCount === 'undefined'
? 4
: objectContent.rowCount
).toString()
)
.setType('number')
.setLabel(_('Rows'))
.setDescription(_('Number of rows.'))
.setHidden(true)
);
objectProperties.set(
'tileSize',
new gd.PropertyDescriptor((objectContent.tileSize || 8).toString())
new gd.PropertyDescriptor(
(typeof objectContent.tileSize === 'undefined'
? 8
: objectContent.tileSize
).toString()
)
.setType('number')
.setLabel(_('Tile size'))
.setDescription(_('Tile size in pixels.'))
Expand Down Expand Up @@ -735,7 +750,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
.addExpression(
'TilesetColumnCount',
_('Tileset column count'),
_('Get the number of column in the tileset.'),
_('Get the number of columns in the tileset.'),
'',
'JsPlatform/Extensions/tile_map.svg'
)
Expand All @@ -746,7 +761,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
.addExpression(
'TilesetRowCount',
_('Tileset row count'),
_('Get the number of row in the tileset.'),
_('Get the number of rows in the tileset.'),
'',
'JsPlatform/Extensions/tile_map.svg'
)
Expand Down Expand Up @@ -815,7 +830,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
'TileIdAtPosition',
_('Tile (at position)'),
_('the id of the tile at the scene coordinates'),
_('the tile id at scene coordinates _PARAM3_ ; _PARAM4_'),
_('the tile id in _PARAM0_ at scene coordinates _PARAM3_ ; _PARAM4_'),
'',
'JsPlatform/Extensions/tile_map.svg'
)
Expand All @@ -832,7 +847,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
_('Flip tile vertically (at position)'),
_('Flip tile vertically at scene coordinates.'),
_(
'Flip tile vertically at scene coordinates _PARAM1_ ; _PARAM2_: _PARAM3_'
'Flip tile vertically in _PARAM0_ at scene coordinates _PARAM1_ ; _PARAM2_: _PARAM3_'
),
_('Effects'),
'res/actions/flipY24.png',
Expand All @@ -851,7 +866,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
_('Flip tile horizontally (at position)'),
_('Flip tile horizontally at scene coordinates.'),
_(
'Flip tile horizontally at scene coordinates _PARAM1_ ; _PARAM2_: _PARAM3_'
'Flip tile horizontally in _PARAM0_ at scene coordinates _PARAM1_ ; _PARAM2_: _PARAM3_'
),
_('Effects'),
'res/actions/flipX24.png',
Expand All @@ -869,7 +884,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
'RemoveTileAtPosition',
_('Remove tile (at position)'),
_('Remove the tile at the scene coordinates.'),
_('Remove tile at scene coordinates _PARAM1_ ; _PARAM2_'),
_('Remove tile in _PARAM0_ at scene coordinates _PARAM1_ ; _PARAM2_'),
'',
'JsPlatform/Extensions/tile_map.svg',
'JsPlatform/Extensions/tile_map.svg'
Expand Down Expand Up @@ -903,7 +918,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
_('Flip tile vertically (on the grid)'),
_('Flip tile vertically at grid coordinates.'),
_(
'Flip tile vertically at grid coordinates _PARAM1_ ; _PARAM2_: _PARAM3_'
'Flip tile vertically in _PARAM0_ at grid coordinates _PARAM1_ ; _PARAM2_: _PARAM3_'
),
_('Effects'),
'res/actions/flipY24.png',
Expand All @@ -922,7 +937,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
_('Flip tile horizontally (on the grid)'),
_('Flip tile horizontally at grid coordinates.'),
_(
'Flip tile horizontally at grid coordinates _PARAM1_ ; _PARAM2_: _PARAM3_'
'Flip tile horizontally in _PARAM0_ at grid coordinates _PARAM1_ ; _PARAM2_: _PARAM3_'
),
_('Effects'),
'res/actions/flipX24.png',
Expand All @@ -940,7 +955,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
'RemoveTileAtGridCoordinates',
_('Remove tile (on the grid)'),
_('Remove the tile at the grid coordinates.'),
_('Remove tile at grid coordinates _PARAM1_ ; _PARAM2_'),
_('Remove tile in _PARAM0_ at grid coordinates _PARAM1_ ; _PARAM2_'),
'',
'JsPlatform/Extensions/tile_map.svg',
'JsPlatform/Extensions/tile_map.svg'
Expand All @@ -957,7 +972,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
_('Tile flipped horizontally (at position)'),
_('Check if tile at scene coordinates is flipped horizontally.'),
_(
'The tile at scene coordinates _PARAM1_ ; _PARAM2_ is flipped horizontally'
'The tile in _PARAM0_ at scene coordinates _PARAM1_ ; _PARAM2_ is flipped horizontally'
),
_('Effects'),
'res/actions/flipX24.png',
Expand All @@ -975,7 +990,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
_('Tile flipped vertically (at position)'),
_('Check if tile at scene coordinates is flipped vertically.'),
_(
'The tile at scene coordinates _PARAM1_ ; _PARAM2_ is flipped vertically'
'The tile in _PARAM0_ at scene coordinates _PARAM1_ ; _PARAM2_ is flipped vertically'
),
_('Effects'),
'res/actions/flipY24.png',
Expand All @@ -993,7 +1008,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
_('Tile flipped horizontally (on the grid)'),
_('Check if tile at grid coordinates is flipped horizontally.'),
_(
'The tile at grid coordinates _PARAM1_ ; _PARAM2_ is flipped horizontally'
'The tile in _PARAM0_ at grid coordinates _PARAM1_ ; _PARAM2_ is flipped horizontally'
),
_('Effects'),
'res/actions/flipX24.png',
Expand All @@ -1011,7 +1026,7 @@ const defineSimpleTileMap = function (extension, _, gd) {
_('Tile flipped vertically (on the grid)'),
_('Check if tile at grid coordinates is flipped vertically.'),
_(
'The tile at grid coordinates _PARAM1_ ; _PARAM2_ is flipped vertically'
'The tile in _PARAM0_ at grid coordinates _PARAM1_ ; _PARAM2_ is flipped vertically'
),
_('Effects'),
'res/actions/flipY24.png',
Expand Down Expand Up @@ -2323,7 +2338,9 @@ module.exports = {
? this._editableTileMap.isEmpty()
: false;
let objectToChange;
if (isTileMapEmpty || !atlasImageResourceName) {
if (this.errorPixiObject) {
objectToChange = this.errorPixiObject;
} else if (isTileMapEmpty || !atlasImageResourceName) {
this.tileMapPixiObject.visible = false;
this._placeholderPixiObject.visible = true;
this._placeholderTextPixiObject.text = !atlasImageResourceName
Expand Down
6 changes: 6 additions & 0 deletions Extensions/TileMap/simpletilemapruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ namespace gdjs {
tileMapLoadingCallback: (tileMap: TileMapHelper.EditableTileMap) => void
): void {
if (!this._initialTileMapAsJsObject) return;
if (this._columnCount <= 0 || this._rowCount <= 0) {
console.error(
`Tilemap object ${this.name} is not configured properly.`
);
return;
}

this._tileMapManager.getOrLoadSimpleTileMap(
this._initialTileMapAsJsObject,
Expand Down
2 changes: 2 additions & 0 deletions newIDE/app/src/CompactPropertiesEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ const CompactPropertiesEditor = ({
compactSelectField = (
<CompactSelectField
value={getFieldValue({ instances, field })}
key={field.name}
id={field.name}
onChange={(newValue: string) => {
instances.forEach(i => setValue(i, parseFloat(newValue) || 0));
Expand All @@ -640,6 +641,7 @@ const CompactPropertiesEditor = ({
field,
defaultValue: '(Multiple values)',
})}
key={field.name}
id={field.name}
onChange={(newValue: string) => {
instances.forEach(i => setValue(i, newValue || ''));
Expand Down
8 changes: 7 additions & 1 deletion newIDE/app/src/InstancesEditor/SelectedInstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import KeyboardShortcuts from '../UI/KeyboardShortcuts';
type Props = {|
instancesSelection: InstancesSelection,
instanceMeasurer: InstanceMeasurer,
shouldDisplayHandles: () => boolean,
onResize: (
deltaX: number,
deltaY: number,
Expand Down Expand Up @@ -72,6 +73,7 @@ const resizeGrabbingIconNames = {
export default class SelectedInstances {
instancesSelection: InstancesSelection;
instanceMeasurer: InstanceMeasurer;
shouldDisplayHandles: () => boolean;
onResize: (
deltaX: number,
deltaY: number,
Expand Down Expand Up @@ -105,6 +107,7 @@ export default class SelectedInstances {
constructor({
instancesSelection,
instanceMeasurer,
shouldDisplayHandles,
onResize,
onResizeEnd,
onRotate,
Expand All @@ -118,6 +121,7 @@ export default class SelectedInstances {
}: Props) {
this.instanceMeasurer = instanceMeasurer;
this.onResize = onResize;
this.shouldDisplayHandles = shouldDisplayHandles;
this.onResizeEnd = onResizeEnd;
this.onRotate = onRotate;
this.onRotateEnd = onRotateEnd;
Expand Down Expand Up @@ -303,6 +307,7 @@ export default class SelectedInstances {
buttonPadding,
hitAreaPadding,
} = getButtonSizes(this._screenType);
const displayHandle = this.shouldDisplayHandles();
const selection = this.instancesSelection.getSelectedInstances();
let x1 = 0;
let y1 = 0;
Expand Down Expand Up @@ -368,7 +373,8 @@ export default class SelectedInstances {

// If there are no unlocked instances, hide the resize buttons.
const show =
selection.filter(instance => !instance.isLocked()).length !== 0;
selection.filter(instance => !instance.isLocked()).length !== 0 &&
displayHandle;

// Position the resize buttons.
for (const grabbingLocation of resizeGrabbingLocationValues) {
Expand Down
Loading
Loading