1 require('script/strict')
2 --
\83\86\81[
\83e
\83B
\83\8a\83e
\83B
\8aÖ
\90\94
5 if str == nil or str == '' then return true
10 function split(str, delim)
11 if string.find(str, delim) == nil then
16 local pat = '(.-)' .. delim .. '()'
18 for part, pos in string.gfind(str, pat) do
19 table.insert(result, part)
22 table.insert(result, string.sub(str, last_pos))
27 function join(tbl, sep)
29 for n, v in pairs(tbl) do
30 local seg = tostring(v)
34 ret = ret .. sep .. seg
41 function find(tbl, elem)
42 if tbl == nil then return false end
44 for n, v in pairs(tbl) do
45 if v == elem then return true end
51 function layout(left_margin, width, right_margin, top_margin, height, bottom_margin)
53 local data = load_game_data('system.client_region')
54 local screen_width = data[1]['width']
55 local screen_height = data[1]['height']
59 -- TODO parameter check. use error function
60 if left_margin ~= nil and right_margin ~= nil then
61 --
\8d¶
\89E
\82Ì
\83}
\81[
\83W
\83\93\82©
\82ç
\92\86\90S
\88Ê
\92u
\82ð
\8b\81\82ß
\82é
62 local center_from_left = left_margin + (1.0 - left_margin - right_margin) / 2
63 x = center_from_left * screen_width - width / 2
66 if top_margin ~= nil and bottom_margin ~= nil then
67 --
\8fã
\89º
\82Ì
\83}
\81[
\83W
\83\93\82©
\82ç
\92\86\90S
\88Ê
\92u
\82ð
\8b\81\82ß
\82é
68 local center_from_top = top_margin + (1.0 - top_margin - bottom_margin) / 2
69 y = center_from_top * screen_height - height / 2
79 function wait_frame(frame)
84 --
\82±
\82±
\82Ì
\83L
\81[
\92è
\90\94\82ÍInputReceiver
\82Æ
\93¯
\8aú
\82µ
\82Ä
\82¢
\82È
\82¯
\82ê
\82Î
\82È
\82ç
\82È
\82¢
119 function sound(filepath)
120 local id = soundCreateImpl(filepath)
122 --disposeImpl(id, 'sound')
126 function load_game_data(resource_path)
127 return loadGameDataImpl(resource_path)
131 function wait_for_key(key)
137 function get_last_key()
138 return getLastKeyImpl()
143 wait_for_key(KEY_ANY)
144 return get_last_key()
148 function message(title, texts, style, initializer)
149 local obj = Message:new(title)
150 if initializer ~= nil then initializer(obj) end
151 local frame = obj:show()
153 for i = 1 , #texts , 1
155 local frame = obj:next(texts[i])
159 local frame = obj:hide()
165 function Message:new(title, style)
166 if style == nil then style = '' end
167 local id = messageNewImpl(title, style)
170 setmetatable(obj, {__index = Message})
175 function Message:show()
176 return showImpl(self.id_, 'message')
180 function Message:hide()
181 return hideImpl(self.id_, 'message')
185 function Message:set_tween(target, stream, period)
186 if period == nil then period = 0 end
187 objectSetBehaviorImpl(self.id_, 'message.' .. target, stream, period)
191 function Message:get_properties()
192 return objectGetPropertiesImpl(self.id_, 'message')
196 function Message:next(text)
198 return messageNextImpl(self.id_, text)
202 function Message:dispose(text)
203 return disposeImpl(self.id_, 'message')
208 function question(title, items, style, disables, initializer)
209 if disables ~= nil then
210 -- disable
\82ª
\8ew
\92è
\82³
\82ê
\82Ä
\82¢
\82½
\82çstyle
\82É
\92Ç
\89Á
211 if not is_empty(style) then style = style .. ';' end
212 style = 'disable=' .. join(disables, ',')
214 local obj = Question:new(title, items, style)
215 if initializer ~= nil then initializer(obj) end
216 local frame = obj:show()
219 local key = get_key()
220 if key == KEY_UP then obj:move_cursor_up()
221 elseif key == KEY_DOWN then obj:move_cursor_down()
222 elseif key == KEY_LEFT then obj:move_cursor_left()
223 elseif key == KEY_RIGHT then obj:move_cursor_right()
224 elseif key == KEY_X then
225 sound("sound/cancel.wav")--
\83L
\83\83\83\93\83Z
\83\8b\89¹
229 return 0 --
\83L
\83\83\83\93\83Z
\83\8b
230 elseif key == KEY_Z then
231 local index = obj:get_current()
232 if not find(disables, index) then -- disable
\82È
\82ç
\96³
\8e\8b\82·
\82é
233 sound("sound/decide.wav")--
\8c\88\92è
\89¹
239 return index + 1 --0
\82Í
\83L
\83\83\83\93\83Z
\83\8b\8e\9e\82Ì
\93®
\82«
246 function Question:new(title, items, style)
247 if style == nil then style = '' end
248 local id = menuNewImpl(title, items, style)
251 setmetatable(obj, {__index = Question})
256 function Question:show()
257 return showImpl(self.id_, 'menu')
261 function Question:hide()
262 return hideImpl(self.id_, 'menu')
266 function Question:set_tween(target, stream, period)
267 if period == nil then period = 0 end
268 objectSetBehaviorImpl(self.id_, 'menu.' .. target, stream, period)
272 function Question:get_properties()
273 return objectGetPropertiesImpl(self.id_, 'menu')
282 function Question:move_cursor_up()
283 return menuMoveCursorImpl(self.id_, MOVE_UP)
286 function Question:move_cursor_down()
287 return menuMoveCursorImpl(self.id_, MOVE_DOWN)
290 function Question:move_cursor_left()
291 return menuMoveCursorImpl(self.id_, MOVE_LEFT)
294 function Question:move_cursor_right()
295 return menuMoveCursorImpl(self.id_, MOVE_RIGHT)
299 function Question:get_current()
300 return menuGetCurrentImpl(self.id_)
304 function Question:select()
305 return menuSelectImpl(self.id_)
309 function Question:dispose()
310 return disposeImpl(self.id_, 'menu')
315 function print_debug(obj, spacer)
316 if (type(obj) ~= 'table') then
317 printDebugImpl(tostring(obj))
321 if spacer == nil then spacer = '' end
323 for key, value in pairs(obj) do
324 if (type(value) ~= 'table') then
325 printDebugImpl(spacer .. tostring(key) .. ' => ' .. tostring(value))
327 printDebugImpl(spacer .. tostring(key) .. ' => ' )
328 print_debug(value, spacer .. ' ')
336 function Picture:new(path)
337 local id = pictureCreateImpl(path)
340 setmetatable(obj, {__index = Picture})
345 function Picture:set_tween(target, stream)
346 objectSetBehaviorImpl(self.id_, 'picture.' .. target, stream, 0)
350 function Picture:dispose()
351 return disposeImpl(self.id_, 'picture')
358 function Particlegen:new()
359 local id = particlegenCreateImpl()
362 setmetatable(obj, {__index = Particlegen})
367 function Particlegen:set_tween(target, stream)
368 objectSetBehaviorImpl(self.id_, 'particlegen.' .. target, stream, 0)
372 function Particlegen:dispose()
373 return disposeImpl(self.id_, 'particlegen')