@@ -70,13 +70,34 @@ export class AbilityControl {
7070 if ( ! movableObject ) return ;
7171 this . inventory = movableObject ;
7272 }
73- paste ( cx : Context ) {
73+ paste ( cx : Context , facing : Facing ) {
7474 if ( ! this . focused ) return ;
7575 if ( ! this . inventory /*|| this.inventory === Block.air*/ ) return ;
76- const x = this . focused . x ;
76+ const width =
77+ this . inventory . relativePositions . reduce (
78+ ( acc , i ) => Math . max ( acc , i . x ) ,
79+ 0 ,
80+ ) -
81+ this . inventory . relativePositions . reduce (
82+ ( acc , i ) => Math . min ( acc , i . x ) ,
83+ 1000 ,
84+ ) +
85+ 1 ;
86+
87+ const x = this . focused . x - ( facing === Facing . left ? width - 1 : 0 ) ;
7788 const y = this . focused . y ;
78- const target = cx . grid . getBlock ( this . focused . x , this . focused . y ) ;
79- if ( ! target || target !== Block . air ) return ;
89+
90+ for ( const i of this . inventory . relativePositions ) {
91+ const positionX = x + i . x ;
92+ const positionY = y + i . y ;
93+ const target = cx . grid . getBlock ( positionX , positionY ) ;
94+ if ( target !== Block . air ) {
95+ // すでに何かある場合は、ペーストできない
96+ return ;
97+ }
98+ }
99+ // const target = cx.grid.getBlock(this.focused.x, this.focused.y);
100+ // if (!target || target !== Block.air) return;
80101 const prevInventory = this . inventory ;
81102
82103 cx . grid . setMovableObject ( cx , x , y , this . inventory ) ;
@@ -157,11 +178,16 @@ export class AbilityControl {
157178 }
158179 console . log ( `history: ${ this . historyIndex } / ${ this . history . length } ` ) ;
159180 }
160- handleKeyDown ( cx : Context , e : KeyboardEvent , onGround : boolean ) {
181+ handleKeyDown (
182+ cx : Context ,
183+ e : KeyboardEvent ,
184+ onGround : boolean ,
185+ facing : Facing ,
186+ ) {
161187 if ( ! ( e . ctrlKey || e . metaKey ) ) return ;
162188
163189 if ( this . enabled . paste && onGround && e . key === "v" ) {
164- this . paste ( cx ) ;
190+ this . paste ( cx , facing ) ;
165191 }
166192 if ( this . enabled . copy && onGround && e . key === "c" ) {
167193 this . copy ( cx ) ;
0 commit comments