Compare commits

...

1 Commits

Author SHA1 Message Date
Florian Rival
8674153505 Fix Tiled sprite and Panel sprites that could have a negative width or height 2021-08-27 17:35:43 +02:00
14 changed files with 650 additions and 153 deletions

View File

@@ -1,38 +1,9 @@
// @ts-check
describe('gdjs.DraggableRuntimeBehavior', function () {
var runtimeGame = new gdjs.RuntimeGame({
variables: [],
resources: { resources: [] },
// @ts-ignore
properties: { windowWidth: 800, windowHeight: 600 },
});
var runtimeScene = new gdjs.RuntimeScene(runtimeGame);
runtimeScene.loadFromScene({
layers: [
{
name: '',
visibility: true,
cameras: [],
effects: [],
ambientLightColorR: 127,
ambientLightColorB: 127,
ambientLightColorG: 127,
isLightingLayer: false,
followBaseLayerCamera: false,
},
],
variables: [],
r: 0,
v: 0,
b: 0,
mangledName: 'Scene1',
name: 'Scene1',
stopSoundsOnStartup: false,
title: '',
behaviorsSharedData: [],
objects: [],
instances: [],
});
const {
runtimeGame,
runtimeScene,
} = gdjs.makeTestRuntimeGameAndRuntimeScene();
var object = new gdjs.RuntimeObject(runtimeScene, {
name: 'obj1',

View File

@@ -114,11 +114,6 @@ namespace gdjs {
onDestroyFromScene(runtimeScene): void {
super.onDestroyFromScene(runtimeScene);
// @ts-ignore
if (this._renderer.onDestroy) {
// @ts-ignore
this._renderer.onDestroy();
}
}
update(runtimeScene: gdjs.RuntimeScene): void {
@@ -192,6 +187,7 @@ namespace gdjs {
* @param width The new width in pixels.
*/
setWidth(width: float): void {
if (width < 0) width = 0;
if (this._width === width) return;
this._width = width;
@@ -204,6 +200,7 @@ namespace gdjs {
* @param height The new height in pixels.
*/
setHeight(height: float): void {
if (height < 0) height = 0;
if (this._height === height) return;
this._height = height;

View File

@@ -0,0 +1,37 @@
// @ts-check
/**
* Basic tests for gdjs.PanelSpriteRuntimeObject
*/
describe('gdjs.PanelSpriteRuntimeObject', function () {
const { runtimeScene } = gdjs.makeTestRuntimeGameAndRuntimeScene();
it('should handle scaling properly', function () {
const object = new gdjs.PanelSpriteRuntimeObject(runtimeScene, {
name: 'obj1',
type: '',
variables: [],
behaviors: [],
effects: [],
rightMargin: 10,
leftMargin: 10,
topMargin: 10,
bottomMargin: 10,
tiled: true,
width: 100,
height: 200,
texture: '',
});
expect(object.getWidth()).to.be(100);
expect(object.getHeight()).to.be(200);
object.setWidth(50);
object.setHeight(75);
expect(object.getWidth()).to.be(50);
expect(object.getHeight()).to.be(75);
object.setWidth(-20);
object.setHeight(-100);
expect(object.getWidth()).to.be(0);
expect(object.getHeight()).to.be(0);
});
});

View File

@@ -5,40 +5,7 @@ describe('gdjs.PathfindingRuntimeBehavior', function () {
const pathFindingName = 'auto1';
const createScene = () => {
const runtimeGame = new gdjs.RuntimeGame({
variables: [],
// @ts-ignore - missing properties.
properties: { windowWidth: 800, windowHeight: 600 },
resources: { resources: [] },
});
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
runtimeScene.loadFromScene({
layers: [
{
name: '',
visibility: true,
effects: [],
cameras: [],
ambientLightColorR: 0,
ambientLightColorG: 0,
ambientLightColorB: 0,
isLightingLayer: false,
followBaseLayerCamera: true,
},
],
variables: [],
r: 0,
v: 0,
b: 0,
mangledName: 'Scene1',
name: 'Scene1',
stopSoundsOnStartup: false,
title: '',
behaviorsSharedData: [],
objects: [],
instances: [],
});
const { runtimeScene } = gdjs.makeTestRuntimeGameAndRuntimeScene();
runtimeScene._timeManager.getElapsedTime = function () {
return (1 / 60) * 1000;
};

View File

@@ -9,40 +9,7 @@ describe('gdjs.PathfindingRuntimeBehavior', function () {
const pathFindingName = 'auto1';
let createScene = () => {
const runtimeGame = new gdjs.RuntimeGame({
variables: [],
// @ts-ignore - missing properties.
properties: { windowWidth: 800, windowHeight: 600 },
resources: { resources: [] },
});
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
runtimeScene.loadFromScene({
layers: [
{
name: '',
visibility: true,
effects: [],
cameras: [],
ambientLightColorR: 0,
ambientLightColorG: 0,
ambientLightColorB: 0,
isLightingLayer: false,
followBaseLayerCamera: true,
},
],
variables: [],
r: 0,
v: 0,
b: 0,
mangledName: 'Scene1',
name: 'Scene1',
stopSoundsOnStartup: false,
title: '',
behaviorsSharedData: [],
objects: [],
instances: [],
});
const { runtimeScene } = gdjs.makeTestRuntimeGameAndRuntimeScene();
runtimeScene._timeManager.getElapsedTime = function () {
return (1 / 60) * 1000;
};

View File

@@ -0,0 +1,32 @@
// @ts-check
/**
* Basic tests for gdjs.PanelSpriteRuntimeObject
*/
describe('gdjs.PanelSpriteRuntimeObject', function () {
const { runtimeScene } = gdjs.makeTestRuntimeGameAndRuntimeScene();
it('should handle scaling properly', function () {
const object = new gdjs.TiledSpriteRuntimeObject(runtimeScene, {
name: 'obj1',
type: '',
variables: [],
behaviors: [],
effects: [],
width: 100,
height: 200,
texture: '',
});
expect(object.getWidth()).to.be(100);
expect(object.getHeight()).to.be(200);
object.setWidth(50);
object.setHeight(75);
expect(object.getWidth()).to.be(50);
expect(object.getHeight()).to.be(75);
object.setWidth(-20);
object.setHeight(-100);
expect(object.getWidth()).to.be(0);
expect(object.getHeight()).to.be(0);
});
});

View File

@@ -143,6 +143,7 @@ namespace gdjs {
* @param width The new width.
*/
setWidth(width: float): void {
if (width < 0) width = 0;
if (this._width === width) return;
this._width = width;
@@ -155,6 +156,7 @@ namespace gdjs {
* @param height The new height.
*/
setHeight(height: float): void {
if (height < 0) height = 0;
if (this._height === height) return;
this._height = height;

View File

@@ -3,40 +3,7 @@ describe('gdjs.TopDownMovementRuntimeBehavior', function () {
const topDownName = 'auto1';
const createScene = () => {
const runtimeGame = new gdjs.RuntimeGame({
variables: [],
// @ts-ignore - missing properties.
properties: { windowWidth: 800, windowHeight: 600 },
resources: { resources: [] },
});
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
runtimeScene.loadFromScene({
layers: [
{
name: '',
visibility: true,
effects: [],
cameras: [],
ambientLightColorR: 0,
ambientLightColorG: 0,
ambientLightColorB: 0,
isLightingLayer: false,
followBaseLayerCamera: true,
},
],
variables: [],
r: 0,
v: 0,
b: 0,
mangledName: 'Scene1',
name: 'Scene1',
stopSoundsOnStartup: false,
title: '',
behaviorsSharedData: [],
objects: [],
instances: [],
});
const { runtimeScene } = gdjs.makeTestRuntimeGameAndRuntimeScene();
runtimeScene._timeManager.getElapsedTime = function () {
return (1 / 60) * 1000;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 B

View File

@@ -0,0 +1,461 @@
{
"firstLayout": "",
"gdVersion": {
"build": 99,
"major": 4,
"minor": 0,
"revision": 0
},
"properties": {
"adaptGameResolutionAtRuntime": true,
"folderProject": false,
"orientation": "landscape",
"packageName": "com.example.gamename",
"pixelsRounding": false,
"projectUuid": "0fdd8671-119f-4cd0-aa1c-c786298685de",
"scaleMode": "linear",
"sizeOnStartupMode": "adaptWidth",
"useExternalSourceFiles": false,
"version": "1.0.0",
"name": "Project",
"author": "",
"windowWidth": 800,
"windowHeight": 600,
"latestCompilationDirectory": "",
"maxFPS": 60,
"minFPS": 20,
"verticalSync": false,
"platformSpecificAssets": {},
"loadingScreen": {
"backgroundColor": 0,
"backgroundFadeInDuration": 0.2,
"backgroundImageResourceName": "",
"gdevelopLogoStyle": "light",
"logoAndProgressFadeInDuration": 0.2,
"logoAndProgressLogoFadeInDelay": 0.2,
"minDuration": 1.5,
"progressBarColor": 16777215,
"progressBarHeight": 20,
"progressBarMaxWidth": 200,
"progressBarMinWidth": 40,
"progressBarWidthPercent": 30,
"showGDevelopSplash": true,
"showProgressBar": true
},
"extensionProperties": [],
"platforms": [
{
"name": "GDevelop JS platform"
}
],
"currentPlatform": "GDevelop JS platform"
},
"resources": {
"resources": [
{
"alwaysLoaded": false,
"file": "assets/Orange strip block (2).png",
"kind": "image",
"metadata": "",
"name": "Orange strip block (2).png",
"smoothed": true,
"userAdded": false,
"origin": {
"identifier": "https://resources.gdevelop-app.com/assets/Industrial Platformer Pack (110 assets)/PNG/Retina/Orange strip block (2).png",
"name": "gdevelop-asset-store"
}
}
],
"resourceFolders": []
},
"objects": [],
"objectsGroups": [],
"variables": [],
"layouts": [
{
"b": 52,
"disableInputWhenNotFocused": true,
"mangledName": "New_32scene",
"name": "New scene",
"oglFOV": 90,
"oglZFar": 500,
"oglZNear": 1,
"r": 128,
"standardSortMethod": true,
"stopSoundsOnStartup": true,
"title": "",
"v": 52,
"uiSettings": {
"grid": false,
"gridType": "rectangular",
"gridWidth": 32,
"gridHeight": 32,
"gridOffsetX": 0,
"gridOffsetY": 0,
"gridColor": 10401023,
"gridAlpha": 0.8,
"snap": false,
"zoomFactor": 0.5445999999999995,
"windowMask": false
},
"objectsGroups": [],
"variables": [],
"instances": [
{
"angle": 0,
"customSize": false,
"height": 0,
"layer": "",
"locked": false,
"name": "Sprite",
"persistentUuid": "a2a729c4-c272-46c5-b9fb-af2de83caf16",
"width": 0,
"x": 161,
"y": 5,
"zOrder": 1,
"numberProperties": [],
"stringProperties": [],
"initialVariables": []
},
{
"angle": 0,
"customSize": true,
"height": 107,
"layer": "",
"locked": false,
"name": "TiledSprite",
"persistentUuid": "c6cd7472-4bc1-4b40-bf71-e4770118d461",
"width": 284,
"x": 161,
"y": 162,
"zOrder": 2,
"numberProperties": [],
"stringProperties": [],
"initialVariables": []
},
{
"angle": 0,
"customSize": true,
"height": 121,
"layer": "",
"locked": false,
"name": "PanelSprite",
"persistentUuid": "827d88c8-5be2-434b-aced-b70718cdfcf5",
"width": 286,
"x": 163,
"y": 277,
"zOrder": 3,
"numberProperties": [],
"stringProperties": [],
"initialVariables": []
},
{
"angle": 0,
"customSize": false,
"height": 0,
"layer": "",
"locked": false,
"name": "NewObject3",
"persistentUuid": "185b7fa0-a88a-4e31-87ed-a05af9475dec",
"width": 0,
"x": 164,
"y": 412,
"zOrder": 4,
"numberProperties": [],
"stringProperties": [],
"initialVariables": []
},
{
"angle": 0,
"customSize": false,
"height": 0,
"layer": "",
"locked": false,
"name": "NewObject4",
"persistentUuid": "f30ef166-3ec0-4a2d-8bdb-c8cd71667c2b",
"width": 0,
"x": 152,
"y": 443,
"zOrder": 5,
"numberProperties": [],
"stringProperties": [],
"initialVariables": []
},
{
"angle": 0,
"customSize": false,
"height": 0,
"layer": "",
"locked": false,
"name": "NewObject5",
"persistentUuid": "b8a6efd6-dfad-4e98-adc3-3340bdb3e89d",
"width": 0,
"x": 158,
"y": 541,
"zOrder": 6,
"numberProperties": [],
"stringProperties": [],
"initialVariables": []
}
],
"objects": [
{
"name": "Sprite",
"tags": "",
"type": "Sprite",
"updateIfNotVisible": false,
"variables": [],
"effects": [],
"behaviors": [],
"animations": [
{
"name": "",
"useMultipleDirections": false,
"directions": [
{
"looping": true,
"timeBetweenFrames": 0.02500000037252903,
"sprites": [
{
"hasCustomCollisionMask": false,
"image": "Orange strip block (2).png",
"points": [],
"originPoint": {
"name": "origine",
"x": 0,
"y": 0
},
"centerPoint": {
"automatic": true,
"name": "centre",
"x": 0,
"y": 0
},
"customCollisionMask": []
}
]
}
]
}
]
},
{
"height": 32,
"name": "TiledSprite",
"tags": "",
"texture": "Orange strip block (2).png",
"type": "TiledSpriteObject::TiledSprite",
"width": 32,
"variables": [],
"effects": [],
"behaviors": []
},
{
"bottomMargin": 10,
"height": 32,
"leftMargin": 10,
"name": "PanelSprite",
"rightMargin": 10,
"tags": "",
"texture": "Orange strip block (2).png",
"tiled": true,
"topMargin": 10,
"type": "PanelSpriteObject::PanelSprite",
"width": 32,
"variables": [],
"effects": [],
"behaviors": []
},
{
"bold": false,
"italic": false,
"name": "NewObject3",
"smoothed": true,
"tags": "",
"type": "TextObject::Text",
"underlined": false,
"variables": [],
"effects": [],
"behaviors": [],
"string": "Text",
"font": "",
"characterSize": 20,
"color": {
"b": 0,
"g": 0,
"r": 0
}
},
{
"name": "NewObject4",
"tags": "",
"type": "BBText::BBText",
"variables": [],
"effects": [],
"behaviors": [],
"content": {
"text": "[b]bold[/b] [i]italic[/i] [size=15]smaller[/size] [font=times]times[/font] font\n[spacing=12]spaced out[/spacing]\n[outline=yellow]outlined[/outline] [shadow=red]DropShadow[/shadow] ",
"opacity": 255,
"fontSize": 20,
"visible": true,
"color": "#000000",
"fontFamily": "Arial",
"align": "left",
"wordWrap": true
}
},
{
"name": "NewObject5",
"tags": "",
"type": "BitmapText::BitmapTextObject",
"variables": [],
"effects": [],
"behaviors": [],
"content": {
"text": "This text use the default bitmap font.\nUse a custom Bitmap Font to create your own texts.",
"opacity": 255,
"scale": 1,
"fontSize": 20,
"tint": "#ffffff",
"bitmapFontResourceName": "",
"textureAtlasResourceName": "",
"align": "left",
"wordWrap": true
}
}
],
"events": [
{
"disabled": false,
"folded": false,
"type": "BuiltinCommonInstructions::Standard",
"conditions": [],
"actions": [
{
"type": {
"inverted": false,
"value": "ChangeWidth"
},
"parameters": [
"Sprite",
"=",
"sin(TimeFromStart()*2)*200"
],
"subInstructions": []
},
{
"type": {
"inverted": false,
"value": "TiledSpriteObject::Width"
},
"parameters": [
"TiledSprite",
"=",
"sin(TimeFromStart()*2)*200"
],
"subInstructions": []
},
{
"type": {
"inverted": false,
"value": "PanelSpriteObject::Width"
},
"parameters": [
"PanelSprite",
"=",
"sin(TimeFromStart()*2)*200"
],
"subInstructions": []
},
{
"type": {
"inverted": false,
"value": "TextObject::WrappingWidth"
},
"parameters": [
"NewObject3",
"=",
"sin(TimeFromStart()*2)*200"
],
"subInstructions": []
},
{
"type": {
"inverted": false,
"value": "BBText::SetWrappingWidth"
},
"parameters": [
"NewObject4",
"=",
"sin(TimeFromStart()*2)*200"
],
"subInstructions": []
},
{
"type": {
"inverted": false,
"value": "BitmapText::BitmapTextObject::SetWrappingWidth"
},
"parameters": [
"NewObject5",
"=",
"sin(TimeFromStart()*2)*200"
],
"subInstructions": []
}
],
"events": []
},
{
"disabled": false,
"folded": false,
"type": "BuiltinCommonInstructions::Standard",
"conditions": [],
"actions": [
{
"type": {
"inverted": false,
"value": "TextObject::SetWrapping"
},
"parameters": [
"NewObject3",
"yes"
],
"subInstructions": []
}
],
"events": []
}
],
"layers": [
{
"ambientLightColorB": 32,
"ambientLightColorG": 0,
"ambientLightColorR": 0,
"followBaseLayerCamera": false,
"isLightingLayer": false,
"name": "",
"visibility": true,
"cameras": [
{
"defaultSize": true,
"defaultViewport": true,
"height": 0,
"viewportBottom": 1,
"viewportLeft": 0,
"viewportRight": 1,
"viewportTop": 0,
"width": 0
}
],
"effects": []
}
],
"behaviorsSharedData": []
}
],
"externalEvents": [],
"eventsFunctionsExtensions": [],
"externalLayouts": [],
"externalSourceFiles": []
}

View File

@@ -78,11 +78,16 @@ module.exports = function (config) {
'../../newIDE/app/resources/GDJS/Runtime/Extensions/Firebase/B_firebasetools/*.js',
'../../newIDE/app/resources/GDJS/Runtime/Extensions/Effects/kawase-blur-pixi-filter.js',
'../../newIDE/app/resources/GDJS/Runtime/Extensions/Effects/pixi-filters/filter-kawase-blur.js',
'../../newIDE/app/resources/GDJS/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject.js',
'../../newIDE/app/resources/GDJS/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject-pixi-renderer.js',
'../../newIDE/app/resources/GDJS/Runtime/Extensions/TiledSpriteObject/tiledspriteruntimeobject.js',
'../../newIDE/app/resources/GDJS/Runtime/Extensions/TiledSpriteObject/tiledspriteruntimeobject-pixi-renderer.js',
// Test extensions:
'./tests/Extensions/**.js',
//All tests files:
'./tests-utils/init.js',
'./tests-utils/init.pixiruntimegamewithassets.js',
// Assets

View File

@@ -0,0 +1,102 @@
// @ts-check
/**
* Create and return a game and scene to be used for tests.
* @returns {{runtimeGame: gdjs.RuntimeGame, runtimeScene: gdjs.RuntimeScene}}
*/
gdjs.makeTestRuntimeGameAndRuntimeScene = () => {
const runtimeGame = new gdjs.RuntimeGame({
variables: [],
properties: {
adaptGameResolutionAtRuntime: true,
folderProject: false,
orientation: 'landscape',
packageName: 'com.gdevelop.integrationtest',
projectFile: '',
scaleMode: 'linear',
pixelsRounding: false,
sizeOnStartupMode: 'adaptWidth',
useExternalSourceFiles: true,
version: '1.0.0',
name: 'Test game with real assets',
author: '',
windowWidth: 800,
windowHeight: 600,
latestCompilationDirectory: '',
maxFPS: 60,
minFPS: 20,
verticalSync: true,
loadingScreen: {
showGDevelopSplash: true,
backgroundImageResourceName: '',
backgroundColor: 0,
backgroundFadeInDuration: 0.2,
minDuration: 0,
logoAndProgressFadeInDuration: 0.2,
logoAndProgressLogoFadeInDelay: 0.2,
showProgressBar: true,
progressBarMinWidth: 40,
progressBarMaxWidth: 300,
progressBarWidthPercent: 40,
progressBarHeight: 20,
progressBarColor: 0xFFFFFF,
},
currentPlatform: '',
extensionProperties: [],
},
firstLayout: '',
gdVersion: {
major: 5,
minor: 0,
build: 0,
revision: 0,
},
objects: [],
layouts: [],
externalLayouts: [],
resources: {
resources: [
{
kind: 'image',
name: 'base/tests-utils/assets/64x64.jpg',
metadata: '',
file: 'base/tests-utils/assets/64x64.jpg',
userAdded: true,
},
],
},
});
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
runtimeScene.loadFromScene({
layers: [
{
name: '',
visibility: true,
effects: [],
cameras: [],
ambientLightColorR: 0,
ambientLightColorG: 0,
ambientLightColorB: 0,
isLightingLayer: false,
followBaseLayerCamera: true,
},
],
variables: [],
r: 0,
v: 0,
b: 0,
mangledName: 'Scene1',
name: 'Scene1',
stopSoundsOnStartup: false,
title: '',
behaviorsSharedData: [],
objects: [],
instances: [],
});
return {
runtimeGame,
runtimeScene
}
};

View File

@@ -1,12 +1,7 @@
// @ts-check
describe('gdjs.EffectsManager', () => {
const runtimeGame = new gdjs.RuntimeGame({
variables: [],
// @ts-ignore TODO: make a function to create an empty game and use it across tests.
properties: { windowWidth: 800, windowHeight: 600 },
resources: { resources: [] },
});
const { runtimeGame } = gdjs.makeTestRuntimeGameAndRuntimeScene();
it('can add effects on a runtime object', () => {
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);

View File

@@ -5,13 +5,7 @@
*/
describe('gdjs.RuntimeObject', () => {
const runtimeGame = new gdjs.RuntimeGame({
variables: [],
// @ts-ignore TODO: make a function to create an empty game and use it across tests.
properties: { windowWidth: 800, windowHeight: 600 },
resources: { resources: [] },
});
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
const { runtimeScene } = gdjs.makeTestRuntimeGameAndRuntimeScene();
it('should compute distances properly', () => {
const object = new gdjs.TestRuntimeObject(runtimeScene, {