mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +09:00
remoteMap animated belts (yellows are bugged)
This commit is contained in:
1 parent
0b07698b78
commit
dc62e714d6
4 files changed
+101
-33
No files matched your search
@@ -55,11 +55,11 @@ class remoteMap {
|
|||||||
this.socket.on("placeEntity", req => {
|
this.socket.on("placeEntity", req => {
|
||||||
// game.player.surface.create_entity{name="small-ship-wreck", position={game.player.position.x-2, game.player.position.y+1}, direction=..., force=...}
|
// game.player.surface.create_entity{name="small-ship-wreck", position={game.player.position.x-2, game.player.position.y+1}, direction=..., force=...}
|
||||||
console.log("placing "+JSON.stringify(req));
|
console.log("placing "+JSON.stringify(req));
|
||||||
if(req.name && typeof req.name == "string" && req.position && Number(req.position.x) && Number(req.position.y)){
|
if(req.name && typeof req.name == "string" && req.position && !isNaN(Number(req.position.x)) && !isNaN(Number(req.position.y))){
|
||||||
if(req.name == "deleted"){ // {{'+req.position.x+','+req.position.y+'},{'+req.position.x+','+req.position.y+'}}
|
if(req.name == "deleted"){ // {{'+req.position.x+','+req.position.y+'},{'+req.position.x+','+req.position.y+'}}
|
||||||
this.messageInterface('/silent-command local toDelete = game.surfaces[1].find_entities({{'+req.position.x+','+req.position.y+'},{'+(req.position.x+1)+','+(req.position.y+1)+'}}) for i, entity in pairs(toDelete) do entity.die() end');
|
this.messageInterface('/silent-command local toDelete = game.surfaces[1].find_entities({{'+req.position.x+','+req.position.y+'},{'+(req.position.x+1)+','+(req.position.y+1)+'}}) for i, entity in pairs(toDelete) do entity.die() end');
|
||||||
// this position is now empty, delete whatever was there from DB
|
// this position is now empty, delete whatever was there from DB
|
||||||
// this.deleteEntity(req.position.x, req.position.y);
|
this.deleteEntity(req.position.x, req.position.y);
|
||||||
} else {
|
} else {
|
||||||
let command = '/silent-command game.surfaces[1].create_entity{name="'+req.name+'", position={'+Number(req.position.x)+', '+Number(req.position.y)+'}, force="neutral"'
|
let command = '/silent-command game.surfaces[1].create_entity{name="'+req.name+'", position={'+Number(req.position.x)+', '+Number(req.position.y)+'}, force="neutral"'
|
||||||
if(req.direction) command += ', direction='+req.direction;
|
if(req.direction) command += ', direction='+req.direction;
|
||||||
|
|||||||
@@ -231,14 +231,33 @@ entityDrawRules["chemical-plant"] = {
|
|||||||
|
|
||||||
["transport-belt", "fast-transport-belt", "express-transport-belt"].forEach(name => {
|
["transport-belt", "fast-transport-belt", "express-transport-belt"].forEach(name => {
|
||||||
entityDrawRules[name] = {
|
entityDrawRules[name] = {
|
||||||
rotOffset: 270,
|
spritesheet: [{
|
||||||
spritesheet: spritesheetJson.frames["images/factorio/entity/"+name+"/"+name+".png.10"],
|
spritesheet: [ // vertical belts
|
||||||
sizeInTiles: {
|
// spritesheetJson.frames["images/factorio/entity/"+name+"/"+name+".png.0"], // 0 to 31
|
||||||
x:1.2,y:1.6,
|
],
|
||||||
},
|
sizeInTiles: {
|
||||||
positionOffset: {
|
x:1.2,y:1.4,
|
||||||
x:0,y:-0.2,
|
},
|
||||||
}
|
positionOffset: {
|
||||||
|
x:-0.1,y:-0,
|
||||||
|
}
|
||||||
|
},{
|
||||||
|
spritesheet: [ // horizontal belts
|
||||||
|
// spritesheetJson.frames["images/factorio/entity/"+name+"/"+name+".png.27"], // 32 to 63
|
||||||
|
],
|
||||||
|
sizeInTiles: {
|
||||||
|
x:1.3,y:1.6,
|
||||||
|
},
|
||||||
|
positionOffset: {
|
||||||
|
x:-0.15,y:-0.25,
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
for(let i = 0; i < 32; i++){
|
||||||
|
// up
|
||||||
|
entityDrawRules[name].spritesheet[1].spritesheet.push(spritesheetJson.frames["images/factorio/entity/"+name+"/"+name+".png."+i]);
|
||||||
|
// right
|
||||||
|
entityDrawRules[name].spritesheet[0].spritesheet.push(spritesheetJson.frames["images/factorio/entity/"+name+"/"+name+".png."+(i+32)]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
["splitter", "fast-splitter", "express-splitter"].forEach(splitter => {
|
["splitter", "fast-splitter", "express-splitter"].forEach(splitter => {
|
||||||
@@ -266,8 +285,7 @@ entityDrawRules["oil-refinery"] = {
|
|||||||
spritesheet: spritesheetJson.frames["images/factorio/entity/oil-refinery/oil-refinery.png.2"],
|
spritesheet: spritesheetJson.frames["images/factorio/entity/oil-refinery/oil-refinery.png.2"],
|
||||||
}, {
|
}, {
|
||||||
spritesheet: spritesheetJson.frames["images/factorio/entity/oil-refinery/oil-refinery.png.3"],
|
spritesheet: spritesheetJson.frames["images/factorio/entity/oil-refinery/oil-refinery.png.3"],
|
||||||
}
|
}],
|
||||||
],
|
|
||||||
}
|
}
|
||||||
// correct image size for the oil refinery frames (same for all of them on this one)
|
// correct image size for the oil refinery frames (same for all of them on this one)
|
||||||
entityDrawRules["oil-refinery"].spritesheet.forEach(object => {
|
entityDrawRules["oil-refinery"].spritesheet.forEach(object => {
|
||||||
|
|||||||
+10
-1
@@ -9,11 +9,20 @@ export function getParameterByName(name, url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ctx, entityImages[name].img, xPos, yPos, size.x, size.y, rotation, sprWidth, sprHeight, offLeft, offTop
|
// ctx, entityImages[name].img, xPos, yPos, size.x, size.y, rotation, sprWidth, sprHeight, offLeft, offTop
|
||||||
export function drawImageWithRotation(ctx, image, x, y, w, h, degrees, sprWidth, sprHeight, offLeft, offTop){
|
export function drawImageWithRotation(ctx, image, x, y, w, h, degrees, sprWidth, sprHeight, offLeft, offTop, flipX, flipY){
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.translate(x+w/2, y+h/2);
|
ctx.translate(x+w/2, y+h/2);
|
||||||
ctx.rotate(degrees*Math.PI/180.0);
|
ctx.rotate(degrees*Math.PI/180.0);
|
||||||
ctx.translate(-x-w/2, -y-h/2);
|
ctx.translate(-x-w/2, -y-h/2);
|
||||||
|
if(flipX) {
|
||||||
|
x -= x*2+sprWidth;
|
||||||
|
ctx.scale(-1, 1);
|
||||||
|
}
|
||||||
|
if(flipY){
|
||||||
|
y -= y*2+sprHeight;
|
||||||
|
ctx.scale(1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
if(sprWidth != undefined && sprHeight != undefined && offLeft != undefined && offTop != undefined){
|
if(sprWidth != undefined && sprHeight != undefined && offLeft != undefined && offTop != undefined){
|
||||||
// console.log(sprWidth+" "+sprHeight+" "+offLeft+" "+offTop+" "+w+" "+h)
|
// console.log(sprWidth+" "+sprHeight+" "+offLeft+" "+offTop+" "+w+" "+h)
|
||||||
ctx.drawImage(image, offLeft, offTop, sprWidth, sprHeight, x, y, w, h);
|
ctx.drawImage(image, offLeft, offTop, sprWidth, sprHeight, x, y, w, h);
|
||||||
|
|||||||
+61
-20
@@ -372,7 +372,7 @@ function renderLoop(){
|
|||||||
if(mousePosition && mousePosition.x){
|
if(mousePosition && mousePosition.x){
|
||||||
// make a box around the mouse cursor
|
// make a box around the mouse cursor
|
||||||
selectionCtx.beginPath();
|
selectionCtx.beginPath();
|
||||||
selectionCtx.lineWidth = remoteMapConfig.tileSize / 8;
|
selectionCtx.lineWidth = remoteMapConfig.tileSize / 16;
|
||||||
selectionCtx.strokeStyle="yellow";
|
selectionCtx.strokeStyle="yellow";
|
||||||
if(mousePosition.clicked) selectionCtx.strokeStyle = "red";
|
if(mousePosition.clicked) selectionCtx.strokeStyle = "red";
|
||||||
if(mousePosition.rightClicked) selectionCtx.strokeStyle = "blue";
|
if(mousePosition.rightClicked) selectionCtx.strokeStyle = "blue";
|
||||||
@@ -415,7 +415,8 @@ function drawEntity(entity, dontCache){
|
|||||||
entityImages[name].draw = function(entity){
|
entityImages[name].draw = function(entity){
|
||||||
if(this.loaded){
|
if(this.loaded){
|
||||||
let name = entity.entity.name;
|
let name = entity.entity.name;
|
||||||
let image, sprWidth, sprHeight, offLeft, offTop, size, offsetX, offsetY
|
let image, sprWidth, sprHeight, offLeft, offTop, size, offsetX, offsetY;
|
||||||
|
let flipX = false, flipY = false;
|
||||||
let rotation = 0;
|
let rotation = 0;
|
||||||
// check hardcoded entity draw rules for specifics (otherwise draw icon as 1x1 entity with rotation if specified)
|
// check hardcoded entity draw rules for specifics (otherwise draw icon as 1x1 entity with rotation if specified)
|
||||||
if(entityDrawRules[name] && (entityDrawRules[name].positionOffset || entityDrawRules[name].spritesheet)){
|
if(entityDrawRules[name] && (entityDrawRules[name].positionOffset || entityDrawRules[name].spritesheet)){
|
||||||
@@ -431,24 +432,63 @@ function drawEntity(entity, dontCache){
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if(rules.spritesheet && Array.isArray(rules.spritesheet)){
|
if(rules.spritesheet && Array.isArray(rules.spritesheet)){
|
||||||
let dir = Number(entity.entity.rot);
|
let dir = Number(entity.entity.rot || 0);
|
||||||
// correct for whether we have 4 or 8 directions
|
// 2 animated sprites, we will need to flip it for rotations.
|
||||||
let spriteSheetRotIndex = dir / (8 / rules.spritesheet.length);
|
if(rules.spritesheet.length == 2){
|
||||||
|
let spritesheetAnim = dir / 2 % 2;
|
||||||
|
let animationStage = Math.floor(Date.now()/16) % rules.spritesheet[spritesheetAnim].spritesheet.length;
|
||||||
|
|
||||||
sprWidth = rules.spritesheet[spriteSheetRotIndex].spritesheet.frame.w;
|
try{
|
||||||
sprHeight = rules.spritesheet[spriteSheetRotIndex].spritesheet.frame.h;
|
sprWidth = rules.spritesheet[spritesheetAnim].spritesheet[animationStage].frame.w;
|
||||||
offLeft = rules.spritesheet[spriteSheetRotIndex].spritesheet.frame.x;
|
sprHeight = rules.spritesheet[spritesheetAnim].spritesheet[animationStage].frame.h;
|
||||||
offTop = rules.spritesheet[spriteSheetRotIndex].spritesheet.frame.y;
|
offLeft = rules.spritesheet[spritesheetAnim].spritesheet[animationStage].frame.x;
|
||||||
image = global.spritesheet;
|
offTop = rules.spritesheet[spritesheetAnim].spritesheet[animationStage].frame.y;
|
||||||
if(rules.spritesheet[spriteSheetRotIndex].positionOffset){
|
} catch(e){
|
||||||
offsetX = rules.spritesheet[spriteSheetRotIndex].positionOffset.x;
|
// console.log(name)
|
||||||
offsetY = rules.spritesheet[spriteSheetRotIndex].positionOffset.y;
|
// console.log(rules.spritesheet[spritesheetAnim].spritesheet)
|
||||||
}
|
}
|
||||||
if(rules.spritesheet[spriteSheetRotIndex].sizeInTiles){
|
image = global.spritesheet;
|
||||||
size = {
|
|
||||||
x: remoteMapConfig.tileSize * rules.spritesheet[dir/2].sizeInTiles.x,
|
// handle rotation (not handled by generic handler because we have to do flips and special stuff)
|
||||||
y: remoteMapConfig.tileSize * rules.spritesheet[dir/2].sizeInTiles.y,
|
if(dir == 4){
|
||||||
};
|
// rotation = (dir/2)*90
|
||||||
|
// console.log("rotating")
|
||||||
|
flipY = true;
|
||||||
|
} else if(dir == 6){
|
||||||
|
flipX = true;
|
||||||
|
// rotation = ((dir+2)/2)*90+180 // this formula is terrible, don't try to repair, there is no sense to it
|
||||||
|
}
|
||||||
|
|
||||||
|
if(rules.spritesheet[spritesheetAnim].positionOffset){
|
||||||
|
offsetX = rules.spritesheet[spritesheetAnim].positionOffset.x;
|
||||||
|
offsetY = rules.spritesheet[spritesheetAnim].positionOffset.y;
|
||||||
|
}
|
||||||
|
if(rules.spritesheet[spritesheetAnim].sizeInTiles){
|
||||||
|
size = {
|
||||||
|
x: remoteMapConfig.tileSize * rules.spritesheet[spritesheetAnim].sizeInTiles.x,
|
||||||
|
y: remoteMapConfig.tileSize * rules.spritesheet[spritesheetAnim].sizeInTiles.y,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// correct for whether we have 4 or 8 directions
|
||||||
|
let spriteSheetRotIndex = dir / (8 / rules.spritesheet.length);
|
||||||
|
|
||||||
|
sprWidth = rules.spritesheet[spriteSheetRotIndex].spritesheet.frame.w;
|
||||||
|
sprHeight = rules.spritesheet[spriteSheetRotIndex].spritesheet.frame.h;
|
||||||
|
offLeft = rules.spritesheet[spriteSheetRotIndex].spritesheet.frame.x;
|
||||||
|
offTop = rules.spritesheet[spriteSheetRotIndex].spritesheet.frame.y;
|
||||||
|
image = global.spritesheet;
|
||||||
|
|
||||||
|
if(rules.spritesheet[spriteSheetRotIndex].positionOffset){
|
||||||
|
offsetX = rules.spritesheet[spriteSheetRotIndex].positionOffset.x;
|
||||||
|
offsetY = rules.spritesheet[spriteSheetRotIndex].positionOffset.y;
|
||||||
|
}
|
||||||
|
if(rules.spritesheet[spriteSheetRotIndex].sizeInTiles){
|
||||||
|
size = {
|
||||||
|
x: remoteMapConfig.tileSize * rules.spritesheet[spriteSheetRotIndex].sizeInTiles.x,
|
||||||
|
y: remoteMapConfig.tileSize * rules.spritesheet[spriteSheetRotIndex].sizeInTiles.y,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if(rules.spritesheet){
|
} else if(rules.spritesheet){
|
||||||
sprWidth = rules.spritesheet.frame.w;
|
sprWidth = rules.spritesheet.frame.w;
|
||||||
@@ -475,7 +515,7 @@ function drawEntity(entity, dontCache){
|
|||||||
}
|
}
|
||||||
if(!image) image = entityImages[name].img;
|
if(!image) image = entityImages[name].img;
|
||||||
// if(name == "oil-refinery") console.log(offsetX)
|
// if(name == "oil-refinery") console.log(offsetX)
|
||||||
drawImageWithRotation(ctx, image, xPos, yPos, size.x, size.y, rotation%360, sprWidth, sprHeight, offLeft, offTop);
|
drawImageWithRotation(ctx, image, xPos, yPos, size.x, size.y, rotation%360, sprWidth, sprHeight, offLeft, offTop, flipX, flipY);
|
||||||
//console.log("Drawing "+name+" at X: "+xPos+", Y: "+yPos+" with with rotation "+rotation);
|
//console.log("Drawing "+name+" at X: "+xPos+", Y: "+yPos+" with with rotation "+rotation);
|
||||||
} else {
|
} else {
|
||||||
// we are waiting for the image to load, push the task to our queue. It will be processed once the image loads.
|
// we are waiting for the image to load, push the task to our queue. It will be processed once the image loads.
|
||||||
@@ -515,3 +555,4 @@ function clear(){
|
|||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
selectionCtx.clearRect(0, 0, selectionCanvas.width, selectionCanvas.height);
|
selectionCtx.clearRect(0, 0, selectionCanvas.width, selectionCanvas.height);
|
||||||
}
|
}
|
||||||
|
// setInterval(()=>console.log(entityDrawRules),5000);
|
||||||
Reference in new issue
Block a user