fix: ECS size change
This commit is contained in:
parent
df0e012338
commit
c27ab133a9
|
@ -12,55 +12,8 @@ import {CHUNK_SIZE, RESOLUTION} from '@/util/constants.js';
|
||||||
import {deferredLighting} from './lights.js';
|
import {deferredLighting} from './lights.js';
|
||||||
|
|
||||||
const TileLayerInternal = PixiComponent('TileLayer', {
|
const TileLayerInternal = PixiComponent('TileLayer', {
|
||||||
create: ({group, tileLayer}) => {
|
create: () => {
|
||||||
const container = new Container();
|
const container = new Container();
|
||||||
const {area, tileSize} = tileLayer;
|
|
||||||
const g = new Graphics();
|
|
||||||
g.beginFill(group === deferredLighting.diffuseGroup ? 0x000000 : 0x7777ff);
|
|
||||||
// outer frame
|
|
||||||
g.drawRect(
|
|
||||||
-RESOLUTION.x / 2,
|
|
||||||
-RESOLUTION.y / 2,
|
|
||||||
area.x * tileSize.x + RESOLUTION.x,
|
|
||||||
RESOLUTION.y / 2,
|
|
||||||
);
|
|
||||||
g.drawRect(
|
|
||||||
-RESOLUTION.x / 2,
|
|
||||||
-RESOLUTION.y / 2,
|
|
||||||
RESOLUTION.x / 2,
|
|
||||||
area.y * tileSize.y + RESOLUTION.y,
|
|
||||||
);
|
|
||||||
g.drawRect(
|
|
||||||
area.x * tileSize.x,
|
|
||||||
0,
|
|
||||||
RESOLUTION.x / 2,
|
|
||||||
area.y * tileSize.y,
|
|
||||||
);
|
|
||||||
g.drawRect(
|
|
||||||
0,
|
|
||||||
area.y * tileSize.y,
|
|
||||||
area.x * tileSize.x,
|
|
||||||
RESOLUTION.y / 2,
|
|
||||||
);
|
|
||||||
g.parentGroup = group;
|
|
||||||
container.addChild(g);
|
|
||||||
const cy = Math.ceil(area.y / CHUNK_SIZE);
|
|
||||||
const cx = Math.ceil(area.x / CHUNK_SIZE);
|
|
||||||
for (let iy = 0; iy < cy; ++iy) {
|
|
||||||
for (let ix = 0; ix < cx; ++ix) {
|
|
||||||
const tilemap = new CompositeTilemap();
|
|
||||||
const renderTexture = RenderTexture.create({
|
|
||||||
width: tileSize.x * CHUNK_SIZE,
|
|
||||||
height: tileSize.y * CHUNK_SIZE,
|
|
||||||
});
|
|
||||||
const sprite = new Sprite(renderTexture);
|
|
||||||
sprite.x = tileSize.x * CHUNK_SIZE * ix;
|
|
||||||
sprite.y = tileSize.y * CHUNK_SIZE * iy;
|
|
||||||
sprite.parentGroup = group;
|
|
||||||
sprite.tilemap = tilemap;
|
|
||||||
container.addChild(sprite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
applyProps: (container, {tileLayer: oldTileLayer}, props) => {
|
applyProps: (container, {tileLayer: oldTileLayer}, props) => {
|
||||||
|
@ -70,6 +23,64 @@ const TileLayerInternal = PixiComponent('TileLayer', {
|
||||||
if (tileLayer === oldTileLayer) {
|
if (tileLayer === oldTileLayer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
!oldTileLayer
|
||||||
|
|| (
|
||||||
|
oldTileLayer.area.x !== tileLayer.area.x
|
||||||
|
|| oldTileLayer.area.y !== tileLayer.area.y
|
||||||
|
|| oldTileLayer.tileSize.x !== tileLayer.tileSize.x
|
||||||
|
|| oldTileLayer.tileSize.y !== tileLayer.tileSize.y
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
container.removeChildren();
|
||||||
|
const {area, tileSize} = tileLayer;
|
||||||
|
const g = new Graphics();
|
||||||
|
g.beginFill(group === deferredLighting.diffuseGroup ? 0x000000 : 0x7777ff);
|
||||||
|
// outer frame
|
||||||
|
g.drawRect(
|
||||||
|
-RESOLUTION.x / 2,
|
||||||
|
-RESOLUTION.y / 2,
|
||||||
|
area.x * tileSize.x + RESOLUTION.x,
|
||||||
|
RESOLUTION.y / 2,
|
||||||
|
);
|
||||||
|
g.drawRect(
|
||||||
|
-RESOLUTION.x / 2,
|
||||||
|
-RESOLUTION.y / 2,
|
||||||
|
RESOLUTION.x / 2,
|
||||||
|
area.y * tileSize.y + RESOLUTION.y,
|
||||||
|
);
|
||||||
|
g.drawRect(
|
||||||
|
area.x * tileSize.x,
|
||||||
|
0,
|
||||||
|
RESOLUTION.x / 2,
|
||||||
|
area.y * tileSize.y,
|
||||||
|
);
|
||||||
|
g.drawRect(
|
||||||
|
0,
|
||||||
|
area.y * tileSize.y,
|
||||||
|
area.x * tileSize.x,
|
||||||
|
RESOLUTION.y / 2,
|
||||||
|
);
|
||||||
|
g.parentGroup = group;
|
||||||
|
container.addChild(g);
|
||||||
|
const cy = Math.ceil(area.y / CHUNK_SIZE);
|
||||||
|
const cx = Math.ceil(area.x / CHUNK_SIZE);
|
||||||
|
for (let iy = 0; iy < cy; ++iy) {
|
||||||
|
for (let ix = 0; ix < cx; ++ix) {
|
||||||
|
const tilemap = new CompositeTilemap();
|
||||||
|
const renderTexture = RenderTexture.create({
|
||||||
|
width: tileSize.x * CHUNK_SIZE,
|
||||||
|
height: tileSize.y * CHUNK_SIZE,
|
||||||
|
});
|
||||||
|
const sprite = new Sprite(renderTexture);
|
||||||
|
sprite.x = tileSize.x * CHUNK_SIZE * ix;
|
||||||
|
sprite.y = tileSize.y * CHUNK_SIZE * iy;
|
||||||
|
sprite.parentGroup = group;
|
||||||
|
sprite.tilemap = tilemap;
|
||||||
|
container.addChild(sprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (const i in tileLayer.$$chunks) {
|
for (const i in tileLayer.$$chunks) {
|
||||||
if (!oldTileLayer || oldTileLayer.$$chunks[i] !== tileLayer.$$chunks[i]) {
|
if (!oldTileLayer || oldTileLayer.$$chunks[i] !== tileLayer.$$chunks[i]) {
|
||||||
const {texture, tilemap} = container.children[parseInt(i) + 1];
|
const {texture, tilemap} = container.children[parseInt(i) + 1];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user