-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrushpresets.lua
144 lines (105 loc) · 3.16 KB
/
brushpresets.lua
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
--to save the brush presets on function keys
-- when we change presets we recompose a preview picture
brushPreviewCanvas=nil
--structure for documentation
--we save setings with f6 f10
--we restore with f1 f5
brushPresets={
-- f1={eraser=true,size=8},
-- f2={size=8,color={r=1.0,g=0.0,b=0.0,type='soft'|'hard'}}
}
--texs stored separately so we can save metadata
brushTexes ={
--f2=realblittablebrush
}
--DIRTY takes keycode directly so slot is f'x' - 5
storeInSlot= function(key)
print('storing '..key)
slot=key:sub(2,3)
tgtslot=slot-5
print('tgtslot '..tgtslot)
tkey='f'..tgtslot
if eraseMode==true then
print('eraser stored')
brushPresets[tkey]={eraser=true,size=eraserRadius}
else
print('brush stored '..tkey)
if currentBrushFunc==roundBrushWithAlpha then
local currentType='hard'
elseif currentBrushFunc==roundBrushWithGradient then
local currentType='soft'
end
brushPresets[tkey]={size=brshradius,color={r=paintcolor.r,g=paintcolor.g,b=paintcolor.b},type=currentType}
if currentBrushFunc==roundBrushWithAlpha then
brushPresets[tkey].type='hard'
elseif currentBrushFunc==roundBrushWithGradient then
brushPresets[tkey].type='soft'
end
brushTexes[tkey]=mybrush
end
end
restoreSlot= function(key)
print('restoring '..key)
local pot=brushPresets[key]
if pot==nil then
print('nothing to restore yet')
return
end
if pot.eraser==true then
print('eraser restored')
eraseMode=true
eraserRadius=pot.size
else
eraseMode=false
if pot.type=='hard' then
currentBrushFunc=roundBrushWithAlpha
elseif pot.type=='soft' then
currentBrushFunc=roundBrushWithGradient
end
print('brush restored '..key)
brshradius=pot.size
paintcolor.r=pot.color.r
paintcolor.g=pot.color.g
paintcolor.b=pot.color.b
mybrush=brushTexes[key]
end
end
saveBrushes=function ()
--brushes are stored by project
--conf.prjfld
--lets try without stripping texes
love.filesystem.write(conf.prjfld..'brushes.lua',serialize(brushPresets))
end
--we loaded brushes, lets prepare the texes
initBrushTexes=function()
for k,pres in pairs( brushPresets )
do
if pres.eraser==nil then
--brush func depends on template
local initBrushFunc=1 --just to exist
if pres.type=='hard' then
initBrushFunc=roundBrushWithAlpha
elseif pres.type=='soft' then
initBrushFunc=roundBrushWithGradient
end
local tmp=love.graphics.newImage(initBrushFunc( pres.size,pres.color.r,pres.color.g,pres.color.b))
tmp:setFilter('nearest','nearest')
brushTexes[k]=tmp
print('text brush stored for '..k)
print('color '..pres.color.r..' '..pres.color.g..' '..pres.color.b)
end
end
end
loadBrushes=function()
local loaded = {}
local loadedFsInfo=love.filesystem.getInfo(conf.prjfld..'brushes.lua')
print('brushes file ')
print(loadedFsInfo)
if loadedFsInfo then
brushPresets=love.filesystem.load(conf.prjfld..'brushes.lua')()
initBrushTexes ()--these can not be serialized
else
-- highscores=defaulths()
print('no brushes file, TODO load defaults')
end
end