Phaser.js the opposite of .putTileAtWorldXY - phaser-framework

Im trying to make a terraria/papercraft like game, and i've been using tiled for the map, and i've wanted to edit the world(break, destroy blocks) and i've looked at this tutorial
https://medium.com/#michaelwesthadley/modular-game-worlds-in-phaser-3-tilemaps-2-dynamic-platformer-3d68e73d494a
at it has the place tile, but has nothing for destroy tile, so how would i destroy tiled tile maps in phaser?
seeing some prev q's, the tile.destroy method with map name sends out bugs every time of the layer name, etc, and nothing seems to work
if anyone has a solution, or could point to a working phaser three tutorial in breaking and destroying tiled maps, please give em, im new to phaser and tiled in general.
what im working on (for context) -> https://glitch.com/edit/#!/paperambi2?path=src%2Fscenes%2FGame.js%3A77%3A21

Depending on your use case you can remove or replace single tiles or groups. check out the documentation (documenation Link replace and documenation Link remove)
Here a demo:
(this demo does not use Tiled, but it should work in the same way, just with less layers)
Demo is based on offical demo
document.body.style = 'margin:0;';
var config = {
type: Phaser.AUTO,
width: 22 * 16,
height: 11 * 16,
scene: { preload, create },
banner: false
};
function preload () {
this.load.image('mario-tiles', 'https://labs.phaser.io/assets/tilemaps/tiles/super-mario.png');
}
function create () {
this.add.text(10, 10, 'Click to remove Tile\n( Use shift to replace Tile)')
.setScale(1.25)
.setColor('black')
.setOrigin(0)
.setStyle({fontStyle: 'bold', fontFamily: 'Arial'})
.setDepth(100);
// Load a map from a 2D array of tile indices
var level = [
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], [ 0, 1, 2, 3, 0, 0, 0, 1, 2, 3, 0, 0, 1, 2, 3, 0, 0, 0, 1, 2, 3, 0, ], [ 0, 5, 6, 7, 0, 0, 0, 5, 6, 7, 0, 0, 5, 6, 7, 0, 0, 0, 5, 6, 7, 0, ], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], [ 0, 0, 0, 14, 13, 14, 0, 0, 0, 0, 0, 0, 0, 0, 14, 13, 14, 0, 0, 0, 0, 0, ], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], [ 0, 0, 14, 14, 14, 14, 14, 0, 0, 0, 15, 0, 0, 14, 14, 14, 14, 14, 0, 0, 0, 15, ], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, ], [ 35, 36, 37, 0, 0, 0, 0, 0, 15, 15, 15, 35, 36, 37, 0, 0, 0, 0, 0, 15, 15, 15, ], [ 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, ] ]
// When loading from an array, make sure to specify the tileWidth and tileHeight
var map = this.make.tilemap({ data: level, tileWidth: 16, tileHeight: 16 });
var tiles = map.addTilesetImage('mario-tiles');
var layer = map.createLayer(0, tiles, 0, 0);
var shiftKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SHIFT);
// replace tile is blue tile
const NEW_TILE_INDEX_AFTER_REMOVE = 0
this.input.on('pointerdown', function({x,y}){
// replace Tile, when shift key is pressed
if(shiftKey && shiftKey.isDown){
let selectedTile = layer.getTileAtWorldXY(x,y);
// prevent error if tile doesn't exist
if(selectedTile){
layer.replaceByIndex(selectedTile.index, NEW_TILE_INDEX_AFTER_REMOVE, selectedTile.x, selectedTile.y, 1, 1);
}
} else {
// default action remove tile
layer.removeTileAtWorldXY(x,y);
}
});
}
new Phaser.Game(config);
<script src="https://cdn.jsdelivr.net/npm/phaser#3.55.2/dist/phaser.js"></script>
You just have to check, that you don't try to replace or remove non-existent tiles, this could cause a crashes / errors, and is more frequently an issue with multilayered maps.

Related

Handling of image buffer data and display of image obtained from Mongodb database in flutter

I am working on a flutter project (club management application). I am using a node API for back-end side. I am able to save image with the rest of user-data to database using multipart file and in response I get image data of type buffer. But I'm not able to assign the image data to a variable in a User model class.
I have attached the following code and response data and error to give some context.
This is the user model class for receiving data.
class User {
String name = '';
String email = '';
String username = '';
List<dynamic> profilepic = <dynamic>[];
String token = '';
User(this.name, this.email, this.token, this.username, this.profilepic);
User.fromJson(Map<String, dynamic> json) {
User(
name = json['user']['name'],
email = json['user']['email'],
username = json['user']['username'],
profilepic = json['user']['profilepic']['data'],
token = json['token'],
);
}
}
Following function for sending and recieving user details.
upload(File imageFile, String username, String name, String email) async {
var uri = "http://192.168.0.121:3000/newuser";
String fileName = imageFile.path.split('/image_picker').last;
FormData data = FormData.fromMap({
'name': name,
'email': email,
'username': username,
"myFile": await MultipartFile.fromFile(
imageFile.path,
filename: fileName,
),
});
BaseOptions options = new BaseOptions(responseType: ResponseType.plain);
Dio dio = new Dio(options);
dio.post(uri, data: data).then((response) {
var jsonResponse = response.data;
var decoded = jsonDecode(jsonResponse);
print(decoded);
var usersigned = User.fromJson(decoded);
print(usersigned.name);
print(usersigned.username);
setState(() {});
}).catchError((error) => print(error));
}
Following is the response from the node server.
I/flutter (10733): {user: {name: Aniket Raj, email: ani99#gmail.com, username: Aniket, profilepic: {type: Buffer, data: [255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 219, 0, 67, 0, 8, 6, 6, 7, 6, 5, 8, 7, 7, 7, 9, 9, 8, 10, 12, 20, 13, 12, 11, 11, 12, 25, 18, 19, 15, 20, 29, 26, 31, 30, 29, 26, 28, 28, 32, 36, 46, 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 56, 50, 60, 46, 51, 52, 50, 255, 219, 0, 67, 1, 9, 9, 9, 12, 11, 12, 24, 13, 13, 24, 50, 33, 28, 33, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 255, 194, 0, 17, 8, 3, 222, 2, 238, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, 0, 26, 0, 1, 0, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 5, 3, 6, 255, 196, 0, 25, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 255, 218, 0, 12, 3, 1, 0, 2, 16, 3, 16, 0, 0, 2, 229, 132, 0
Following is the error recieved while saving the user photo using the user model.
I/flutter (10733): type 'List<dynamic>' is not a subtype of type 'String'
I have tried changing the photo-data type to String but to no avail. The code works without the profilepic field.
And it would be great if you could also tell me how I should render images using buffer data in flutter.
Think I was having the same problem as you.
Try this, think you will also need to change the type of your profile pic in your class to Uint8List.
profilepic: Uint8List.fromList((json['user']['profilepic']['data'] as List)
?.map((e) => e as int)
?.toList())

node.js: Convert json to array

Table I am looking to create in memory...Doing a web request to TDA API and getting a JSON formatted return on a number of strike prices for a stock/ticker. I am unable to get to the individual strike prices details which are in a json array. Below is the output I am getting:
What I am trying to accomplish is taking the data from each strike (eg: 13.5, 14.0...) and create an in-memory columnar table/array so that I can use the data to evaluate/assess potential trades/executions.
Any help would be greatly appreciated!!!
{
"symbol": "F",
"status": "SUCCESS",
"underlying": null,
"strategy": "SINGLE",
"interval": 0,
"isDelayed": true,
"isIndex": false,
"interestRate": 0.1,
"underlyingPrice": 13.08,
"volatility": 29,
"daysToExpiration": 0,
"numberOfContracts": 19,
"putExpDateMap": {},
"callExpDateMap": {
"2021-09-03:2": {
"13.5": [
{
"putCall": "CALL",
"symbol": "F_090321C13.5",
"description": "F Sep 3 2021 13.5 Call (Weekly)",
"exchangeName": "OPR",
"bid": 0.03,
"ask": 0.04,
"last": 0.04,
"mark": 0.04,
"bidSize": 207,
"askSize": 655,
"bidAskSize": "207X655",
"lastSize": 0,
"highPrice": 0.05,
"lowPrice": 0.02,
"openPrice": 0,
"closePrice": 0.03,
"totalVolume": 47477,
"tradeDate": null,
"tradeTimeInLong": 1630526399010,
"quoteTimeInLong": 1630526399727,
"netChange": 0.01,
"volatility": 35.069,
"delta": 0.169,
"gamma": 0.64,
"theta": -0.019,
"vega": 0.003,
"rho": 0,
"openInterest": 73416,
"timeValue": 0.04,
"theoreticalOptionValue": 0.035,
"theoreticalVolatility": 29,
"optionDeliverablesList": null,
"strikePrice": 13.5,
"expirationDate": 1630699200000,
"daysToExpiration": 2,
"expirationType": "S",
"lastTradingDay": 1630713600000,
"multiplier": 100,
"settlementType": " ",
"deliverableNote": "",
"isIndexOption": null,
"percentChange": 20.12,
"markChange": 0,
"markPercentChange": 5.11,
"inTheMoney": false,
"mini": false,
"nonStandard": false
}
],
"14.0": [
{
"putCall": "CALL",
"symbol": "F_090321C14",
"description": "F Sep 3 2021 14 Call (Weekly)",
"exchangeName": "OPR",
"bid": 0.01,
"ask": 0.02,
"last": 0.01,
"mark": 0.02,
"bidSize": 66,
"askSize": 1468,
"bidAskSize": "66X1468",
"lastSize": 0,
"highPrice": 0.02,
"lowPrice": 0.01,
"openPrice": 0,
"closePrice": 0.01,
"totalVolume": 3453,
"tradeDate": null,
"tradeTimeInLong": 1630526389748,
"quoteTimeInLong": 1630526395218,
"netChange": 0,
"volatility": 49.446,
"delta": 0.063,
"gamma": 0.224,
"theta": -0.013,
"vega": 0.001,
"rho": 0,
"openInterest": 31282,
"timeValue": 0.01,
"theoreticalOptionValue": 0.015,
"theoreticalVolatility": 29,
"optionDeliverablesList": null,
"strikePrice": 14,
"expirationDate": 1630699200000,
"daysToExpiration": 2,
"expirationType": "S",
"lastTradingDay": 1630713600000,
"multiplier": 100,
"settlementType": " ",
"deliverableNote": "",
"isIndexOption": null,
"percentChange": -33.33,
"markChange": 0,
"markPercentChange": 0,
"inTheMoney": false,
"mini": false,
"nonStandard": false
}
],
"14.5": [
{
"putCall": "CALL",
"symbol": "F_090321C14.5",
"description": "F Sep 3 2021 14.5 Call (Weekly)",
"exchangeName": "OPR",
"bid": 0,
"ask": 0.01,
"last": 0.01,
"mark": 0.01,
"bidSize": 0,
"askSize": 386,
"bidAskSize": "0X386",
"lastSize": 0,
"highPrice": 0.01,
"lowPrice": 0.01,
"openPrice": 0,
"closePrice": 0.01,
"totalVolume": 70,
"tradeDate": null,
"tradeTimeInLong": 1630520505930,
"quoteTimeInLong": 1630526227626,
"netChange": 0,
"volatility": 60.163,
"delta": 0.027,
"gamma": 0.092,
"theta": -0.008,
"vega": 0.001,
"rho": 0,
"openInterest": 5529,
"timeValue": 0.01,
"theoreticalOptionValue": 0.007,
"theoreticalVolatility": 29,
"optionDeliverablesList": null,
"strikePrice": 14.5,
"expirationDate": 1630699200000,
"daysToExpiration": 2,
"expirationType": "S",
"lastTradingDay": 1630713600000,
"multiplier": 100,
"settlementType": " ",
"deliverableNote": "",
"isIndexOption": null,
"percentChange": 40.85,
"markChange": 0,
"markPercentChange": -4.23,
"inTheMoney": false,
"mini": false,
"nonStandard": false
}
],
"15.0": [
{
"putCall": "CALL",
"symbol": "F_090321C15",
"description": "F Sep 3 2021 15 Call (Weekly)",
"exchangeName": "OPR",
"bid": 0,
"ask": 0.01,
"last": 0.01,
"mark": 0,
"bidSize": 0,
"askSize": 594,
"bidAskSize": "0X594",
"lastSize": 0,
"highPrice": 0.01,
"lowPrice": 0.01,
"openPrice": 0,
"closePrice": 0,
"totalVolume": 184,
"tradeDate": null,
"tradeTimeInLong": 1630524777537,
"quoteTimeInLong": 1630526370053,
"netChange": 0.01,
"volatility": 68.916,
"delta": 0.012,
"gamma": 0.041,
"theta": -0.005,
"vega": 0,
"rho": 0,
"openInterest": 4867,
"timeValue": 0.01,
"theoreticalOptionValue": 0.003,
"theoreticalVolatility": 29,
"optionDeliverablesList": null,
"strikePrice": 15,
"expirationDate": 1630699200000,
"daysToExpiration": 2,
"expirationType": "S",
"lastTradingDay": 1630713600000,
"multiplier": 100,
"settlementType": " ",
"deliverableNote": "",
"isIndexOption": null,
"percentChange": 185.71,
"markChange": 0,
"markPercentChange": -8.57,
"inTheMoney": false,
"mini": false,
"nonStandard": false
}
]
}
}
}

Vba to trigger 'pointerdown' event on an html element

Need help to trigger 'pointerdown' event on an html element as part of a webpage automation project in excel vba.
Have been able to successfully automate using 'mousedown' trigger but recently the webpage source code has been modified to use 'pointerdown' to trigger instead of 'mousedown'.
Existing 'mousedown' code:
Set e1 = IE.Document.createEvent("MouseEvent")
e1.initMouseEvent "mousedown", True, True, 0, 1, 0, 0, 0, 0, True, False, False, False, 0, Null
ElementCol.Item(i).dispatchEvent e1
Tried the following 'pointerdown' code, but excel is throwing 'Automation error' on initPointerEvent line:
Set e1 = IE.Document.createEvent("PointerEvent")
e1.initPointerEvent "pointerdown", True, True, 0, 1, 0, 0, 0, 0, False, False, False, False, 0, Null , 0, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, False
ElementCol.Item(i).dispatchEvent e1
Any help would be greatly appreciated.

Syntax to create a heat map with Highcharts

I would like to do a heat map but without 'time' and integer as X and Y axis (In fact in the example of Highcharts http://jsfiddle.net/9pJhF/ it use csv with integers and data time) but with the strings, something like that:
'Name1','A',3077
'Name2','B',5486
'Name3','A',377
'Name4','B',546
'Name5','A',77
'Name6','B',46
I would like to know how is implemented the data variable when we not use the csv or a trick to circumvent the problem with csv strings.
You can use something like this
xAxis: {
//type: 'category',
categories: ['Name1','Name2','Name3'],
tickInterval: 1,
gridLineWidth: 1,
tickLength: 0,
lineWidth: 0,
min: 0,
max: 2
},
yAxis: {
categories: ['Name1a','Name2a','Name3a'],
tickInterval: 1,
title: {
text: null
},
minPadding: 0,
maxPadding: 0,
startOnTick: false,
endOnTick: false,
tickLength: 0,
lineWidth: 0,
min: 0,
max: 2
},
http://jsfiddle.net/tZ6GP/5
http://jsfiddle.net/tZ6GP/6

Heat map with Highcharts and csv string data [duplicate]

I would like to do a heat map but without 'time' and integer as X and Y axis (In fact in the example of Highcharts http://jsfiddle.net/9pJhF/ it use csv with integers and data time) but with the strings, something like that:
'Name1','A',3077
'Name2','B',5486
'Name3','A',377
'Name4','B',546
'Name5','A',77
'Name6','B',46
I would like to know how is implemented the data variable when we not use the csv or a trick to circumvent the problem with csv strings.
You can use something like this
xAxis: {
//type: 'category',
categories: ['Name1','Name2','Name3'],
tickInterval: 1,
gridLineWidth: 1,
tickLength: 0,
lineWidth: 0,
min: 0,
max: 2
},
yAxis: {
categories: ['Name1a','Name2a','Name3a'],
tickInterval: 1,
title: {
text: null
},
minPadding: 0,
maxPadding: 0,
startOnTick: false,
endOnTick: false,
tickLength: 0,
lineWidth: 0,
min: 0,
max: 2
},
http://jsfiddle.net/tZ6GP/5
http://jsfiddle.net/tZ6GP/6

Resources