File size: 689 Bytes
90cbf22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8cbe088
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

const UNDO_STAX_MAX_LEN = 16

let undo_stack = [];
let undoqueu   = [];

export function undo_mark_task_start(layer) {
    undoqueu = [];
    undoqueu.push(layer);
}

export function undo_add_index_to_task(tileindex) {
    undoqueu.push(tileindex);
}

export function undo_mark_task_end() {
    undo_stack.push(undoqueu);
    if (undo_stack.length > UNDO_STAX_MAX_LEN){
        undo_stack.shift();
    }
}

// utility function for adding a single tile as a task
export function undo_add_single_index_as_task(layer, tileindex) {
    undo_mark_task_start(layer);
    undo_add_index_to_task(tileindex);
    undo_mark_task_end();
}

export function undo_pop() {
    return undo_stack.pop();
}