forked from Benjamin-Dobell/ge_tts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid.ttslua
71 lines (54 loc) · 1.68 KB
/
Grid.ttslua
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local SaveManager = require('ge_tts.SaveManager')
local GlobalGrid = Grid
---@class ge_tts__Grid : tts__GlobalGrid
local Grid = {}
Grid.Type = {
Box = 1,
HexHorizontal = 2,
HexVertical = 3,
}
Grid.Snapping = {
None = 1,
Lines = 2,
Center = 3,
LinesAndCenter = 4,
}
-- We're tracking snapping as a *partial* work-around for a TTS bug:
-- https://github.com/tts-community/tts-community-bug-tracker/issues/28
-- It's a partial work-around in that we'll return the correct value for snapping as long as it's only set using this
-- wrapper. If Grid.snapping is changed by script without using this wrapper or by UI, our return value will be wrong.
---@type tts__GridSnapping
local snapping = GlobalGrid.snapping
setmetatable(Grid, {
__index = function(_, key)
if key == 'snapping' then
local ttsSnapping = GlobalGrid.snapping
-- At the time of writing Grid.Snapping.Lines is the only value that we can trust from TTS...
if ttsSnapping == Grid.Snapping.Lines then
snapping = Grid.Snapping.Lines
end
return snapping
end
return GlobalGrid[key]
end,
__newindex = function(_, key, value)
if key == 'snapping' then
snapping = value
end
GlobalGrid[key] = value
end
})
---@return string
local function onSave()
return tostring(snapping)
end
---@param savedState string
local function onLoad(savedState)
if savedState ~= '' then
snapping = tonumber(savedState)
end
end
local MODULE_NAME = 'ge_tts.Grid'
SaveManager.registerOnSave(MODULE_NAME, onSave)
SaveManager.registerOnLoad(MODULE_NAME, onLoad)
return Grid