-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatenewsequence.lua
216 lines (129 loc) · 3.78 KB
/
createnewsequence.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
local backQuad = {x=2*64, y=8*64, w=64, h=64}
local createQuad = {x=0, y=5*64, w=64, h=64}
--called on button click
local function createNewProjectFolder()
if string.len(newSeqName)==0 then
screenMsg='enter a project name'
return
end
tgt='project/'..newSeqName
pot=love.filesystem.getInfo(tgt)
if pot~=nil then
screenMsg='project already exists'
return
end
love.filesystem.createDirectory(tgt)
-- local tmp = love.filesystem.newFileData('template/'..newT
-- local newname = name..'.wav'
-- local tgtpath=spath..newname
-- print('writing sound '..tgtpath)
-- love.filesystem.write(tgtpath,tmp)
love.filesystem.write(tgt..'/template.lua',"return '".. newTemplate .."'")
--create currentproject.lua
changeProjectOnStart (newSeqName)
--reboot
love.event.quit( "restart" )
end
local newSeqKeyFunc=function(k)
print(k)
if k=='escape' or k=='backspace' then
newSeqName=''
end
end
local newSeqTextInput=function(t)
if t==' ' then return end
newSeqName=newSeqName..t
end
-- if t=='w' then
-- love.keyboard.setTextInput(false)
-- createNewProjectFolder()
-- return
-- end
local function exitCNS()
print('exit CNS ')
toPaintMode()
end
local widgets={}
local getTemplatesList=function()
local ret={}
for i,f in ipairs(love.filesystem.getDirectoryItems('template/'))
do
print ('file '..f)
info = love.filesystem.getInfo( 'template/'..f, 'directory' )
if info ~=nil then
print(f..' is a dir')
table.insert(ret,f)
end
end
return ret
end
local function changetemplate (folder)
--TODO
print('changetemplate '..folder)
newTemplate=folder
--we need to create a currenttemplate.lua
screenMsg=' type unused seq name then press create'
newSeqName=''
love.keyboard.setTextInput(true)
love.textinput=newSeqTextInput
end
local createtemplateButton=function(i,p)
local w = createTextButton(i*128*buttonZoom,64*buttonZoom,changetemplate,{text=p,key=p},buttonZoom)
return w
end
local createCNSButtons=function()
Templates=getTemplatesList()
widgets={}
local wExitZP = createpicbutton(0,0,buttonsPic,exitCNS,backQuad,buttonZoom)
local wCreate = createpicbutton(0,128*buttonZoom,buttonsPic,createNewProjectFolder,createQuad,buttonZoom)
table.insert(widgets,wExitZP)
table.insert(widgets,wCreate)
--we need to create a button per template
for i,p in ipairs(Templates)
do
table.insert(widgets,createtemplateButton(i,p))
end
end
local function rendertouicanvas()
love.graphics.setCanvas(ui)
love.graphics.clear(0.5,0.5,0.5,1.0)
love.graphics.setColor(0.,0.,0.,1.0)
love.graphics.print(screenMsg,200,64,0,4,4)
love.graphics.print('new seq : '..newSeqName,200,300,0,4,4)
love.graphics.setColor(1.,1.,1.,1.0)
renderWidgets(widgets)
msgToCvs()
--love.graphics.print()
love.graphics.setCanvas()
end
local function createNewSequenceDraw()
rendertouicanvas()
--this is the background image of our paint
love.graphics.clear(.5,.5,.5,1.0)
--love.graphics.clear(1.,1.,1.,1.0)
love.graphics.setColor(1.0,1.0,1.0,1.0)
love.graphics.draw(ui,0,0,0,scrsx,scrsy)
end
local function createNewSequenceUpdate()
if npress==true then
-- print('bs click')
-- addMsg('bs click')
consumed=consumeClick(widgets)
-- print('consumed '..tostring(consumed))brushScreenbrushScreen
if consumed==true
then
return
end
npress=false
end
end
function toCreateNewSequence()
love.keyboard.setTextInput(false)
screenMsg='select template'
newSeqName=''
createCNSButtons()
uiResize=createCNSButtons
keyFunc = newSeqKeyFunc
drawFunc=createNewSequenceDraw
updateFunc=createNewSequenceUpdate
end