File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -2,23 +2,24 @@ import TreeElement from "./../gameobjects/IBranchContainer";
22import { ITreeElementDetails } from "@/gameobjects/IBranchContainer" ;
33import TreeGameObject from "@/gameobjects/TreeGameObject" ;
44import ICommand from "@/commands/ICommand" ;
5+ import SlowTreeError from "@/errors/SlowTreeError" ;
56
67export default class AddTreeElementCommand implements ICommand {
7- private element : TreeElement | null = null ;
8-
98 constructor ( private tree : TreeGameObject , private parent : string , private details : ITreeElementDetails ) {
109 }
1110
1211 do ( ) : void {
1312 const owner = this . tree . find ( this . parent ) ;
1413 if ( owner ) {
15- this . element = owner . addTreeElement ( this . details ) ;
14+ owner . addTreeElement ( this . details ) . id ;
1615 }
1716 }
1817
1918 undo ( ) : void {
20- if ( this . element ) {
21- this . element . destroy ( ) ;
19+ const element = this . tree . find ( this . details . id ) ;
20+ if ( ! element ) {
21+ throw new SlowTreeError ( "Could not find element with ID " + this . details . id ) ;
2222 }
23+ element . destroy ( ) ;
2324 }
2425}
You can’t perform that action at this time.
0 commit comments