@@ -29,13 +29,7 @@ type History = {
2929 } [ ] ;
3030} ;
3131
32- function isMovableObject ( obj : MovableObject | Block ) : obj is MovableObject {
33- return ( obj as MovableObject ) . objectId !== undefined ;
34- }
35-
3632export class AbilityControl {
37- // history: History[] = [];
38- // historyIndex = 0;
3933 inventory : MovableObject | null = null ;
4034 inventoryIsInfinite = false ;
4135 enabled : AbilityEnableOptions ;
@@ -74,10 +68,6 @@ export class AbilityControl {
7468 const movableObject = cx . grid . getMovableObject ( x , y ) ;
7569 if ( ! movableObject ) return ;
7670 this . inventory = movableObject ;
77- // cx.gridとinventryは重複しないように
78- // cx.grid.movableBlocks = cx.grid.movableBlocks.filter(
79- // (block) => block.objectId !== movableObject.objectId,
80- // );
8171 }
8272 paste ( cx : Context , facing : Facing ) {
8373 if ( ! this . focused ) return ;
@@ -124,10 +114,7 @@ export class AbilityControl {
124114 // removable 以外はカットできない
125115 if ( ! target || target !== Block . movable ) return ;
126116 const movableObject = cx . grid . getMovableObject ( x , y ) ;
127- if ( ! movableObject ) {
128- console . log ( "aaaaaa" ) ;
129- return ;
130- }
117+ if ( ! movableObject ) return ;
131118 this . inventory = movableObject ;
132119 // cx.gridとinventryは重複しないように
133120 // 取得したオブジェクトは削除する
@@ -142,18 +129,19 @@ export class AbilityControl {
142129 }
143130
144131 // History については、 `docs/history-stack.png` を参照のこと
132+ // すべての状態を保存
145133 pushHistory (
146134 h : History ,
147135 history : {
148136 list : History [ ] ;
149137 index : number ;
150138 } ,
151139 ) {
152- history . list = history . list . slice ( 0 , history . index ) ;
140+ // history.listの先頭(初期状態)は残す
141+ history . list = history . list . slice ( 0 , Math . max ( history . index , 1 ) ) ;
153142 history . list . push ( JSON . parse ( JSON . stringify ( h ) ) ) ;
154143 history . index = history . list . length ;
155144 console . log ( `history: ${ history . index } / ${ history . list . length } ` ) ;
156- console . log ( history ) ;
157145 }
158146 undo (
159147 cx : Context ,
@@ -162,13 +150,10 @@ export class AbilityControl {
162150 index : number ;
163151 } ,
164152 ) {
165- console . log ( history . index ) ;
166153 if ( history . index <= 0 ) return ;
167154 history . index -- ; // undo は、巻き戻し後の index で計算する
168155 const op = history . list [ history . index ] ;
169156
170- console . log ( "bbb" ) ;
171-
172157 // すべてのオブジェクトを削除
173158 cx . grid . clearAllMovableBlocks ( ) ;
174159
@@ -285,7 +270,6 @@ export class AbilityControl {
285270 } ,
286271 history ,
287272 ) ;
288- console . log ( "x" , history ) ;
289273 }
290274 if ( e . key === "z" ) {
291275 this . undo ( cx , history ) ;
0 commit comments