Skip to content

Commit

Permalink
feat: unify the tileId and add tileMode
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-moe-pupil committed Sep 26, 2024
1 parent 5658ddb commit 87fdf2e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
13 changes: 0 additions & 13 deletions ts/src/renderer/three/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ namespace Renderer {
private timeSinceLastRaycast = 0;

// TODO: decouple this to the voxelEditor
public tmp_tileId = 7;
public tmp_waterTileId = 0;
public voxelEditor: VoxelEditor;
public entityEditor: EntityEditor;
private showRepublishWarning: boolean;
Expand Down Expand Up @@ -779,17 +777,6 @@ namespace Renderer {
return this._instance.entitiesLayer;
}

tmpSetTileId(tileId: number) {
this.tmp_tileId = tileId;
this.voxelEditor.voxelMarker.updatePreview(false);
}

tmpSetWaterTileId(tileId: number) {
this.tmp_waterTileId = tileId;
console.log(tileId)
// this.voxelEditor.voxelMarker.updatePreview(false);
}

raycastFloor(layer?: number): THREE.Vector3 | null {
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(this.pointer, this.camera.instance);
Expand Down
25 changes: 21 additions & 4 deletions ts/src/renderer/three/VoxelEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class VoxelEditor {
voxels: Renderer.Three.Voxels;
voxelMarker: Renderer.Three.VoxelMarker;
tileSize: number;
tileId: number;
tileMode: Renderer.Three.TileMode = Renderer.Three.TileMode.TILE;
prevData: { edit: MapEditTool['edit'] } | undefined;
commandController: CommandController = new CommandController({
increaseBrushSize: () => { },
Expand Down Expand Up @@ -144,6 +146,15 @@ class VoxelEditor {
this.voxelMarker;
}

setTileId(tileId: number) {
this.tileId = tileId;
this.voxelMarker.updatePreview(false);
}

setTileMode(tileMode: Renderer.Three.TileMode) {
this.tileMode = tileMode
}

edit<T extends MapEditToolEnum>(data: TileData<T>): void {
if (JSON.stringify(data) === '{}') {
throw 'receive: {}';
Expand Down Expand Up @@ -312,14 +323,17 @@ class VoxelEditor {
const _y = Math.floor((intersect.z * 64) / Renderer.Three.getTileSize().y);

const selectedTiles = {};
const tileId = renderer.tmp_tileId;
const tileId = renderer.voxelEditor.tileId;
selectedTiles[_x] = {};
selectedTiles[_x][_y] = developerMode.activeButton === 'eraser' ? -1 : tileId;
const nowTile = rfdc()(selectedTiles);
const oldTile = this.getTile(_x, this.voxels.calcLayersHeight(this.currentLayerIndex), _y);
nowTile[_x][_y] = oldTile;
const nowLayer = this.currentLayerIndex;
this.voxelMarker.updatePreview();
if (this.tileMode !== Renderer.Three.TileMode.ANIMATED_TILE) {

this.voxelMarker.updatePreview();
}
if (this.leftButtonDown) {
const tex = Renderer.Three.gAssetManager.getTexture(key).clone();
const frameWidth = tex.image.width / cols;
Expand Down Expand Up @@ -353,8 +367,11 @@ class VoxelEditor {
43: 7,
44: 3
}
temp.play(water_animations[animationMap[renderer.tmp_waterTileId]]);
temp.play(water_animations[animationMap[renderer.voxelEditor.tileId]]);
Renderer.Three.instance().animatedTilesLayer.add(temp);
if (this.tileMode === Renderer.Three.TileMode.ANIMATED_TILE) {
return;
}
(window as any).waters.push(temp);
switch (taro.developerMode.activeButton) {
case 'eraser':
Expand Down Expand Up @@ -421,7 +438,7 @@ class VoxelEditor {
const _y = Math.floor(intersect.z);
const taroMap = taro.game.data.map;
if (taroMap.layers[this.currentLayerIndex].data[_y * taroMap.width + _x] !== 0) {
renderer.tmp_tileId = taroMap.layers[this.currentLayerIndex].data[_y * taroMap.width + _x];
renderer.voxelEditor.tileId = taroMap.layers[this.currentLayerIndex].data[_y * taroMap.width + _x];
}
this.voxels.updateLayer(new Map(), this.currentLayerIndex, false, true);
}
Expand Down
2 changes: 1 addition & 1 deletion ts/src/renderer/three/VoxelMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Renderer {
const _x = Math.floor(this.lastPoint.x);
const _y = Math.floor(this.lastPoint.z);
const selectedTiles = {};
const tileId = renderer.tmp_tileId;
const tileId = renderer.voxelEditor.tileId;
selectedTiles[_x] = {};
selectedTiles[_x][_y] = tileId;
renderer.voxelEditor.putTiles(
Expand Down
4 changes: 4 additions & 0 deletions ts/src/renderer/three/entities/Region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ namespace Renderer {
Normal,
Development,
}
export enum TileMode {
ANIMATED_TILE = "animatedTile",
TILE = "TILE"
}
export class Region extends Node {
gameObject: THREE.Object3D;
mesh: THREE.Mesh & { region?: Region };
Expand Down

0 comments on commit 87fdf2e

Please sign in to comment.