-
Notifications
You must be signed in to change notification settings - Fork 7
/
SetArchiveDataCommand.go
45 lines (37 loc) · 1.17 KB
/
SetArchiveDataCommand.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
package archives
import (
"github.com/inkyblackness/hacked/ss1/resource"
"github.com/inkyblackness/hacked/ss1/world"
)
type setArchiveDataCommand struct {
model *viewModel
selectedLevel int
oldData map[resource.ID][]byte
newData map[resource.ID][]byte
}
func (command setArchiveDataCommand) Do(modder world.Modder) error {
command.delResources(modder, command.oldData)
return command.perform(modder, command.newData)
}
func (command setArchiveDataCommand) Undo(modder world.Modder) error {
command.delResources(modder, command.newData)
return command.perform(modder, command.oldData)
}
func (command setArchiveDataCommand) delResources(modder world.Modder, data map[resource.ID][]byte) {
for id := range data {
modder.DelResource(resource.LangAny, id)
}
}
// nolint: interfacer
func (command setArchiveDataCommand) perform(modder world.Modder, data map[resource.ID][]byte) error {
for id, blockData := range data {
if len(blockData) > 0 {
modder.SetResourceBlocks(resource.LangAny, id, [][]byte{blockData})
} else {
modder.DelResource(resource.LangAny, id)
}
}
command.model.restoreFocus = true
command.model.selectedLevel = command.selectedLevel
return nil
}