· 5 years ago · Oct 06, 2020, 06:54 AM
1# ===================================================================
2#
3# Script: Component_CommandInterpreter
4#
5# $$COPYRIGHT$$
6#
7# ===================================================================
8class Component_CommandInterpreter extends gs.Component
9 @objectCodecBlackList = ["object", "command", "onMessageADVWaiting", "onMessageADVDisappear", "onMessageADVFinish"]
10
11 ###*
12 * Called if this object instance is restored from a data-bundle. It can be used
13 * re-assign event-handler, anonymous functions, etc.
14 *
15 * @method onDataBundleRestore.
16 * @param Object data - The data-bundle
17 * @param gs.ObjectCodecContext context - The codec-context.
18 ###
19 onDataBundleRestore: (data, context) ->
20
21
22 ###*
23 * A component which allows a game object to process commands like for
24 * scene-objects. For each command a command-function exists. To add
25 * own custom commands to the interpreter just create a sub-class and
26 * override the gs.Component_CommandInterpreter.assignCommand method
27 * and assign the command-function for your custom-command.
28 *
29 * @module gs
30 * @class Component_CommandInterpreter
31 * @extends gs.Component
32 * @memberof gs
33 ###
34 constructor: () ->
35 super()
36
37 ###*
38 * Wait-Counter in frames. If greater than 0, the interpreter will for that amount of frames before continue.
39 * @property waitCounter
40 * @type number
41 ###
42 @waitCounter = 0
43
44 ###*
45 * Index to the next command to execute.
46 * @property pointer
47 * @type number
48 ###
49 @pointer = 0
50
51 ###*
52 * Stores states of conditions.
53 * @property conditions
54 * @type number
55 * @protected
56 ###
57 @conditions = []
58
59 ###*
60 * Stores states of loops.
61 * @property loops
62 * @type number
63 * @protected
64 ###
65 @loops = []
66
67 # FIXME: Should not be stored in the interpreter.
68 @timers = []
69
70 ###*
71 * Indicates if the interpreter is currently running.
72 * @property isRunning
73 * @type boolean
74 * @readOnly
75 ###
76 @isRunning = no
77
78 ###*
79 * Indicates if the interpreter is currently waiting.
80 * @property isWaiting
81 * @type boolean
82 ###
83 @isWaiting = no
84
85 ###*
86 * Indicates if the interpreter is currently waiting until a message processed by another context like a Common Event
87 * is finished.
88 * FIXME: Conflict handling can be removed maybe.
89 * @property isWaitingForMessage
90 * @type boolean
91 ###
92 @isWaitingForMessage = no
93
94 ###*
95 * Stores internal preview-info if the game runs currently in Live-Preview.
96 * <ul>
97 * <li>previewInfo.timeout - Timer ID if a timeout for live-preview was configured to exit the game loop after a certain amount of time.</li>
98 * <li>previewInfo.waiting - Indicates if Live-Preview is currently waiting for the next user-action. (Selecting another command, etc.)</li>
99 * <li>previewInfo.executedCommands - Counts the amount of executed commands since the last
100 * interpreter-pause(waiting, etc.). If its more than 500, the interpreter will automatically pause for 1 frame to
101 * avoid that Live-Preview freezes the Editor in case of endless loops.</li>
102 * </ul>
103 * @property previewInfo
104 * @type boolean
105 * @protected
106 ###
107 @previewInfo = new gs.LivePreviewInfo()
108
109 ###*
110 * Stores Live-Preview related info passed from the VN Maker editor like the command-index the player clicked on, etc.
111 * @property previewData
112 * @type Object
113 * @protected
114 ###
115 @previewData = null
116
117 ###*
118 * Indicates if the interpreter automatically repeats execution after the last command was executed.
119 * @property repeat
120 * @type boolean
121 ###
122 @repeat = no
123
124 ###*
125 * The execution context of the interpreter.
126 * @property context
127 * @type gs.InterpreterContext
128 * @protected
129 ###
130 @context = new gs.InterpreterContext(0, null)
131
132 ###*
133 * Sub-Interpreter from a Common Event Call. The interpreter will wait until the sub-interpreter is done and set back to
134 * <b>null</b>.
135 * @property subInterpreter
136 * @type gs.Component_CommandInterpreter
137 * @protected
138 ###
139 @subInterpreter = null
140
141 ###*
142 * Current indent-level of execution
143 * @property indent
144 * @type number
145 * @protected
146 ###
147 @indent = 0
148
149 ###*
150 * Stores information about for what the interpreter is currently waiting for like for a ADV message, etc. to
151 * restore probably when loaded from a save-game.
152 * @property waitingFor
153 * @type Object
154 * @protected
155 ###
156 @waitingFor = {}
157
158 ###*
159 * Stores interpreter related settings like how to handle messages, etc.
160 * @property settings
161 * @type Object
162 * @protected
163 ###
164 @settings = { message: { byId: {}, autoErase: yes, waitAtEnd: yes, backlog: yes }, screen: { pan: new gs.Point(0, 0) } }
165
166 ###*
167 * Mapping table to quickly get the anchor point for the an inserted anchor-point constant such as
168 * Top-Left(0), Top(1), Top-Right(2) and so on.
169 * @property graphicAnchorPointsByConstant
170 * @type gs.Point[]
171 * @protected
172 ###
173 @graphicAnchorPointsByConstant = [
174 new gs.Point(0.0, 0.0),
175 new gs.Point(0.5, 0.0),
176 new gs.Point(1.0, 0.0),
177 new gs.Point(1.0, 0.5),
178 new gs.Point(1.0, 1.0),
179 new gs.Point(0.5, 1.0),
180 new gs.Point(0.0, 1.0),
181 new gs.Point(0.0, 0.5),
182 new gs.Point(0.5, 0.5)
183 ]
184
185 onHotspotClick: (e, data) ->
186 @executeAction(data.params.actions.onClick, no, data.bindValue)
187 onHotspotEnter: (e, data) ->
188 @executeAction(data.params.actions.onEnter, yes, data.bindValue)
189 onHotspotLeave: (e, data) ->
190 @executeAction(data.params.actions.onLeave, no, data.bindValue)
191 onHotspotDragStart: (e, data) ->
192 @executeAction(data.params.actions.onDrag, yes, data.bindValue)
193 onHotspotDrag: (e, data) ->
194 @executeAction(data.params.actions.onDrag, yes, data.bindValue)
195 onHotspotDragEnd: (e, data) ->
196 @executeAction(data.params.actions.onDrag, no, data.bindValue)
197 onHotspotDrop: (e, data) ->
198 @executeAction(data.params.actions.onDrop, no, data.bindValue)
199 gs.GlobalEventManager.emit("hotspotDrop", e.sender)
200 onHotspotDropReceived: (e, data) ->
201 @executeAction(data.params.actions.onDropReceive, yes, data.bindValue)
202 onHotspotStateChanged: (e, params) ->
203 if e.sender.behavior.selected
204 @executeAction(params.actions.onSelect, yes)
205 else
206 @executeAction(params.actions.onDeselect, no)
207
208 ###*
209 * Called when a ADV message finished rendering and is now waiting
210 * for the user/autom-message timer to proceed.
211 *
212 * @method onMessageADVWaiting
213 * @return {Object} Event Object containing additional data.
214 * @protected
215 ###
216 onMessageADVWaiting: (e) ->
217 messageObject = e.sender.object
218 if !@messageSettings().waitAtEnd
219 if e.data.params.waitForCompletion
220 @isWaiting = no
221 messageObject.textRenderer.isWaiting = no
222 messageObject.textRenderer.isRunning = no
223 messageObject.events.off "waiting", e.handler
224
225 if @messageSettings().backlog and (messageObject.settings.autoErase or messageObject.settings.paragraphSpacing > 0)
226 GameManager.backlog.push({ character: messageObject.character, message: messageObject.behavior.message, choices: [] })
227
228 ###*
229 * Called when an ADV message finished fade-out.
230 *
231 * @method onMessageADVDisappear
232 * @return {Object} Event Object containing additional data.
233 * @protected
234 ###
235 onMessageADVDisappear: (messageObject, waitForCompletion) ->
236 SceneManager.scene.currentCharacter = { name: "" }
237 messageObject.behavior.clear()
238 messageObject.visible = no
239
240 if messageObject.waitForCompletion
241 @isWaiting = no
242 @waitingFor.messageADV = null
243
244 ###*
245 * Called when an ADV message finished clear.
246 *
247 * @method onMessageADVClear
248 * @return {Object} Event Object containing additional data.
249 * @protected
250 ###
251 onMessageADVClear: (messageObject, waitForCompletion) ->
252 messageObject = @targetMessage()
253 if @messageSettings().backlog
254 GameManager.backlog.push({ character: messageObject.character, message: messageObject.behavior.message, choices: [] })
255 @onMessageADVDisappear(messageObject, waitForCompletion)
256
257
258
259 ###*
260 * Called when a hotspot/image-map sends a "jumpTo" event to let the
261 * interpreter jump to the position defined in the event object.
262 *
263 * @method onJumpTo
264 * @return {Object} Event Object containing additional data.
265 * @protected
266 ###
267 onJumpTo: (e) ->
268 @jumpToLabel(e.label)
269 @isWaiting = no
270
271 ###*
272 * Called when a hotspot/image-map sends a "callCommonEvent" event to let the
273 * interpreter call the common event defined in the event object.
274 *
275 * @method onJumpTo
276 * @return {Object} Event Object containing additional data.
277 * @protected
278 ###
279 onCallCommonEvent: (e) ->
280 eventId = e.commonEventId
281 event = RecordManager.commonEvents[eventId]
282 if !event
283 event = RecordManager.commonEvents.first (x) => x.name == eventId
284 eventId = event.index if event
285 @callCommonEvent(eventId, e.params || [], !e.finish)
286 @isWaiting = e.waiting ? no
287
288 ###*
289 * Called when a ADV message finishes.
290 *
291 * @method onMessageADVFinish
292 * @return {Object} Event Object containing additional data.
293 * @protected
294 ###
295 onMessageADVFinish: (e) ->
296 messageObject = e.sender.object
297
298 if not @messageSettings().waitAtEnd then return
299
300 GameManager.globalData.messages[lcsm(e.data.params.message)] = { read: yes }
301 GameManager.saveGlobalData()
302 if e.data.params.waitForCompletion
303 @isWaiting = no
304 @waitingFor.messageADV = null
305 pointer = @pointer
306 commands = @object.commands
307
308 messageObject.events.off "finish", e.handler
309 #messageObject.character = null
310
311 if messageObject.voice? and GameManager.settings.skipVoiceOnAction
312 AudioManager.stopSound(messageObject.voice.name)
313
314 if not @isMessageCommand(pointer, commands) and @messageSettings().autoErase
315 @isWaiting = yes
316 @waitingFor.messageADV = e.data.params
317
318 fading = GameManager.tempSettings.messageFading
319 duration = if GameManager.tempSettings.skip then 0 else fading.duration
320
321 messageObject.waitForCompletion = e.data.params.waitForCompletion
322 messageObject.animator.disappear(fading.animation, fading.easing, duration, gs.CallBack("onMessageADVDisappear", this, e.data.params.waitForCompletion))
323
324 ###*
325 * Called when a common event finished execution. In most cases, the interpreter
326 * will stop waiting and continue processing after this. But h
327 *
328 * @method onCommonEventFinish
329 * @return {Object} Event Object containing additional data.
330 * @protected
331 ###
332 onCommonEventFinish: (e) ->
333 SceneManager.scene.commonEventContainer.removeObject(e.sender.object)
334 e.sender.object.events.off "finish"
335 @subInterpreter = null
336 @isWaiting = e.data.waiting ? no
337
338 ###*
339 * Called when a scene call finished execution.
340 *
341 * @method onCallSceneFinish
342 * @param {Object} sender - The sender of this event.
343 * @protected
344 ###
345 onCallSceneFinish: (sender) ->
346 @isWaiting = no
347 @subInterpreter = null
348
349 ###*
350 * Serializes the interpreter into a data-bundle.
351 *
352 * @method toDataBundle
353 * @return {Object} The data-bundle.
354 ###
355 toDataBundle: ->
356 if @isInputDataCommand(Math.max(@pointer - 1, 0), @object.commands)
357 pointer: Math.max(@pointer - 1 , 0),
358 choice: @choice,
359 conditions: @conditions,
360 loops: @loops,
361 labels: @labels,
362 isWaiting: no,
363 isRunning: @isRunning,
364 waitCounter: @waitCounter,
365 waitingFor: @waitingFor,
366 indent: @indent,
367 settings: @settings
368 else
369 pointer: @pointer,
370 choice: @choice,
371 conditions: @conditions,
372 loops: @loops,
373 labels: @labels,
374 isWaiting: @isWaiting,
375 isRunning: @isRunning,
376 waitCounter: @waitCounter,
377 waitingFor: @waitingFor,
378 indent: @indent,
379 settings: @settings
380
381 ###*
382 # Previews the current scene at the specified pointer. This method is called from the
383 # VN Maker Scene-Editor if live-preview is enabled and the user clicked on a command.
384 #
385 # @method preview
386 ###
387 preview: ->
388 try
389 return if !$PARAMS.preview or !$PARAMS.preview.scene
390 AudioManager.stopAllSounds()
391 AudioManager.stopAllMusic()
392 AudioManager.stopAllVoices()
393 SceneManager.scene.choices = []
394 GameManager.setupCursor()
395 @previewData = $PARAMS.preview
396 gs.GlobalEventManager.emit("previewRestart")
397 if @previewInfo.timeout
398 clearTimeout(@previewInfo.timeout)
399
400 if Graphics.stopped
401 Graphics.stopped = no
402 Graphics.onEachFrame(gs.Main.frameCallback)
403
404 scene = new vn.Object_Scene()
405
406 scene.sceneData.uid = @previewData.scene.uid
407 SceneManager.switchTo(scene)
408 catch ex
409 console.warn(ex)
410
411 ###*
412 # Sets up the interpreter.
413 #
414 # @method setup
415 ###
416 setup: ->
417 super
418
419 @previewData = $PARAMS.preview
420 if @previewData
421 gs.GlobalEventManager.on "mouseDown", (=>
422 if @previewInfo.waiting
423 if @previewInfo.timeout
424 clearTimeout(@previewInfo.timeout)
425 @previewInfo.waiting = no
426 #@isWaiting = no
427 GameManager.tempSettings.skip = no
428 @previewData = null
429 gs.GlobalEventManager.emit("previewRestart")
430 ), null, @object
431
432 ###*
433 # Disposes the interpreter.
434 #
435 # @method dispose
436 ###
437 dispose: ->
438 if @previewData
439 gs.GlobalEventManager.offByOwner("mouseDown", @object)
440
441
442 super
443
444
445 isInstantSkip: -> GameManager.tempSettings.skip and GameManager.tempSettings.skipTime == 0
446
447 ###*
448 * Restores the interpreter from a data-bundle
449 *
450 * @method restore
451 * @param {Object} bundle- The data-bundle.
452 ###
453 restore: ->
454
455 ###*
456 * Gets the default game message for novel-mode.
457 *
458 * @method messageObjectNVL
459 * @return {ui.Object_Message} The NVL game message object.
460 ###
461 messageObjectNVL: -> gs.ObjectManager.current.objectById("nvlGameMessage_message")
462
463 ###*
464 * Gets the default game message for adventure-mode.
465 *
466 * @method messageObjectADV
467 * @return {ui.Object_Message} The ADV game message object.
468 ###
469 messageObjectADV: ->
470 gs.ObjectManager.current.objectById("gameMessage_message")
471
472 ###*
473 * Starts the interpreter
474 *
475 * @method start
476 ###
477 start: ->
478 @conditions = []
479 @loops = []
480 @indent = 0
481 @pointer = 0
482 @isRunning = yes
483 @isWaiting = no
484 @subInterpreter = null
485 @waitCounter = 0
486
487 ###*
488 * Stops the interpreter
489 *
490 * @method stop
491 ###
492 stop: ->
493 @isRunning = no
494
495 ###*
496 * Resumes the interpreter
497 *
498 * @method resume
499 ###
500 resume: ->
501 @isRunning = yes
502
503 ###*
504 * Updates the interpreter and executes all commands until the next wait is
505 * triggered by a command. So in the case of an endless-loop the method will
506 * never return.
507 *
508 * @method update
509 ###
510 update: ->
511 if @subInterpreter?
512 @subInterpreter.update()
513 return
514
515 GameManager.variableStore.setupTempVariables(@context)
516
517 if (not @object.commands? or @pointer >= @object.commands.length) and not @isWaiting
518 if @repeat
519 @start()
520 else if @isRunning
521 @isRunning = no
522 if @onFinish? then @onFinish(this)
523 return
524
525 if not @isRunning then return
526
527 if not @object.commands.optimized
528 DataOptimizer.optimizeEventCommands(@object.commands)
529
530 if @waitCounter > 0
531 @waitCounter--
532 @isWaiting = @waitCounter > 0
533 return
534
535 if @isWaitingForMessage
536 @isWaiting = yes
537 if not @isProcessingMessageInOtherContext()
538 @isWaiting = no
539 @isWaitingForMessage = no
540 else
541 return
542
543 if GameManager.inLivePreview
544 while not (@isWaiting or @previewInfo.waiting) and @pointer < @object.commands.length and @isRunning
545 @executeCommand(@pointer)
546
547 @previewInfo.executedCommands++
548
549 if @previewInfo.executedCommands > 500
550 @previewInfo.executedCommands = 0
551 @isWaiting = yes
552 @waitCounter = 1
553 else
554 while not (@isWaiting or @previewInfo.waiting) and @pointer < @object.commands.length and @isRunning
555 @executeCommand(@pointer)
556
557
558 if @pointer >= @object.commands.length and not @isWaiting
559 if @repeat
560 @start()
561 else if @isRunning
562 @isRunning = no
563 if @onFinish? then @onFinish(this)
564
565
566
567
568 ###*
569 * Assigns the correct command-function to the specified command-object if
570 * necessary.
571 *
572 * @method assignCommand
573 ###
574 assignCommand: (command) ->
575 switch command.id
576 when "gs.Idle" then command.execute = @commandIdle
577 when "gs.StartTimer" then command.execute = @commandStartTimer
578 when "gs.PauseTimer" then command.execute = @commandPauseTimer
579 when "gs.ResumeTimer" then command.execute = @commandResumeTimer
580 when "gs.StopTimer" then command.execute = @commandStopTimer
581 when "gs.WaitCommand" then command.execute = @commandWait
582 when "gs.LoopCommand" then command.execute = @commandLoop
583 when "gs.LoopForInList" then command.execute = @commandLoopForInList
584 when "gs.BreakLoopCommand" then command.execute = @commandBreakLoop
585 when "gs.Comment" then command.execute = -> 0
586 when "gs.EmptyCommand" then command.execute = -> 0
587 when "gs.ListAdd" then command.execute = @commandListAdd
588 when "gs.ListPop" then command.execute = @commandListPop
589 when "gs.ListShift" then command.execute = @commandListShift
590 when "gs.ListRemoveAt" then command.execute = @commandListRemoveAt
591 when "gs.ListInsertAt" then command.execute = @commandListInsertAt
592 when "gs.ListValueAt" then command.execute = @commandListValueAt
593 when "gs.ListClear" then command.execute = @commandListClear
594 when "gs.ListShuffle" then command.execute = @commandListShuffle
595 when "gs.ListSort" then command.execute = @commandListSort
596 when "gs.ListIndexOf" then command.execute = @commandListIndexOf
597 when "gs.ListSet" then command.execute = @commandListSet
598 when "gs.ListCopy" then command.execute = @commandListCopy
599 when "gs.ListLength" then command.execute = @commandListLength
600 when "gs.ListJoin" then command.execute = @commandListJoin
601 when "gs.ListFromText" then command.execute = @commandListFromText
602 when "gs.ResetVariables" then command.execute = @commandResetVariables
603 when "gs.ChangeVariableDomain" then command.execute = @commandChangeVariableDomain
604 when "gs.ChangeNumberVariables" then command.execute = @commandChangeNumberVariables
605 when "gs.ChangeDecimalVariables" then command.execute = @commandChangeDecimalVariables
606 when "gs.ChangeBooleanVariables" then command.execute = @commandChangeBooleanVariables
607 when "gs.ChangeStringVariables" then command.execute = @commandChangeStringVariables
608 when "gs.CheckSwitch" then command.execute = @commandCheckSwitch
609 when "gs.CheckNumberVariable" then command.execute = @commandCheckNumberVariable
610 when "gs.CheckTextVariable" then command.execute = @commandCheckTextVariable
611 when "gs.Condition" then command.execute = @commandCondition
612 when "gs.ConditionElse" then command.execute = @commandConditionElse
613 when "gs.ConditionElseIf" then command.execute = @commandConditionElseIf
614 when "gs.Label" then command.execute = @commandLabel
615 when "gs.JumpToLabel" then command.execute = @commandJumpToLabel
616 when "gs.SetMessageArea" then command.execute = @commandSetMessageArea
617 when "gs.ShowMessage" then command.execute = @commandShowMessage
618 when "gs.ShowPartialMessage" then command.execute = @commandShowPartialMessage
619 when "gs.MessageFading" then command.execute = @commandMessageFading
620 when "gs.MessageSettings" then command.execute = @commandMessageSettings
621 when "gs.CreateMessageArea" then command.execute = @commandCreateMessageArea
622 when "gs.EraseMessageArea" then command.execute = @commandEraseMessageArea
623 when "gs.SetTargetMessage" then command.execute = @commandSetTargetMessage
624 when "vn.MessageBoxDefaults" then command.execute = @commandMessageBoxDefaults
625 when "vn.MessageBoxVisibility" then command.execute = @commandMessageBoxVisibility
626 when "vn.MessageVisibility" then command.execute = @commandMessageVisibility
627 when "vn.BacklogVisibility" then command.execute = @commandBacklogVisibility
628 when "gs.ClearMessage" then command.execute = @commandClearMessage
629 when "gs.ChangeWeather" then command.execute = @commandChangeWeather
630 when "gs.FreezeScreen" then command.execute = @commandFreezeScreen
631 when "gs.ScreenTransition" then command.execute = @commandScreenTransition
632 when "gs.ShakeScreen" then command.execute = @commandShakeScreen
633 when "gs.TintScreen" then command.execute = @commandTintScreen
634 when "gs.FlashScreen" then command.execute = @commandFlashScreen
635 when "gs.ZoomScreen" then command.execute = @commandZoomScreen
636 when "gs.RotateScreen" then command.execute = @commandRotateScreen
637 when "gs.PanScreen" then command.execute = @commandPanScreen
638 when "gs.ScreenEffect" then command.execute = @commandScreenEffect
639 when "gs.ShowVideo" then command.execute = @commandShowVideo
640 when "gs.MoveVideo" then command.execute = @commandMoveVideo
641 when "gs.MoveVideoPath" then command.execute = @commandMoveVideoPath
642 when "gs.TintVideo" then command.execute = @commandTintVideo
643 when "gs.FlashVideo" then command.execute = @commandFlashVideo
644 when "gs.CropVideo" then command.execute = @commandCropVideo
645 when "gs.RotateVideo" then command.execute = @commandRotateVideo
646 when "gs.ZoomVideo" then command.execute = @commandZoomVideo
647 when "gs.BlendVideo" then command.execute = @commandBlendVideo
648 when "gs.MaskVideo" then command.execute = @commandMaskVideo
649 when "gs.VideoEffect" then command.execute = @commandVideoEffect
650 when "gs.VideoMotionBlur" then command.execute = @commandVideoMotionBlur
651 when "gs.VideoDefaults" then command.execute = @commandVideoDefaults
652 when "gs.EraseVideo" then command.execute = @commandEraseVideo
653 when "gs.ShowImageMap" then command.execute = @commandShowImageMap
654 when "gs.EraseImageMap" then command.execute = @commandEraseImageMap
655 when "gs.AddHotspot" then command.execute = @commandAddHotspot
656 when "gs.EraseHotspot" then command.execute = @commandEraseHotspot
657 when "gs.ChangeHotspotState" then command.execute = @commandChangeHotspotState
658 when "gs.ShowPicture" then command.execute = @commandShowPicture
659 when "gs.MovePicture" then command.execute = @commandMovePicture
660 when "gs.MovePicturePath" then command.execute = @commandMovePicturePath
661 when "gs.TintPicture" then command.execute = @commandTintPicture
662 when "gs.FlashPicture" then command.execute = @commandFlashPicture
663 when "gs.CropPicture" then command.execute = @commandCropPicture
664 when "gs.RotatePicture" then command.execute = @commandRotatePicture
665 when "gs.ZoomPicture" then command.execute = @commandZoomPicture
666 when "gs.BlendPicture" then command.execute = @commandBlendPicture
667 when "gs.ShakePicture" then command.execute = @commandShakePicture
668 when "gs.MaskPicture" then command.execute = @commandMaskPicture
669 when "gs.PictureEffect" then command.execute = @commandPictureEffect
670 when "gs.PictureMotionBlur" then command.execute = @commandPictureMotionBlur
671 when "gs.PictureDefaults" then command.execute = @commandPictureDefaults
672 when "gs.PlayPictureAnimation" then command.execute = @commandPlayPictureAnimation
673 when "gs.ErasePicture" then command.execute = @commandErasePicture
674 when "gs.InputNumber" then command.execute = @commandInputNumber
675 when "vn.Choice" then command.execute = @commandShowChoice
676 when "vn.ChoiceTimer" then command.execute = @commandChoiceTimer
677 when "vn.ShowChoices" then command.execute = @commandShowChoices
678 when "vn.UnlockCG" then command.execute = @commandUnlockCG
679 when "vn.L2DJoinScene" then command.execute = @commandL2DJoinScene
680 when "vn.L2DExitScene" then command.execute = @commandL2DExitScene
681 when "vn.L2DMotion" then command.execute = @commandL2DMotion
682 when "vn.L2DMotionGroup" then command.execute = @commandL2DMotionGroup
683 when "vn.L2DExpression" then command.execute = @commandL2DExpression
684 when "vn.L2DMove" then command.execute = @commandL2DMove
685 when "vn.L2DParameter" then command.execute = @commandL2DParameter
686 when "vn.L2DSettings" then command.execute = @commandL2DSettings
687 when "vn.L2DDefaults" then command.execute = @commandL2DDefaults
688 when "vn.CharacterJoinScene" then command.execute = @commandCharacterJoinScene
689 when "vn.CharacterExitScene" then command.execute = @commandCharacterExitScene
690 when "vn.CharacterChangeExpression" then command.execute = @commandCharacterChangeExpression
691 when "vn.CharacterSetParameter" then command.execute = @commandCharacterSetParameter
692 when "vn.CharacterGetParameter" then command.execute = @commandCharacterGetParameter
693 when "vn.CharacterDefaults" then command.execute = @commandCharacterDefaults
694 when "vn.CharacterEffect" then command.execute = @commandCharacterEffect
695 when "vn.ZoomCharacter" then command.execute = @commandZoomCharacter
696 when "vn.RotateCharacter" then command.execute = @commandRotateCharacter
697 when "vn.BlendCharacter" then command.execute = @commandBlendCharacter
698 when "vn.ShakeCharacter" then command.execute = @commandShakeCharacter
699 when "vn.MaskCharacter" then command.execute = @commandMaskCharacter
700 when "vn.MoveCharacter" then command.execute = @commandMoveCharacter
701 when "vn.MoveCharacterPath" then command.execute = @commandMoveCharacterPath
702 when "vn.FlashCharacter" then command.execute = @commandFlashCharacter
703 when "vn.TintCharacter" then command.execute = @commandTintCharacter
704 when "vn.CharacterMotionBlur" then command.execute = @commandCharacterMotionBlur
705 when "vn.ChangeBackground" then command.execute = @commandChangeBackground
706 when "vn.ShakeBackground" then command.execute = @commandShakeBackground
707 when "vn.ScrollBackground" then command.execute = @commandScrollBackground
708 when "vn.ScrollBackgroundTo" then command.execute = @commandScrollBackgroundTo
709 when "vn.ScrollBackgroundPath" then command.execute = @commandScrollBackgroundPath
710 when "vn.ZoomBackground" then command.execute = @commandZoomBackground
711 when "vn.RotateBackground" then command.execute = @commandRotateBackground
712 when "vn.TintBackground" then command.execute = @commandTintBackground
713 when "vn.BlendBackground" then command.execute = @commandBlendBackground
714 when "vn.MaskBackground" then command.execute = @commandMaskBackground
715 when "vn.BackgroundMotionBlur" then command.execute = @commandBackgroundMotionBlur
716 when "vn.BackgroundEffect" then command.execute = @commandBackgroundEffect
717 when "vn.BackgroundDefaults" then command.execute = @commandBackgroundDefaults
718 when "vn.ChangeScene" then command.execute = @commandChangeScene
719 when "vn.ReturnToPreviousScene" then command.execute = @commandReturnToPreviousScene
720 when "vn.CallScene" then command.execute = @commandCallScene
721 when "vn.SwitchToLayout" then command.execute = @commandSwitchToLayout
722 when "gs.ChangeTransition" then command.execute = @commandChangeTransition
723 when "gs.ChangeWindowSkin" then command.execute = @commandChangeWindowSkin
724 when "gs.ChangeScreenTransitions" then command.execute = @commandChangeScreenTransitions
725 when "vn.UIAccess" then command.execute = @commandUIAccess
726 when "gs.PlayVideo" then command.execute = @commandPlayVideo
727 when "gs.PlayMusic" then command.execute = @commandPlayMusic
728 when "gs.StopMusic" then command.execute = @commandStopMusic
729 when "gs.PlaySound" then command.execute = @commandPlaySound
730 when "gs.StopSound" then command.execute = @commandStopSound
731 when "gs.PauseMusic" then command.execute = @commandPauseMusic
732 when "gs.ResumeMusic" then command.execute = @commandResumeMusic
733 when "gs.AudioDefaults" then command.execute = @commandAudioDefaults
734 when "gs.EndCommonEvent" then command.execute = @commandEndCommonEvent
735 when "gs.ResumeCommonEvent" then command.execute = @commandResumeCommonEvent
736 when "gs.CallCommonEvent" then command.execute = @commandCallCommonEvent
737 when "gs.ChangeTimer" then command.execute = @commandChangeTimer
738 when "gs.ShowText" then command.execute = @commandShowText
739 when "gs.RefreshText" then command.execute = @commandRefreshText
740 when "gs.TextMotionBlur" then command.execute = @commandTextMotionBlur
741 when "gs.MoveText" then command.execute = @commandMoveText
742 when "gs.MoveTextPath" then command.execute = @commandMoveTextPath
743 when "gs.RotateText" then command.execute = @commandRotateText
744 when "gs.ZoomText" then command.execute = @commandZoomText
745 when "gs.BlendText" then command.execute = @commandBlendText
746 when "gs.ColorText" then command.execute = @commandColorText
747 when "gs.EraseText" then command.execute = @commandEraseText
748 when "gs.TextEffect" then command.execute = @commandTextEffect
749 when "gs.TextDefaults" then command.execute = @commandTextDefaults
750 when "gs.ChangeTextSettings" then command.execute = @commandChangeTextSettings
751 when "gs.InputText" then command.execute = @commandInputText
752 when "gs.InputName" then command.execute = @commandInputName
753 when "gs.SavePersistentData" then command.execute = @commandSavePersistentData
754 when "gs.SaveSettings" then command.execute = @commandSaveSettings
755 when "gs.PrepareSaveGame" then command.execute = @commandPrepareSaveGame
756 when "gs.SaveGame" then command.execute = @commandSaveGame
757 when "gs.LoadGame" then command.execute = @commandLoadGame
758 when "gs.GetInputData" then command.execute = @commandGetInputData
759 when "gs.WaitForInput" then command.execute = @commandWaitForInput
760 when "gs.ChangeObjectDomain" then command.execute = @commandChangeObjectDomain
761 when "vn.GetGameData" then command.execute = @commandGetGameData
762 when "vn.SetGameData" then command.execute = @commandSetGameData
763 when "vn.GetObjectData" then command.execute = @commandGetObjectData
764 when "vn.SetObjectData" then command.execute = @commandSetObjectData
765 when "vn.ChangeSounds" then command.execute = @commandChangeSounds
766 when "vn.ChangeColors" then command.execute = @commandChangeColors
767 when "gs.ChangeScreenCursor" then command.execute = @commandChangeScreenCursor
768 when "gs.ResetGlobalData" then command.execute = @commandResetGlobalData
769 when "gs.Script" then command.execute = @commandScript
770
771 ###*
772 * Executes the command at the specified index and increases the command-pointer.
773 *
774 * @method executeCommand
775 ###
776 executeCommand: (index) ->
777 @command = @object.commands[index]
778
779 if @previewData
780 if @previewData.uid and @previewData.uid != @command.uid
781 GameManager.tempSettings.skip = yes
782 GameManager.tempSettings.skipTime = 0
783 else if @pointer < @previewData.pointer
784 GameManager.tempSettings.skip = yes
785 GameManager.tempSettings.skipTime = 0
786 else
787 GameManager.tempSettings.skip = @previewData.settings.animationDisabled
788 GameManager.tempSettings.skipTime = 0
789 @previewInfo.waiting = yes
790
791 gs.GlobalEventManager.emit("previewWaiting")
792 if @previewData.settings.animationDisabled or @previewData.settings.animationTime > 0
793 @previewInfo.timeout = setTimeout (-> Graphics.stopped = yes), (@previewData.settings.animationTime)*1000
794
795 if @command.execute?
796 @command.interpreter = this
797 @command.execute() if @command.indent == @indent
798 @pointer++
799
800 @command = @object.commands[@pointer]
801 if @command?
802 indent = @command.indent
803 else
804 indent = @indent
805 while indent > 0 and (not @loops[indent]?)
806 indent--
807
808 if indent < @indent
809 @indent = indent
810 if @loops[@indent]?.condition()
811 @pointer = @loops[@indent].pointer
812 @command = @object.commands[@pointer]
813 @command.interpreter = this
814 else
815 @loops[@indent] = null
816 else
817 @assignCommand(@command)
818
819 if @command.execute?
820 @command.interpreter = this
821 @command.execute() if @command.indent == @indent
822 @pointer++
823 @command = @object.commands[@pointer]
824 if @command?
825 indent = @command.indent
826 else
827 indent = @indent
828 while indent > 0 and (not @loops[indent]?)
829 indent--
830
831 if indent < @indent
832 @indent = indent
833 if @loops[@indent]?.condition()
834 @pointer = @loops[@indent].pointer
835 @command = @object.commands[@pointer]
836 @command.interpreter = this
837 else
838 @loops[@indent] = null
839 else
840 @pointer++
841 ###*
842 * Skips all commands until a command with the specified indent-level is
843 * found. So for example: To jump from a Condition-Command to the next
844 * Else-Command just pass the indent-level of the Condition/Else command.
845 *
846 * @method skip
847 * @param {number} indent - The indent-level.
848 * @param {boolean} backward - If true the skip runs backward.
849 ###
850 skip: (indent, backward) ->
851 if backward
852 @pointer--
853 while @pointer > 0 and @object.commands[@pointer].indent != indent
854 @pointer--
855 else
856 @pointer++
857 while @pointer < @object.commands.length and @object.commands[@pointer].indent != indent
858 @pointer++
859
860 ###*
861 * Halts the interpreter for the specified amount of time. An optionally
862 * callback function can be passed which is called when the time is up.
863 *
864 * @method wait
865 * @param {number} time - The time to wait
866 * @param {gs.Callback} callback - Called if the wait time is up.
867 ###
868 wait: (time, callback) ->
869 @isWaiting = yes
870 @waitCounter = time
871 @waitCallback = callback
872
873 ###*
874 * Checks if the command at the specified pointer-index is a game message
875 * related command.
876 *
877 * @method isMessageCommand
878 * @param {number} pointer - The pointer/index.
879 * @param {Object[]} commands - The list of commands to check.
880 * @return {boolean} <b>true</b> if its a game message related command. Otherwise <b>false</b>.
881 ###
882 isMessageCommand: (pointer, commands) ->
883 result = yes
884 if pointer >= commands.length or (commands[pointer].id != "gs.InputNumber" and
885 commands[pointer].id != "vn.Choice" and
886 commands[pointer].id != "gs.InputText" and
887 commands[pointer].id != "gs.InputName")
888 result = no
889 return result
890
891 ###*
892 * Checks if the command at the specified pointer-index asks for user-input like
893 * the Input Number or Input Text command.
894 *
895 * @method isInputDataCommand
896 * @param {number} pointer - The pointer/index.
897 * @param {Object[]} commands - The list of commands to check.
898 * @return {boolean} <b>true</b> if its an input-data command. Otherwise <b>false</b>
899 ###
900 isInputDataCommand: (pointer, commands) ->
901 pointer < commands.length and (
902 commands[pointer].id == "gs.InputNumber" or
903 commands[pointer].id == "gs.InputText" or
904 commands[pointer].id == "vn.Choice" or
905 commands[pointer].id == "vn.ShowChoices"
906 )
907
908 ###*
909 * Checks if a game message is currently running by another interpreter like a
910 * common-event interpreter.
911 *
912 * @method isProcessingMessageInOtherContext
913 * @return {boolean} <b>true</b> a game message is running in another context. Otherwise <b>false</b>
914 ###
915 isProcessingMessageInOtherContext: ->
916 result = no
917 gm = GameManager
918 s = SceneManager.scene
919
920 result =
921 (s.inputNumberWindow? and s.inputNumberWindow.visible and s.inputNumberWindow.executionContext != @context) or
922 (s.inputTextWindow? and s.inputTextWindow.active and s.inputTextWindow.executionContext != @context)
923
924 return result
925
926 ###*
927 * If a game message is currently running by an other interpreter like a common-event
928 * interpreter, this method trigger a wait until the other interpreter is finished
929 * with the game message.
930 *
931 * @method waitForMessage
932 * @return {boolean} <b>true</b> a game message is running in another context. Otherwise <b>false</b>
933 ###
934 waitForMessage: ->
935 @isWaitingForMessage = yes
936 @isWaiting = yes
937 @pointer--
938
939
940 ###*
941 * Gets the value the number variable at the specified index.
942 *
943 * @method numberValueAtIndex
944 * @param {number} scope - The variable's scope.
945 * @param {number} index - The index of the variable to get the value from.
946 * @return {Number} The value of the variable.
947 ###
948 numberValueAtIndex: (scope, index, domain) -> GameManager.variableStore.numberValueAtIndex(scope, index, domain)
949
950 ###*
951 * Gets the value of a (possible) number variable. If a constant number value is specified, this method
952 * does nothing an just returns that constant value. That's to make it more comfortable to just pass a value which
953 * can be calculated by variable but also be just a constant value.
954 *
955 * @method numberValueOf
956 * @param {number|Object} object - A number variable or constant number value.
957 * @return {Number} The value of the variable.
958 ###
959 numberValueOf: (object) -> GameManager.variableStore.numberValueOf(object)
960
961 ###*
962 * It does the same like <b>numberValueOf</b> with one difference: If the specified object
963 * is a variable, it's value is considered as a duration-value in milliseconds and automatically converted
964 * into frames.
965 *
966 * @method durationValueOf
967 * @param {number|Object} object - A number variable or constant number value.
968 * @return {Number} The value of the variable.
969 ###
970 durationValueOf: (object) ->
971 if object and object.index?
972 Math.round(GameManager.variableStore.numberValueOf(object) / 1000 * Graphics.frameRate)
973 else
974 Math.round(GameManager.variableStore.numberValueOf(object))
975
976 ###*
977 * Gets a position ({x, y}) for the specified predefined object position configured in
978 * Database - System.
979 *
980 * @method predefinedObjectPosition
981 * @param {number} position - The index/ID of the predefined object position to set.
982 * @param {gs.Object_Base} object - The game object to set the position for.
983 * @param {Object} params - The params object of the scene command.
984 * @return {Object} The position {x, y}.
985 ###
986 predefinedObjectPosition: (position, object, params) ->
987 objectPosition = RecordManager.system.objectPositions[position]
988 if !objectPosition then return { x: 0, y: 0 }
989
990 return objectPosition.func.call(null, object, params) || { x: 0, y: 0 }
991
992 ###*
993 * Sets the value of a variable.
994 *
995 * @method setValueToVariable
996 * @param {number} variable - The variable to set.
997 * @param {number} variableType - The type of the variable to set.
998 * @param {number} value - The value to set the variable to. Depends on the variable type.
999 ###
1000 setValueToVariable: (variable, variableType, value) ->
1001 switch variableType
1002 when 0 # Number
1003 GameManager.variableStore.setNumberValueTo(variable, value)
1004 when 1 # Switch
1005 GameManager.variableStore.setBooleanValueTo(variable, value)
1006 when 2 # Text
1007 GameManager.variableStore.setStringValueTo(variable, value)
1008 when 3 # List
1009 GameManager.variableStore.setListObjectTo(variable, value)
1010
1011 ###*
1012 * Sets the value of a number variable at the specified index.
1013 *
1014 * @method setNumberValueAtIndex
1015 * @param {number} scope - The variable's scope.
1016 * @param {number} index - The index of the variable to set.
1017 * @param {number} value - The number value to set the variable to.
1018 ###
1019 setNumberValueAtIndex: (scope, index, value, domain) -> GameManager.variableStore.setNumberValueAtIndex(scope, index, value, domain)
1020
1021 ###*
1022 * Sets the value of a number variable.
1023 *
1024 * @method setNumberValueTo
1025 * @param {number} variable - The variable to set.
1026 * @param {number} value - The number value to set the variable to.
1027 ###
1028 setNumberValueTo: (variable, value) -> GameManager.variableStore.setNumberValueTo(variable, value)
1029
1030 ###*
1031 * Sets the value of a list variable.
1032 *
1033 * @method setListObjectTo
1034 * @param {Object} variable - The variable to set.
1035 * @param {Object} value - The list object to set the variable to.
1036 ###
1037 setListObjectTo: (variable, value) -> GameManager.variableStore.setListObjectTo(variable, value)
1038
1039 ###*
1040 * Sets the value of a boolean/switch variable.
1041 *
1042 * @method setBooleanValueTo
1043 * @param {Object} variable - The variable to set.
1044 * @param {boolean} value - The boolean value to set the variable to.
1045 ###
1046 setBooleanValueTo: (variable, value) -> GameManager.variableStore.setBooleanValueTo(variable, value)
1047
1048 ###*
1049 * Sets the value of a number variable at the specified index.
1050 *
1051 * @method setBooleanValueAtIndex
1052 * @param {number} scope - The variable's scope.
1053 * @param {number} index - The index of the variable to set.
1054 * @param {boolean} value - The boolean value to set the variable to.
1055 ###
1056 setBooleanValueAtIndex: (scope, index, value, domain) -> GameManager.variableStore.setBooleanValueAtIndex(scope, index, value, domain)
1057
1058 ###*
1059 * Sets the value of a string/text variable.
1060 *
1061 * @method setStringValueTo
1062 * @param {Object} variable - The variable to set.
1063 * @param {string} value - The string/text value to set the variable to.
1064 ###
1065 setStringValueTo: (variable, value) -> GameManager.variableStore.setStringValueTo(variable, value)
1066
1067 ###*
1068 * Sets the value of the string variable at the specified index.
1069 *
1070 * @method setStringValueAtIndex
1071 * @param {number} scope - The variable scope.
1072 * @param {number} index - The variable's index.
1073 * @param {string} value - The value to set.
1074 ###
1075 setStringValueAtIndex: (scope, index, value, domain) -> GameManager.variableStore.setStringValueAtIndex(scope, index, value, domain)
1076
1077 ###*
1078 * Gets the value of a (possible) string variable. If a constant string value is specified, this method
1079 * does nothing an just returns that constant value. That's to make it more comfortable to just pass a value which
1080 * can be calculated by variable but also be just a constant value.
1081 *
1082 * @method stringValueOf
1083 * @param {string|Object} object - A string variable or constant string value.
1084 * @return {string} The value of the variable.
1085 ###
1086 stringValueOf: (object) -> GameManager.variableStore.stringValueOf(object)
1087
1088 ###*
1089 * Gets the value of the string variable at the specified index.
1090 *
1091 * @method stringValueAtIndex
1092 * @param {number} scope - The variable's scope.
1093 * @param {number} index - The index of the variable to get the value from.
1094 * @return {string} The value of the variable.
1095 ###
1096 stringValueAtIndex: (scope, index, domain) -> GameManager.variableStore.stringValueAtIndex(scope, index, domain)
1097
1098 ###*
1099 * Gets the value of a (possible) boolean variable. If a constant boolean value is specified, this method
1100 * does nothing an just returns that constant value. That's to make it more comfortable to just pass a value which
1101 * can be calculated by variable but also be just a constant value.
1102 *
1103 * @method booleanValueOf
1104 * @param {boolean|Object} object - A boolean variable or constant boolean value.
1105 * @return {boolean} The value of the variable.
1106 ###
1107 booleanValueOf: (object) -> GameManager.variableStore.booleanValueOf(object)
1108
1109 ###*
1110 * Gets the value of the boolean variable at the specified index.
1111 *
1112 * @method booleanValueAtIndex
1113 * @param {number} scope - The variable's scope.
1114 * @param {number} index - The index of the variable to get the value from.
1115 * @return {string} The value of the variable.
1116 ###
1117 booleanValueAtIndex: (scope, index, domain) -> GameManager.variableStore.booleanValueAtIndex(scope, index, domain)
1118
1119 ###*
1120 * Gets the value of a (possible) list variable.
1121 *
1122 * @method listObjectOf
1123 * @param {Object} object - A list variable.
1124 * @return {Object} The value of the list variable.
1125 ###
1126 listObjectOf: (object) -> GameManager.variableStore.listObjectOf(object)
1127
1128 ###*
1129 * Compares two object using the specified operation and returns the result.
1130 *
1131 * @method compare
1132 * @param {Object} a - Object A.
1133 * @param {Object} b - Object B.
1134 * @param {number} operation - The compare-operation to compare Object A with Object B.
1135 * <ul>
1136 * <li>0 = Equal To</li>
1137 * <li>1 = Not Equal To</li>
1138 * <li>2 = Greater Than</li>
1139 * <li>3 = Greater or Equal To</li>
1140 * <li>4 = Less Than</li>
1141 * <li>5 = Less or Equal To</li>
1142 * </ul>
1143 * @return {boolean} The comparison result.
1144 ###
1145 compare: (a, b, operation) ->
1146 switch operation
1147 when 0 then return `a == b`
1148 when 1 then return `a != b`
1149 when 2 then return a > b
1150 when 3 then return a >= b
1151 when 4 then return a < b
1152 when 5 then return a <= b
1153
1154 ###*
1155 * Changes number variables and allows decimal values such as 0.5 too.
1156 *
1157 * @method changeDecimalVariables
1158 * @param {Object} params - Input params from the command
1159 * @param {Object} roundMethod - The result of the operation will be rounded using the specified method.
1160 * <ul>
1161 * <li>0 = None. The result will not be rounded.</li>
1162 * <li>1 = Commercially</li>
1163 * <li>2 = Round Up</li>
1164 * <li>3 = Round Down</li>
1165 * </ul>
1166 ###
1167 changeDecimalVariables: (params, roundMethod) ->
1168 source = 0
1169 roundFunc = null
1170
1171 switch roundMethod
1172 when 0 then roundFunc = (value) -> value
1173 when 1 then roundFunc = (value) -> Math.round(value)
1174 when 2 then roundFunc = (value) -> Math.ceil(value)
1175 when 3 then roundFunc = (value) -> Math.floor(value)
1176
1177 switch params.source
1178 when 0 # Constant Value / Variable Value
1179 source = @numberValueOf(params.sourceValue)
1180 when 1 # Random
1181 start = @numberValueOf(params.sourceRandom.start)
1182 end = @numberValueOf(params.sourceRandom.end)
1183 diff = end - start
1184 source = Math.floor(start + Math.random() * (diff+1))
1185 when 2 # Pointer
1186 source = @numberValueAtIndex(params.sourceScope, @numberValueOf(params.sourceReference)-1, params.sourceReferenceDomain)
1187 when 3 # Game Data
1188 source = @numberValueOfGameData(params.sourceValue1)
1189 when 4 # Database Data
1190 source = @numberValueOfDatabaseData(params.sourceValue1)
1191
1192 switch params.target
1193 when 0 # Variable
1194 switch params.operation
1195 when 0 # Set
1196 @setNumberValueTo(params.targetVariable, roundFunc(source))
1197 when 1 # Add
1198 @setNumberValueTo(params.targetVariable, roundFunc(@numberValueOf(params.targetVariable) + source) )
1199 when 2 # Sub
1200 @setNumberValueTo(params.targetVariable, roundFunc(@numberValueOf(params.targetVariable) - source) )
1201 when 3 # Mul
1202 @setNumberValueTo(params.targetVariable, roundFunc(@numberValueOf(params.targetVariable) * source))
1203 when 4 # Div
1204 @setNumberValueTo(params.targetVariable, roundFunc(@numberValueOf(params.targetVariable) / source))
1205 when 5 # Mod
1206 @setNumberValueTo(params.targetVariable, @numberValueOf(params.targetVariable) % source)
1207 when 1 # Range
1208 scope = params.targetScope
1209 start = params.targetRange.start-1
1210 end = params.targetRange.end-1
1211 for i in [start..end]
1212 switch params.operation
1213 when 0 # Set
1214 @setNumberValueAtIndex(scope, i, roundFunc(source))
1215 when 1 # Add
1216 @setNumberValueAtIndex(scope, i, roundFunc(@numberValueAtIndex(scope, i) + source))
1217 when 2 # Sub
1218 @setNumberValueAtIndex(scope, i, roundFunc(@numberValueAtIndex(scope, i) - source))
1219 when 3 # Mul
1220 @setNumberValueAtIndex(scope, i, roundFunc(@numberValueAtIndex(scope, i) * source))
1221 when 4 # Div
1222 @setNumberValueAtIndex(scope, i, roundFunc(@numberValueAtIndex(scope, i) / source))
1223 when 5 # Mod
1224 @setNumberValueAtIndex(scope, i, @numberValueAtIndex(scope, i) % source)
1225 when 2 # Reference
1226 index = @numberValueOf(params.targetReference) - 1
1227 switch params.operation
1228 when 0 # Set
1229 @setNumberValueAtIndex(params.targetScope, index, roundFunc(source), params.targetReferenceDomain)
1230 when 1 # Add
1231 @setNumberValueAtIndex(params.targetScope, index, roundFunc(@numberValueAtIndex(params.targetScope, index, params.targetReferenceDomain) + source), params.targetReferenceDomain)
1232 when 2 # Sub
1233 @setNumberValueAtIndex(params.targetScope, index, roundFunc(@numberValueAtIndex(params.targetScope, index, params.targetReferenceDomain) - source), params.targetReferenceDomain)
1234 when 3 # Mul
1235 @setNumberValueAtIndex(params.targetScope, index, roundFunc(@numberValueAtIndex(params.targetScope, index, params.targetReferenceDomain) * source), params.targetReferenceDomain)
1236 when 4 # Div
1237 @setNumberValueAtIndex(params.targetScope, index, roundFunc(@numberValueAtIndex(params.targetScope, index, params.targetReferenceDomain) / source), params.targetReferenceDomain)
1238 when 5 # Mod
1239 @setNumberValueAtIndex(params.targetScope, index, @numberValueAtIndex(params.targetScope, index, params.targetReferenceDomain) % source, params.targetReferenceDomain)
1240
1241 return null
1242
1243 ###*
1244 * Shakes a game object.
1245 *
1246 * @method shakeObject
1247 * @param {gs.Object_Base} object - The game object to shake.
1248 * @return {Object} A params object containing additional info about the shake-animation.
1249 ###
1250 shakeObject: (object, params) ->
1251 duration = Math.max(Math.round(@durationValueOf(params.duration)), 2)
1252 easing = gs.Easings.fromObject(params.easing)
1253
1254 object.animator.shake({ x: @numberValueOf(params.range.x), y: @numberValueOf(params.range.y) }, @numberValueOf(params.speed) / 100, duration, easing)
1255
1256 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1257 @isWaiting = yes
1258 @waitCounter = duration
1259
1260 ###*
1261 * Lets the interpreter wait for the completion of a running operation like an animation, etc.
1262 *
1263 * @method waitForCompletion
1264 * @param {gs.Object_Base} object - The game object the operation is executed on. Can be <b>null</b>.
1265 * @return {Object} A params object containing additional info.
1266 ###
1267 waitForCompletion: (object, params) ->
1268 duration = @durationValueOf(params.duration)
1269 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1270 @isWaiting = yes
1271 @waitCounter = duration
1272
1273 ###*
1274 * Erases a game object.
1275 *
1276 * @method eraseObject
1277 * @param {gs.Object_Base} object - The game object to erase.
1278 * @return {Object} A params object containing additional info.
1279 ###
1280 eraseObject: (object, params, callback) ->
1281 easing = gs.Easings.fromObject(params.easing)
1282 duration = @durationValueOf(params.duration)
1283 object.animator.disappear(params.animation, easing, duration, (sender) =>
1284 sender.dispose()
1285 callback?(sender)
1286 )
1287
1288 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1289 @isWaiting = yes
1290 @waitCounter = duration
1291
1292 ###*
1293 * Shows a game object on screen.
1294 *
1295 * @method showObject
1296 * @param {gs.Object_Base} object - The game object to show.
1297 * @param {gs.Point} position - The position where the game object should be shown.
1298 * @param {Object} A params object containing additional info.
1299 ###
1300 showObject: (object, position, params) ->
1301 x = @numberValueOf(position.x)
1302 y = @numberValueOf(position.y)
1303 easing = gs.Easings.fromObject(params.easing)
1304 duration = @durationValueOf(params.duration)
1305
1306 object.animator.appear(x, y, params.animation, easing, duration)
1307
1308 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1309 @isWaiting = yes
1310 @waitCounter = duration
1311
1312
1313 ###*
1314 * Moves a game object.
1315 *
1316 * @method moveObject
1317 * @param {gs.Object_Base} object - The game object to move.
1318 * @param {gs.Point} position - The position to move the game object to.
1319 * @param {Object} A params object containing additional info.
1320 ###
1321 moveObject: (object, position, params) ->
1322 if params.positionType == 0
1323 p = @predefinedObjectPosition(params.predefinedPositionId, object, params)
1324 x = p.x
1325 y = p.y
1326 else
1327 x = @numberValueOf(position.x)
1328 y = @numberValueOf(position.y)
1329
1330 easing = gs.Easings.fromObject(params.easing)
1331 duration = @durationValueOf(params.duration)
1332
1333 zoom = object.zoom
1334 if object.anchor.x != 0 and object.anchor.y != 0
1335 bitmap = object.bitmap
1336 if bitmap?
1337 x += (bitmap.width*zoom.x-bitmap.width) * object.anchor.x
1338 y += (bitmap.height*zoom.y-bitmap.height) * object.anchor.y
1339
1340 object.animator.moveTo(x, y, duration, easing)
1341
1342 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1343 @isWaiting = yes
1344 @waitCounter = duration
1345
1346 ###*
1347 * Moves a game object along a path.
1348 *
1349 * @method moveObjectPath
1350 * @param {gs.Object_Base} object - The game object to move.
1351 * @param {Object} path - The path to move the game object along.
1352 * @param {Object} A params object containing additional info.
1353 ###
1354 moveObjectPath: (object, path, params) ->
1355 easing = gs.Easings.fromObject(params.easing)
1356 duration = @durationValueOf(params.duration)
1357 object.animator.movePath(path.data, params.loopType, duration, easing, path.effects?.data)
1358
1359 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1360 @isWaiting = yes
1361 @waitCounter = duration
1362
1363 ###*
1364 * Scrolls a scrollable game object along a path.
1365 *
1366 * @method scrollObjectPath
1367 * @param {gs.Object_Base} object - The game object to scroll.
1368 * @param {Object} path - The path to scroll the game object along.
1369 * @param {Object} A params object containing additional info.
1370 ###
1371 scrollObjectPath: (object, path, params) ->
1372 easing = gs.Easings.fromObject(params.easing)
1373 duration = @durationValueOf(params.duration)
1374 object.animator.scrollPath(path, params.loopType, duration, easing)
1375
1376 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1377 @isWaiting = yes
1378 @waitCounter = duration
1379
1380 ###*
1381 * Zooms/Scales a game object.
1382 *
1383 * @method zoomObject
1384 * @param {gs.Object_Base} object - The game object to zoom.
1385 * @param {Object} A params object containing additional info.
1386 ###
1387 zoomObject: (object, params) ->
1388 easing = gs.Easings.fromObject(params.easing)
1389 duration = @durationValueOf(params.duration)
1390 object.animator.zoomTo(@numberValueOf(params.zooming.x) / 100, @numberValueOf(params.zooming.y) / 100, duration, easing)
1391
1392 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1393 @isWaiting = yes
1394 @waitCounter = duration
1395
1396 ###*
1397 * Rotates a game object.
1398 *
1399 * @method rotateObject
1400 * @param {gs.Object_Base} object - The game object to rotate.
1401 * @param {Object} A params object containing additional info.
1402 ###
1403 rotateObject: (object, params) ->
1404 easing = gs.Easings.fromObject(params.easing)
1405 duration = @durationValueOf(params.duration)
1406
1407
1408 easing = gs.Easings.fromObject(params.easing)
1409
1410 #if GameManager.tempSettings.skip
1411 # actualDuration = @durationValueOf(@params.duration)
1412 # duration = @durationValueOf(@duration)
1413 # speed = @numberValueOf(@params.speed) / 100
1414 # speed = Math.round(duration / (actualDuration||1) * speed)
1415 # picture.animator.rotate(@params.direction, speed, actualDuration||1, easing)
1416 # duration = actualDuration
1417 #else
1418 # duration = @durationValueOf(params.duration)
1419 # object.animator.rotate(params.direction, @numberValueOf(@params.speed) / 100, duration, easing)
1420
1421 object.animator.rotate(params.direction, @numberValueOf(params.speed) / 100, duration, easing)
1422
1423 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1424 @isWaiting = yes
1425 @waitCounter = duration
1426
1427 ###*
1428 * Blends a game object.
1429 *
1430 * @method blendObject
1431 * @param {gs.Object_Base} object - The game object to blend.
1432 * @param {Object} A params object containing additional info.
1433 ###
1434 blendObject: (object, params) ->
1435 easing = gs.Easings.fromObject(params.easing)
1436 duration = @durationValueOf(params.duration)
1437 object.animator.blendTo(@numberValueOf(params.opacity), duration, easing)
1438
1439 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1440 @isWaiting = yes
1441 @waitCounter = duration
1442
1443 ###*
1444 * Executes a masking-effect on a game object..
1445 *
1446 * @method maskObject
1447 * @param {gs.Object_Base} object - The game object to execute a masking-effect on.
1448 * @param {Object} A params object containing additional info.
1449 ###
1450 maskObject: (object, params) ->
1451 easing = gs.Easings.fromObject(params.easing)
1452
1453 if params.mask.type == 0
1454 object.mask.type = 0
1455 object.mask.ox = @numberValueOf(params.mask.ox)
1456 object.mask.oy = @numberValueOf(params.mask.oy)
1457 if object.mask.source?.videoElement?
1458 object.mask.source.pause()
1459
1460 if params.mask.sourceType == 0
1461 object.mask.source = ResourceManager.getBitmap(ResourceManager.getPath(params.mask.graphic))
1462 else
1463 object.mask.source = ResourceManager.getVideo(ResourceManager.getPath(params.mask.video))
1464 if object.mask.source
1465 object.mask.source.play()
1466 object.mask.source.loop = yes
1467 else
1468 duration = @durationValueOf(params.duration)
1469 mask = Object.flatCopy(params.mask)
1470 mask.value = @numberValueOf(mask.value)
1471 object.animator.maskTo(mask, duration, easing)
1472
1473 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1474 @isWaiting = yes
1475 @waitCounter = duration
1476
1477 ###*
1478 * Tints a game object.
1479 *
1480 * @method tintObject
1481 * @param {gs.Object_Base} object - The game object to tint.
1482 * @param {Object} A params object containing additional info.
1483 ###
1484 tintObject: (object, params) ->
1485 duration = @durationValueOf(params.duration)
1486 easing = gs.Easings.fromObject(params.easing)
1487 object.animator.tintTo(params.tone, duration, easing)
1488
1489 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1490 @isWaiting = yes
1491 @waitCounter = duration
1492
1493 ###*
1494 * Flashes a game object.
1495 *
1496 * @method flashObject
1497 * @param {gs.Object_Base} object - The game object to flash.
1498 * @param {Object} A params object containing additional info.
1499 ###
1500 flashObject: (object, params) ->
1501 duration = @durationValueOf(params.duration)
1502 object.animator.flash(new Color(params.color), duration)
1503
1504 if params.waitForCompletion and not (duration == 0 or @isInstantSkip())
1505 @isWaiting = yes
1506 @waitCounter = duration
1507
1508 ###*
1509 * Cropes a game object.
1510 *
1511 * @method cropObject
1512 * @param {gs.Object_Base} object - The game object to crop.
1513 * @param {Object} A params object containing additional info.
1514 ###
1515 cropObject: (object, params) ->
1516 object.srcRect.x = @numberValueOf(params.x)
1517 object.srcRect.y = @numberValueOf(params.y)
1518 object.srcRect.width = @numberValueOf(params.width)
1519 object.srcRect.height = @numberValueOf(params.height)
1520
1521 object.dstRect.width = @numberValueOf(params.width)
1522 object.dstRect.height = @numberValueOf(params.height)
1523
1524 ###*
1525 * Sets the motion blur settings of a game object.
1526 *
1527 * @method objectMotionBlur
1528 * @param {gs.Object_Base} object - The game object to set the motion blur settings for.
1529 * @param {Object} A params object containing additional info.
1530 ###
1531 objectMotionBlur: (object, params) ->
1532 object.motionBlur.set(params.motionBlur)
1533
1534 ###*
1535 * Enables an effect on a game object.
1536 *
1537 * @method objectEffect
1538 * @param {gs.Object_Base} object - The game object to execute a masking-effect on.
1539 * @param {Object} A params object containing additional info.
1540 ###
1541 objectEffect: (object, params) ->
1542 duration = @durationValueOf(params.duration)
1543 easing = gs.Easings.fromObject(params.easing)
1544
1545 switch params.type
1546 when 0 # Wobble
1547 object.animator.wobbleTo(params.wobble.power / 10000, params.wobble.speed / 100, duration, easing)
1548 wobble = object.effects.wobble
1549 wobble.enabled = params.wobble.power > 0
1550 wobble.vertical = params.wobble.orientation == 0 or params.wobble.orientation == 2
1551 wobble.horizontal = params.wobble.orientation == 1 or params.wobble.orientation == 2
1552 when 1 # Blur
1553 object.animator.blurTo(params.blur.power / 100, duration, easing)
1554 object.effects.blur.enabled = yes
1555 when 2 # Pixelate
1556 object.animator.pixelateTo(params.pixelate.size.width, params.pixelate.size.height, duration, easing)
1557 object.effects.pixelate.enabled = yes
1558
1559 if params.waitForCompletion and duration != 0
1560 @isWaiting = yes
1561 @waitCounter = duration
1562
1563 ###*
1564 * Executes an action for a choice.
1565 *
1566 * @method executeChoiceAction
1567 * @param {Object} action - Action-Data.
1568 * @param {boolean} stateValue - In case of switch-binding, the switch is set to this value.
1569 ###
1570 executeChoiceAction: (action, stateValue) ->
1571 switch action.type
1572 when 4
1573 scene = SceneManager.scene
1574 GameManager.sceneData = GameManager.sceneData = {
1575 uid: uid = action.scene.uid,
1576 pictures: scene.pictureContainer.subObjectsByDomain,
1577 texts: scene.textContainer.subObjectsByDomain,
1578 videos: scene.videoContainer.subObjectsByDomain
1579 }
1580 newScene = new vn.Object_Scene()
1581 newScene.sceneData = uid: action.scene.uid, pictures: scene.pictureContainer.subObjectsByDomain, texts: scene.textContainer.subObjectsByDomain, videos: scene.videoContainer.subObjectsByDomain
1582 SceneManager.switchTo(newScene, no, => @isWaiting = no)
1583 else
1584 @executeAction(action, stateValue, 0)
1585
1586 ###*
1587 * Executes an action like for a hotspot.
1588 *
1589 * @method executeAction
1590 * @param {Object} action - Action-Data.
1591 * @param {boolean} stateValue - In case of switch-binding, the switch is set to this value.
1592 * @param {number} bindValue - A number value which be put into the action's bind-value variable.
1593 ###
1594 executeAction: (action, stateValue, bindValue) ->
1595 switch action.type
1596 when 0 # Jump To Label
1597 if action.labelIndex
1598 @pointer = action.labelIndex
1599 else
1600 @jumpToLabel(action.label)
1601 when 1 # Call Common Event
1602 @callCommonEvent(action.commonEventId, null, @isWaiting)
1603 when 2 # Bind To Switch
1604 domain = GameManager.variableStore.domain
1605 @setBooleanValueTo(action.switch, stateValue)
1606 when 3 # Call Scene
1607 @callScene(action.scene?.uid)
1608 when 4 # Bind Value to Variable
1609 domain = GameManager.variableStore.domain
1610 @setNumberValueTo(action.bindValueVariable, bindValue)
1611 if action.labelIndex
1612 @pointer = action.labelIndex
1613 else
1614 @jumpToLabel(action.label)
1615
1616 ###*
1617 * Calls a common event and returns the sub-interpreter for it.
1618 *
1619 * @method callCommonEvent
1620 * @param {number} id - The ID of the common event to call.
1621 * @param {Object} parameters - Optional common event parameters.
1622 * @param {boolean} wait - Indicates if the interpreter should be stay in waiting-mode even if the sub-interpreter is finished.
1623 ###
1624 callCommonEvent: (id, parameters, wait) ->
1625 commonEvent = GameManager.commonEvents[id]
1626
1627 if commonEvent?
1628 if SceneManager.scene.commonEventContainer.subObjects.indexOf(commonEvent) == -1
1629 SceneManager.scene.commonEventContainer.addObject(commonEvent)
1630 commonEvent.events?.on "finish", gs.CallBack("onCommonEventFinish", this), { waiting: wait }
1631
1632 @subInterpreter = commonEvent.behavior.call(parameters || [], @settings, @context)
1633 #GameManager.variableStore.setupLocalVariables(@subInterpreter.context)
1634 #GameManager.variableStore.setupTempVariables(@subInterpreter.context)
1635 commonEvent.behavior.update()
1636
1637 if @subInterpreter?
1638 @isWaiting = yes
1639 @subInterpreter.settings = @settings
1640 @subInterpreter.start()
1641 @subInterpreter.update()
1642
1643 GameManager.variableStore.setupTempVariables(@context)
1644
1645 ###*
1646 * Calls a scene and returns the sub-interpreter for it.
1647 *
1648 * @method callScene
1649 * @param {String} uid - The UID of the scene to call.
1650 ###
1651 callScene: (uid) ->
1652 sceneDocument = DataManager.getDocument(uid)
1653
1654 if sceneDocument?
1655 @isWaiting = yes
1656 @subInterpreter = new vn.Component_CallSceneInterpreter()
1657 object = { commands: sceneDocument.items.commands }
1658 @subInterpreter.repeat = no
1659 @subInterpreter.context.set(sceneDocument.uid, sceneDocument)
1660 @subInterpreter.object = object
1661 @subInterpreter.onFinish = gs.CallBack("onCallSceneFinish", this)
1662 @subInterpreter.start()
1663 @subInterpreter.settings = @settings
1664 @subInterpreter.update()
1665
1666
1667
1668 ###*
1669 * Calls a common event and returns the sub-interpreter for it.
1670 *
1671 * @method storeListValue
1672 * @param {number} id - The ID of the common event to call.
1673 * @param {Object} parameters - Optional common event parameters.
1674 * @param {boolean} wait - Indicates if the interpreter should be stay in waiting-mode even if the sub-interpreter is finished.
1675 ###
1676 storeListValue: (variable, list, value, valueType) ->
1677 switch valueType
1678 when 0 # Number Value
1679 @setNumberValueTo(variable, (if !isNaN(value) then value else 0))
1680 when 1 # Switch Value
1681 @setBooleanValueTo(variable, (if value then 1 else 0))
1682 when 2 # Text Value
1683 @setStringValueTo(variable, value.toString())
1684 when 3 # List Value
1685 @setListObjectTo(variable, (if value.length? then value else []))
1686
1687 ###*
1688 * @method jumpToLabel
1689 ###
1690 jumpToLabel: (label) ->
1691 return if not label
1692 found = no
1693
1694 for i in [0...@object.commands.length]
1695 if @object.commands[i].id == "gs.Label" and @object.commands[i].params.name == label
1696 @pointer = i
1697 @indent = @object.commands[i].indent
1698 found = yes
1699 break
1700
1701 if found
1702 @waitCounter = 0
1703 @isWaiting = no
1704
1705 ###*
1706 * Gets the current message box object depending on game mode (ADV or NVL).
1707 *
1708 * @method messageBoxObject
1709 * @return {gs.Object_Base} The message box object.
1710 * @protected
1711 ###
1712 messageBoxObject: (id) ->
1713 if SceneManager.scene.layout.visible
1714 return gs.ObjectManager.current.objectById(id || "messageBox")
1715 else
1716 return gs.ObjectManager.current.objectById(id || "nvlMessageBox")
1717
1718 ###*
1719 * Gets the current message object depending on game mode (ADV or NVL).
1720 *
1721 * @method messageObject
1722 * @return {ui.Object_Message} The message object.
1723 * @protected
1724 ###
1725 messageObject: ->
1726 if SceneManager.scene.layout.visible
1727 return gs.ObjectManager.current.objectById("gameMessage_message")
1728 else
1729 return gs.ObjectManager.current.objectById("nvlGameMessage_message")
1730 ###*
1731 * Gets the current message ID depending on game mode (ADV or NVL).
1732 *
1733 * @method messageObjectId
1734 * @return {string} The message object ID.
1735 * @protected
1736 ###
1737 messageObjectId: ->
1738 if SceneManager.scene.layout.visible
1739 return "gameMessage_message"
1740 else
1741 return "nvlGameMessage_message"
1742
1743 ###*
1744 * Gets the current message settings.
1745 *
1746 * @method messageSettings
1747 * @return {Object} The message settings
1748 * @protected
1749 ###
1750 messageSettings: ->
1751 message = @targetMessage()
1752
1753 return message.settings
1754
1755 ###*
1756 * Gets the current target message object where all message commands are executed on.
1757 *
1758 * @method targetMessage
1759 * @return {ui.Object_Message} The target message object.
1760 * @protected
1761 ###
1762 targetMessage: ->
1763 message = @messageObject()
1764 target = @settings.message.target
1765 if target?
1766 switch target.type
1767 when 0 # Layout-Based
1768 message = gs.ObjectManager.current.objectById(target.id) ? @messageObject()
1769 when 1 # Custom
1770 message = SceneManager.scene.messageAreas[target.id]?.message ? @messageObject()
1771
1772 return message
1773
1774 ###*
1775 * Gets the current target message box containing the current target message.
1776 *
1777 * @method targetMessageBox
1778 * @return {ui.Object_UIElement} The target message box.
1779 * @protected
1780 ###
1781 targetMessageBox: ->
1782 messageBox = @messageObject()
1783 target = @settings.message.target
1784 if target?
1785 switch target.type
1786 when 0 # Layout-Based
1787 messageBox = gs.ObjectManager.current.objectById(target.id) ? @messageObject()
1788 when 1 # Custom
1789 messageBox = gs.ObjectManager.current.objectById("customGameMessage_"+target.id) ? @messageObject()
1790
1791 return messageBox
1792
1793 ###*
1794 * Called after an input number dialog was accepted by the user. It takes the user's input and puts
1795 * it in the configured number variable.
1796 *
1797 * @method onInputNumberFinish
1798 * @return {Object} Event Object containing additional data like the number, etc.
1799 * @protected
1800 ###
1801 onInputNumberFinish: (e) ->
1802 @messageObject().behavior.clear()
1803 @setNumberValueTo(@waitingFor.inputNumber.variable, parseInt(ui.Component_FormulaHandler.fieldValue(e.sender, e.number)))
1804 @isWaiting = no
1805 @waitingFor.inputNumber = null
1806 SceneManager.scene.inputNumberBox.dispose()
1807
1808 ###*
1809 * Called after an input text dialog was accepted by the user. It takes the user's text input and puts
1810 * it in the configured string variable.
1811 *
1812 * @method onInputTextFinish
1813 * @return {Object} Event Object containing additional data like the text, etc.
1814 * @protected
1815 ###
1816 onInputTextFinish: (e) ->
1817 @messageObject().behavior.clear()
1818 @setStringValueTo(@waitingFor.inputText.variable, ui.Component_FormulaHandler.fieldValue(e.sender, e.text).replace(/_/g, ""))
1819 @isWaiting = no
1820 @waitingFor.inputText = null
1821 SceneManager.scene.inputTextBox.dispose()
1822
1823 ###*
1824 * Called after a choice was selected by the user. It jumps to the corresponding label
1825 * and also puts the choice into backlog.
1826 *
1827 * @method onChoiceAccept
1828 * @return {Object} Event Object containing additional data like the label, etc.
1829 * @protected
1830 ###
1831 onChoiceAccept: (e) ->
1832 scene = SceneManager.scene
1833 scene.choiceTimer.behavior.stop()
1834
1835 e.isSelected = yes
1836 delete e.sender
1837
1838 GameManager.backlog.push({ character: { name: "" }, message: "", choice: e, choices: scene.choices, isChoice: yes })
1839 scene.choices = []
1840 messageObject = @messageObject()
1841 if messageObject?.visible
1842 @isWaiting = yes
1843 fading = GameManager.tempSettings.messageFading
1844 duration = if GameManager.tempSettings.skip then 0 else fading.duration
1845 messageObject.animator.disappear(fading.animation, fading.easing, duration, =>
1846 messageObject.behavior.clear()
1847 messageObject.visible = no
1848 @isWaiting = no
1849 @waitingFor.choice = null
1850 @executeChoiceAction(e.action, true)
1851 )
1852 else
1853 @isWaiting = no
1854 @executeChoiceAction(e.action, true)
1855 scene.choiceWindow.dispose()
1856
1857 ###*
1858 * Idle
1859 * @method commandIdle
1860 * @protected
1861 ###
1862 commandIdle: ->
1863 @interpreter.isWaiting = !@interpreter.isInstantSkip()
1864
1865
1866 ###*
1867 * Start Timer
1868 * @method commandStartTimer
1869 * @protected
1870 ###
1871 commandStartTimer: ->
1872 scene = SceneManager.scene
1873 timers = scene.timers
1874 number = @interpreter.numberValueOf(@params.number)
1875 timer = timers[number]
1876 if not timer?
1877 timer = new gs.Object_IntervalTimer()
1878 timers[number] = timer
1879
1880 timer.events.offByOwner("elapsed", @object)
1881 timer.events.on("elapsed", (e) =>
1882 params = e.data.params
1883 switch params.action.type
1884 when 0 # Jump To Label
1885 if params.labelIndex?
1886 SceneManager.scene.interpreter.pointer = params.labelIndex
1887 else
1888 SceneManager.scene.interpreter.jumpToLabel(params.action.data.label)
1889 when 1 # Call Common Event
1890 SceneManager.scene.interpreter.callCommonEvent(params.action.data.commonEventId, null, @interpreter.isWaiting)
1891 { params: @params }, @object)
1892
1893 timer.behavior.interval = @interpreter.durationValueOf(@params.interval)
1894 timer.behavior.start()
1895
1896
1897 ###*
1898 * Resume Timer
1899 * @method commandResumeTimer
1900 * @protected
1901 ###
1902 commandResumeTimer: ->
1903 timers = SceneManager.scene.timers
1904 number = @interpreter.numberValueOf(@params.number)
1905 timers[number]?.behavior.resume()
1906
1907 ###*
1908 * Pauses Timer
1909 * @method commandPauseTimer
1910 * @protected
1911 ###
1912 commandPauseTimer: ->
1913 timers = SceneManager.scene.timers
1914 number = @interpreter.numberValueOf(@params.number)
1915 timers[number]?.behavior.pause()
1916
1917 ###*
1918 * Stop Timer
1919 * @method commandStopTimer
1920 * @protected
1921 ###
1922 commandStopTimer: ->
1923 timers = SceneManager.scene.timers
1924 number = @interpreter.numberValueOf(@params.number)
1925 timers[number]?.behavior.stop()
1926
1927 ###*
1928 * Wait
1929 * @method commandWait
1930 * @protected
1931 ###
1932 commandWait: ->
1933 time = @interpreter.durationValueOf(@params.time)
1934
1935 if time? and time > 0 and !@interpreter.previewData
1936 @interpreter.waitCounter = time
1937 @interpreter.isWaiting = yes
1938
1939 ###*
1940 * Loop
1941 * @method commandLoop
1942 * @protected
1943 ###
1944 commandLoop: ->
1945 @interpreter.loops[@interpreter.indent] = { pointer: @interpreter.pointer, condition: -> true }
1946 @interpreter.indent++
1947
1948 ###*
1949 * For-Loop over lists
1950 * @method commandLoopForInList
1951 * @protected
1952 ###
1953 commandLoopForInList: ->
1954 if !@interpreter.loops[@interpreter.indent]
1955 @interpreter.loops[@interpreter.indent] = new gs.ForLoopCommand(@params, @interpreter)
1956 if @interpreter.loops[@interpreter.indent].condition()
1957 @interpreter.indent++
1958 else
1959 @interpreter.indent++
1960
1961 ###*
1962 * Break Loop
1963 * @method commandBreakLoop
1964 * @protected
1965 ###
1966 commandBreakLoop: ->
1967 indent = @indent
1968 while not @interpreter.loops[indent]? and indent > 0
1969 indent--
1970
1971 @interpreter.loops[indent] = null
1972 @interpreter.indent = indent
1973
1974 ###*
1975 * @method commandListAdd
1976 * @protected
1977 ###
1978 commandListAdd: ->
1979 list = @interpreter.listObjectOf(@params.listVariable)
1980
1981 switch @params.valueType
1982 when 0 # Number Value
1983 list.push(@interpreter.numberValueOf(@params.numberValue))
1984 when 1 # Switch Value
1985 list.push(@interpreter.booleanValueOf(@params.switchValue))
1986 when 2 # Text Value
1987 list.push(@interpreter.stringValueOf(@params.stringValue))
1988 when 3 # List Value
1989 list.push(@interpreter.listObjectOf(@params.listValue))
1990
1991 @interpreter.setListObjectTo(@params.listVariable, list)
1992
1993 ###*
1994 * @method commandListPop
1995 * @protected
1996 ###
1997 commandListPop: ->
1998 list = @interpreter.listObjectOf(@params.listVariable)
1999 value = list.pop() ? 0
2000
2001 @interpreter.storeListValue(@params.targetVariable, list, value, @params.valueType)
2002
2003 ###*
2004 * @method commandListShift
2005 * @protected
2006 ###
2007 commandListShift: ->
2008 list = @interpreter.listObjectOf(@params.listVariable)
2009 value = list.shift() ? 0
2010
2011 @interpreter.storeListValue(@params.targetVariable, list, value, @params.valueType)
2012
2013 ###*
2014 * @method commandListIndexOf
2015 * @protected
2016 ###
2017 commandListIndexOf: ->
2018 list = @interpreter.listObjectOf(@params.listVariable)
2019 value = -1
2020
2021 switch @params.valueType
2022 when 0 # Number Value
2023 value = list.indexOf(@interpreter.numberValueOf(@params.numberValue))
2024 when 1 # Switch Value
2025 value = list.indexOf(@interpreter.booleanValueOf(@params.switchValue))
2026 when 2 # Text Value
2027 value = list.indexOf(@interpreter.stringValueOf(@params.stringValue))
2028 when 3 # List Value
2029 value = list.indexOf(@interpreter.listObjectOf(@params.listValue))
2030
2031 @interpreter.setNumberValueTo(@params.targetVariable, value)
2032
2033 ###*
2034 * @method commandListClear
2035 * @protected
2036 ###
2037 commandListClear: ->
2038 list = @interpreter.listObjectOf(@params.listVariable)
2039 list.length = 0
2040
2041 ###*
2042 * @method commandListValueAt
2043 * @protected
2044 ###
2045 commandListValueAt: ->
2046 list = @interpreter.listObjectOf(@params.listVariable)
2047 index = @interpreter.numberValueOf(@params.index)
2048
2049 if index >= 0 and index < list.length
2050 value = list[index] ? 0
2051 @interpreter.storeListValue(@params.targetVariable, list, value, @params.valueType)
2052
2053 ###*
2054 * @method commandListRemoveAt
2055 * @protected
2056 ###
2057 commandListRemoveAt: ->
2058 list = @interpreter.listObjectOf(@params.listVariable)
2059 index = @interpreter.numberValueOf(@params.index)
2060
2061 if index >= 0 and index < list.length
2062 list.splice(index, 1)
2063
2064 ###*
2065 * @method commandListInsertAt
2066 * @protected
2067 ###
2068 commandListInsertAt: ->
2069 list = @interpreter.listObjectOf(@params.listVariable)
2070 index = @interpreter.numberValueOf(@params.index)
2071
2072 if index >= 0 and index < list.length
2073 switch @params.valueType
2074 when 0 # Number Value
2075 list.splice(index, 0, @interpreter.numberValueOf(@params.numberValue))
2076 when 1 # Switch Value
2077 list.splice(index, 0, @interpreter.booleanValueOf(@params.switchValue))
2078 when 2 # Text Value
2079 list.splice(index, 0, @interpreter.stringValueOf(@params.stringValue))
2080 when 3 # List Value
2081 list.splice(index, 0, @interpreter.listObjectOf(@params.listValue))
2082
2083 @interpreter.setListObjectTo(@params.listVariable, list)
2084
2085 ###*
2086 * @method commandListSet
2087 * @protected
2088 ###
2089 commandListSet: ->
2090 list = @interpreter.listObjectOf(@params.listVariable)
2091 index = @interpreter.numberValueOf(@params.index)
2092
2093 if index >= 0
2094 switch @params.valueType
2095 when 0 # Number Value
2096 list[index] = @interpreter.numberValueOf(@params.numberValue)
2097 when 1 # Switch Value
2098 list[index] = @interpreter.booleanValueOf(@params.switchValue)
2099 when 2 # Text Value
2100 list[index] = @interpreter.stringValueOf(@params.stringValue)
2101 when 3 # List Value
2102 list[index] = @interpreter.listObjectOf(@params.listValue)
2103
2104 @interpreter.setListObjectTo(@params.listVariable, list)
2105
2106 ###*
2107 * @method commandListCopy
2108 * @protected
2109 ###
2110 commandListCopy: ->
2111 list = @interpreter.listObjectOf(@params.listVariable)
2112 copy = Object.deepCopy(list)
2113
2114 @interpreter.setListObjectTo(@params.targetVariable, copy)
2115
2116 ###*
2117 * @method commandListLength
2118 * @protected
2119 ###
2120 commandListLength: ->
2121 list = @interpreter.listObjectOf(@params.listVariable)
2122
2123 @interpreter.setNumberValueTo(@params.targetVariable, list.length)
2124
2125 ###*
2126 * @method commandListJoin
2127 * @protected
2128 ###
2129 commandListJoin: ->
2130 list = @interpreter.listObjectOf(@params.listVariable)
2131 value = if @params.order == 0 then list.join(@params.separator||"") else list.reverse().join(@params.separator||"")
2132
2133 @interpreter.setStringValueTo(@params.targetVariable, value)
2134
2135 ###*
2136 * @method commandListFromText
2137 * @protected
2138 ###
2139 commandListFromText: ->
2140 text = @interpreter.stringValueOf(@params.textVariable)
2141 separator = @interpreter.stringValueOf(@params.separator)
2142 list = text.split(separator)
2143
2144 @interpreter.setListObjectTo(@params.targetVariable, list)
2145
2146 ###*
2147 * @method commandListShuffle
2148 * @protected
2149 ###
2150 commandListShuffle: ->
2151 list = @interpreter.listObjectOf(@params.listVariable)
2152 if list.length <= 1 then return
2153
2154 for i in [list.length-1..1]
2155 j = Math.floor(Math.random() * (i+1))
2156 tempi = list[i]
2157 tempj = list[j]
2158 list[i] = tempj
2159 list[j] = tempi
2160
2161 ###*
2162 * @method commandListSort
2163 * @protected
2164 ###
2165 commandListSort: ->
2166 list = @interpreter.listObjectOf(@params.listVariable)
2167 if list.length == 0 then return
2168
2169 switch @params.sortOrder
2170 when 0 # Ascending
2171 list.sort (a, b) ->
2172 if a < b then return -1
2173 if a > b then return 1
2174 return 0
2175 when 1 # Descending
2176 list.sort (a, b) ->
2177 if a > b then return -1
2178 if a < b then return 1
2179 return 0
2180
2181
2182 ###*
2183 * @method commandResetVariables
2184 * @protected
2185 ###
2186 commandResetVariables: ->
2187 switch @params.target
2188 when 0 # All
2189 range = null
2190 when 1 # Range
2191 range = @params.range
2192
2193 switch @params.scope
2194 when 0 # Local
2195 if @params.scene
2196 GameManager.variableStore.clearLocalVariables({ id: @params.scene.uid }, @params.type, range)
2197 when 1 # All Locals
2198 GameManager.variableStore.clearLocalVariables(null, @params.type, range)
2199 when 2 # Global
2200 GameManager.variableStore.clearGlobalVariables(@params.type, range)
2201 when 3 # Persistent
2202 GameManager.variableStore.clearPersistentVariables(@params.type, range)
2203 GameManager.saveGlobalData()
2204
2205
2206 ###*
2207 * @method commandChangeVariableDomain
2208 * @protected
2209 ###
2210 commandChangeVariableDomain: ->
2211 GameManager.variableStore.changeDomain(@interpreter.stringValueOf(@params.domain))
2212
2213 ###*
2214 * @method commandChangeDecimalVariables
2215 * @protected
2216 ###
2217 commandChangeDecimalVariables: -> @interpreter.changeDecimalVariables(@params, @params.roundMethod)
2218
2219 ###*
2220 * @method commandChangeNumberVariables
2221 * @protected
2222 ###
2223 commandChangeNumberVariables: ->
2224 source = 0
2225
2226 switch @params.source
2227 when 0 # Constant Value / Variable Value
2228 source = @interpreter.numberValueOf(@params.sourceValue)
2229 when 1 # Random
2230 start = @interpreter.numberValueOf(@params.sourceRandom.start)
2231 end = @interpreter.numberValueOf(@params.sourceRandom.end)
2232 diff = end - start
2233 source = Math.floor(start + Math.random() * (diff+1))
2234 when 2 # Pointer
2235 source = @interpreter.numberValueAtIndex(@params.sourceScope, @interpreter.numberValueOf(@params.sourceReference)-1, @params.sourceReferenceDomain)
2236 when 3 # Game Data
2237 source = @interpreter.numberValueOfGameData(@params.sourceValue1)
2238 when 4 # Database Data
2239 source = @interpreter.numberValueOfDatabaseData(@params.sourceValue1)
2240
2241 switch @params.target
2242 when 0 # Variable
2243 switch @params.operation
2244 when 0 # Set
2245 @interpreter.setNumberValueTo(@params.targetVariable, source)
2246 when 1 # Add
2247 @interpreter.setNumberValueTo(@params.targetVariable, @interpreter.numberValueOf(@params.targetVariable) + source)
2248 when 2 # Sub
2249 @interpreter.setNumberValueTo(@params.targetVariable, @interpreter.numberValueOf(@params.targetVariable) - source)
2250 when 3 # Mul
2251 @interpreter.setNumberValueTo(@params.targetVariable, @interpreter.numberValueOf(@params.targetVariable) * source)
2252 when 4 # Div
2253 @interpreter.setNumberValueTo(@params.targetVariable, Math.floor(@interpreter.numberValueOf(@params.targetVariable) / source))
2254 when 5 # Mod
2255 @interpreter.setNumberValueTo(@params.targetVariable, @interpreter.numberValueOf(@params.targetVariable) % source)
2256 when 1 # Range
2257 scope = @params.targetScope
2258 start = @params.targetRange.start-1
2259 end = @params.targetRange.end-1
2260 for i in [start..end]
2261 switch @params.operation
2262 when 0 # Set
2263 @interpreter.setNumberValueAtIndex(scope, i, source)
2264 when 1 # Add
2265 @interpreter.setNumberValueAtIndex(scope, i, @interpreter.numberValueAtIndex(scope, i) + source)
2266 when 2 # Sub
2267 @interpreter.setNumberValueAtIndex(scope, i, @interpreter.numberValueAtIndex(scope, i) - source)
2268 when 3 # Mul
2269 @interpreter.setNumberValueAtIndex(scope, i, @interpreter.numberValueAtIndex(scope, i) * source)
2270 when 4 # Div
2271 @interpreter.setNumberValueAtIndex(scope, i, Math.floor(@interpreter.numberValueAtIndex(scope, i) / source))
2272 when 5 # Mod
2273 @interpreter.setNumberValueAtIndex(scope, i, @interpreter.numberValueAtIndex(scope, i) % source)
2274 when 2 # Reference
2275 index = @interpreter.numberValueOf(@params.targetReference) - 1
2276 switch @params.operation
2277 when 0 # Set
2278 @interpreter.setNumberValueAtIndex(@params.targetScope, index, source, @params.targetReferenceDomain)
2279 when 1 # Add
2280 @interpreter.setNumberValueAtIndex(@params.targetScope, index, @interpreter.numberValueAtIndex(@params.targetScope, index, @params.targetReferenceDomain) + source, @params.targetReferenceDomain)
2281 when 2 # Sub
2282 @interpreter.setNumberValueAtIndex(@params.targetScope, index, @interpreter.numberValueAtIndex(@params.targetScope, index, @params.targetReferenceDomain) - source, @params.targetReferenceDomain)
2283 when 3 # Mul
2284 @interpreter.setNumberValueAtIndex(@params.targetScope, index, @interpreter.numberValueAtIndex(@params.targetScope, index, @params.targetReferenceDomain) * source, @params.targetReferenceDomain)
2285 when 4 # Div
2286 @interpreter.setNumberValueAtIndex(@params.targetScope, index, Math.floor(@interpreter.numberValueAtIndex(@params.targetScope, index, @params.targetReferenceDomain) / source), @params.targetReferenceDomain)
2287 when 5 # Mod
2288 @interpreter.setNumberValueAtIndex(@params.targetScope, index, @interpreter.numberValueAtIndex(@params.targetScope, index, @params.targetReferenceDomain) % source, @params.targetReferenceDomain)
2289
2290 return null
2291
2292 ###*
2293 * @method commandChangeBooleanVariables
2294 * @protected
2295 ###
2296 commandChangeBooleanVariables: ->
2297 source = @interpreter.booleanValueOf(@params.value)
2298
2299 switch @params.target
2300 when 0 # Variable
2301 if @params.value == 2 # Trigger
2302 targetValue = @interpreter.booleanValueOf(@params.targetVariable)
2303 @interpreter.setBooleanValueTo(@params.targetVariable, if targetValue then false else true)
2304 else
2305 @interpreter.setBooleanValueTo(@params.targetVariable, source)
2306 when 1 # Range
2307 variable = { index: 0, scope: @params.targetRangeScope }
2308 for i in [(@params.rangeStart-1)..(@params.rangeEnd-1)]
2309 variable.index = i
2310 if @params.value == 2 # Trigger
2311 targetValue = @interpreter.booleanValueOf(variable)
2312 @interpreter.setBooleanValueTo(variable, if targetValue then false else true)
2313 else
2314 @interpreter.setBooleanValueTo(variable, source)
2315 when 2 # Reference
2316 index = @interpreter.numberValueOf(@params.targetReference) - 1
2317 @interpreter.setBooleanValueAtIndex(@params.targetRangeScope, index, source, @params.targetReferenceDomain)
2318
2319 return null
2320
2321 ###*
2322 * @method commandChangeStringVariables
2323 * @protected
2324 ###
2325 commandChangeStringVariables: ->
2326 source = ""
2327 switch @params.source
2328 when 0 # Constant Text
2329 source = lcs(@params.textValue)
2330 when 1 # Variable
2331 source = @interpreter.stringValueOf(@params.sourceVariable)
2332 when 2 # Database Data
2333 source = @interpreter.stringValueOfDatabaseData(@params.databaseData)
2334 when 2 # Script
2335 try
2336 source = eval(@params.script)
2337 catch ex
2338 source = "ERR: " + ex.message
2339 else
2340 source = lcs(@params.textValue)
2341
2342 switch @params.target
2343 when 0 # Variable
2344 switch @params.operation
2345 when 0 # Set
2346 @interpreter.setStringValueTo(@params.targetVariable, source)
2347 when 1 # Add
2348 @interpreter.setStringValueTo(@params.targetVariable, @interpreter.stringValueOf(@params.targetVariable) + source)
2349 when 2 # To Upper-Case
2350 @interpreter.setStringValueTo(@params.targetVariable, @interpreter.stringValueOf(@params.targetVariable).toUpperCase())
2351 when 3 # To Lower-Case
2352 @interpreter.setStringValueTo(@params.targetVariable, @interpreter.stringValueOf(@params.targetVariable).toLowerCase())
2353
2354 when 1 # Range
2355 variable = { index: 0, scope: @params.targetRangeScope }
2356 for i in [@params.rangeStart-1..@params.rangeEnd-1]
2357 variable.index = i
2358 switch @params.operation
2359 when 0 # Set
2360 @interpreter.setStringValueTo(variable, source)
2361 when 1 # Add
2362 @interpreter.setStringValueTo(variable, @interpreter.stringValueOf(variable) + source)
2363 when 2 # To Upper-Case
2364 @interpreter.setStringValueTo(variable, @interpreter.stringValueOf(variable).toUpperCase())
2365 when 3 # To Lower-Case
2366 @interpreter.setStringValueTo(variable, @interpreter.stringValueOf(variable).toLowerCase())
2367
2368 when 2 # Reference
2369 index = @interpreter.numberValueOf(@params.targetReference) - 1
2370 switch @params.operation
2371 when 0 # Set
2372 @interpreter.setStringValueAtIndex(@params.targetRangeScope, index, source, @params.targetReferenceDomain)
2373 when 1 # Add
2374 targetValue = @interpreter.stringValueAtIndex(@params.targetRangeScope, index, @params.targetReferenceDomain)
2375 @interpreter.setStringValueAtIndex(@params.targetRangeScope, index, targetValue + source, @params.targetReferenceDomain)
2376 when 2 # To Upper-Case
2377 targetValue = @interpreter.stringValueAtIndex(@params.targetRangeScope, index, @params.targetReferenceDomain)
2378 @interpreter.setStringValueAtIndex(@params.targetRangeScope, index, targetValue.toUpperCase(), @params.targetReferenceDomain)
2379 when 3 # To Lower-Case
2380 targetValue = @interpreter.stringValueAtIndex(@params.targetRangeScope, index, @params.targetReferenceDomain)
2381 @interpreter.setStringValueTo(@params.targetRangeScope, index, targetValue.toLowerCase(), @params.targetReferenceDomain)
2382 return null
2383
2384 ###*
2385 * @method commandCheckSwitch
2386 * @protected
2387 ###
2388 commandCheckSwitch: ->
2389 result = @interpreter.booleanValueOf(@params.targetVariable) && @params.value
2390 if result
2391 @interpreter.pointer = @params.labelIndex
2392
2393
2394 ###*
2395 * @method commandNumberCondition
2396 * @protected
2397 ###
2398 commandNumberCondition: ->
2399 result = @interpreter.compare(@interpreter.numberValueOf(@params.targetVariable), @interpreter.numberValueOf(@params.value), @params.operation)
2400 @interpreter.conditions[@interpreter.indent] = result
2401
2402 if result
2403 @interpreter.indent++
2404
2405 ###*
2406 * @method commandCondition
2407 * @protected
2408 ###
2409 commandCondition: ->
2410 switch @params.valueType
2411 when 0 # Number
2412 result = @interpreter.compare(@interpreter.numberValueOf(@params.variable), @interpreter.numberValueOf(@params.numberValue), @params.operation)
2413 when 1 # Switch
2414 result = @interpreter.compare(@interpreter.booleanValueOf(@params.variable), @interpreter.booleanValueOf(@params.switchValue), @params.operation)
2415 when 2 # Text
2416 result = @interpreter.compare(lcs(@interpreter.stringValueOf(@params.variable)), lcs(@interpreter.stringValueOf(@params.textValue)), @params.operation)
2417
2418 @interpreter.conditions[@interpreter.indent] = result
2419 if result
2420 @interpreter.indent++
2421
2422 ###*
2423 * @method commandConditionElse
2424 * @protected
2425 ###
2426 commandConditionElse: ->
2427 if not @interpreter.conditions[@interpreter.indent]
2428 @interpreter.indent++
2429
2430 ###*
2431 * @method commandConditionElseIf
2432 * @protected
2433 ###
2434 commandConditionElseIf: ->
2435 if not @interpreter.conditions[@interpreter.indent]
2436 @interpreter.commandCondition.call(this)
2437
2438 ###*
2439 * @method commandCheckNumberVariable
2440 * @protected
2441 ###
2442 commandCheckNumberVariable: ->
2443 result = @interpreter.compare(@interpreter.numberValueOf(@params.targetVariable), @interpreter.numberValueOf(@params.value), @params.operation)
2444 if result
2445 @interpreter.pointer = @params.labelIndex
2446
2447 ###*
2448 * @method commandCheckTextVariable
2449 * @protected
2450 ###
2451 commandCheckTextVariable: ->
2452 result = no
2453 text1 = @interpreter.stringValueOf(@params.targetVariable)
2454 text2 = @interpreter.stringValueOf(@params.value)
2455 switch @params.operation
2456 when 0 then result = text1 == text2
2457 when 1 then result = text1 != text2
2458 when 2 then result = text1.length > text2.length
2459 when 3 then result = text1.length >= text2.length
2460 when 4 then result = text1.length < text2.length
2461 when 5 then result = text1.length <= text2.length
2462
2463 if result
2464 @interpreter.pointer = @params.labelIndex
2465
2466 ###*
2467 * @method commandLabel
2468 * @protected
2469 ###
2470 commandLabel: -> # Does Nothing
2471
2472
2473 ###*
2474 * @method commandJumpToLabel
2475 * @protected
2476 ###
2477 commandJumpToLabel: ->
2478 label = @params.labelIndex #@interpreter.labels[@params.name]
2479 if label?
2480 @interpreter.pointer = label
2481 @interpreter.indent = @interpreter.object.commands[label].indent
2482 else
2483 switch @params.target
2484 when "activeContext"
2485 @interpreter.jumpToLabel(@interpreter.stringValueOf(@params.name))
2486 when "activeScene"
2487 SceneManager.scene.interpreter.jumpToLabel(@interpreter.stringValueOf(@params.name))
2488 else
2489 @interpreter.jumpToLabel(@interpreter.stringValueOf(@params.name))
2490
2491 ###*
2492 * @method commandClearMessage
2493 * @protected
2494 ###
2495 commandClearMessage: ->
2496 scene = SceneManager.scene
2497 messageObject = @interpreter.targetMessage()
2498 if not messageObject? then return
2499
2500 flags = @params.fieldFlags || {}
2501 isLocked = gs.CommandFieldFlags.isLocked
2502 duration = 0
2503 fading = GameManager.tempSettings.messageFading
2504 if not GameManager.tempSettings.skip
2505 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else fading.duration
2506 messageObject.animator.disappear(fading.animation, fading.easing, duration, gs.CallBack("onMessageADVClear", @interpreter))
2507
2508 @interpreter.waitForCompletion(messageObject, @params)
2509 gs.GameNotifier.postMinorChange()
2510
2511 ###*
2512 * @method commandMessageBoxDefaults
2513 * @protected
2514 ###
2515 commandMessageBoxDefaults: ->
2516 defaults = GameManager.defaults.messageBox
2517 flags = @params.fieldFlags || {}
2518 isLocked = gs.CommandFieldFlags.isLocked
2519
2520 if !isLocked(flags.appearDuration) then defaults.appearDuration = @interpreter.durationValueOf(@params.appearDuration)
2521 if !isLocked(flags.disappearDuration) then defaults.disappearDuration = @interpreter.durationValueOf(@params.disappearDuration)
2522 if !isLocked(flags.zOrder) then defaults.zOrder = @interpreter.numberValueOf(@params.zOrder)
2523 if !isLocked(flags["appearEasing.type"]) then defaults.appearEasing = @params.appearEasing
2524 if !isLocked(flags["appearAnimation.type"]) then defaults.appearAnimation = @params.appearAnimation
2525 if !isLocked(flags["disappearEasing.type"]) then defaults.disappearEasing = @params.disappearEasing
2526 if !isLocked(flags["disappearAnimation.type"]) then defaults.disappearAnimation = @params.disappearAnimation
2527
2528
2529 ###*
2530 * @method commandShowMessage
2531 * @protected
2532 ###
2533 commandShowMessage: ->
2534 scene = SceneManager.scene
2535 scene.messageMode = vn.MessageMode.ADV
2536 character = scene.characters.first (v) => !v.disposed and v.rid == @params.characterId
2537
2538 showMessage = =>
2539 character = RecordManager.characters[@params.characterId]
2540
2541 scene.layout.visible = yes
2542 messageObject = @interpreter.targetMessage()
2543
2544 if not messageObject? then return
2545
2546 scene.currentCharacter = character
2547 messageObject.character = character
2548
2549 messageObject.opacity = 255
2550 messageObject.events.offByOwner("callCommonEvent", @interpreter)
2551 messageObject.events.on("callCommonEvent", gs.CallBack("onCallCommonEvent", @interpreter), params: @params, @interpreter)
2552 messageObject.events.once("finish", gs.CallBack("onMessageADVFinish", @interpreter), params: @params, @interpreter)
2553 messageObject.events.once("waiting", gs.CallBack("onMessageADVWaiting", @interpreter), params: @params, @interpreter)
2554 if messageObject.settings.useCharacterColor
2555 messageObject.message.showMessage(@interpreter, @params, character)
2556 else
2557 messageObject.message.showMessage(@interpreter, @params)
2558
2559 settings = GameManager.settings
2560 voiceSettings = settings.voicesByCharacter[character.index]
2561
2562 if @params.voice? and GameManager.settings.voiceEnabled and (!voiceSettings or voiceSettings > 0)
2563 if (GameManager.settings.skipVoiceOnAction or !AudioManager.voice?.playing) and !GameManager.tempSettings.skip
2564 messageObject.voice = @params.voice
2565 messageObject.behavior.voice = AudioManager.playVoice(@params.voice)
2566 else
2567 messageObject.behavior.voice = null
2568
2569 if @params.expressionId? and character?
2570 expression = RecordManager.characterExpressions[@params.expressionId || 0]
2571 defaults = GameManager.defaults.character
2572 duration = if !gs.CommandFieldFlags.isLocked(@params.fieldFlags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.expressionDuration
2573 easing = gs.Easings.fromObject(defaults.changeEasing)
2574 animation = defaults.changeAnimation
2575
2576 character.behavior.changeExpression(expression, animation, easing, duration, =>
2577 showMessage()
2578 )
2579 else
2580 showMessage()
2581
2582 @interpreter.isWaiting = (@params.waitForCompletion ? yes) and !(GameManager.tempSettings.skip and GameManager.tempSettings.skipTime == 0)
2583 @interpreter.waitingFor.messageADV = @params
2584
2585 ###*
2586 * @method commandSetMessageArea
2587 * @protected
2588 ###
2589 commandSetMessageArea: ->
2590 scene = SceneManager.scene
2591 number = @interpreter.numberValueOf(@params.number)
2592
2593 if scene.messageAreas[number]
2594 messageLayout = scene.messageAreas[number].layout
2595 messageLayout.dstRect.x = @params.box.x
2596 messageLayout.dstRect.y = @params.box.y
2597 messageLayout.dstRect.width = @params.box.size.width
2598 messageLayout.dstRect.height = @params.box.size.height
2599 messageLayout.needsUpdate = yes
2600
2601 ###*
2602 * @method commandMessageFading
2603 * @protected
2604 ###
2605 commandMessageFading: ->
2606 GameManager.tempSettings.messageFading = duration: @interpreter.durationValueOf(@params.duration), animation: @params.animation, easing: gs.Easings.fromObject(@params.easing)
2607
2608 ###*
2609 * @method commandMessageSettings
2610 * @protected
2611 ###
2612 commandMessageSettings: ->
2613 messageObject = @interpreter.targetMessage()
2614 if !messageObject then return
2615
2616 flags = @params.fieldFlags || {}
2617 isLocked = gs.CommandFieldFlags.isLocked
2618 messageSettings = @interpreter.messageSettings()
2619
2620 if !isLocked(flags.autoErase)
2621 messageSettings.autoErase = @params.autoErase
2622
2623 if !isLocked(flags.waitAtEnd)
2624 messageSettings.waitAtEnd = @params.waitAtEnd
2625
2626 if !isLocked(flags.backlog)
2627 messageSettings.backlog = @params.backlog
2628
2629 if !isLocked(flags.lineHeight)
2630 messageSettings.lineHeight = @params.lineHeight
2631
2632 if !isLocked(flags.lineSpacing)
2633 messageSettings.lineSpacing = @params.lineSpacing
2634
2635 if !isLocked(flags.linePadding)
2636 messageSettings.linePadding = @params.linePadding
2637
2638 if !isLocked(flags.paragraphSpacing)
2639 messageSettings.paragraphSpacing = @params.paragraphSpacing
2640
2641 if !isLocked(flags.useCharacterColor)
2642 messageSettings.useCharacterColor = @params.useCharacterColor
2643
2644 messageObject.textRenderer.minLineHeight = messageSettings.lineHeight ? 0
2645 messageObject.textRenderer.lineSpacing = messageSettings.lineSpacing ? messageObject.textRenderer.lineSpacing
2646 messageObject.textRenderer.padding = messageSettings.linePadding ? messageObject.textRenderer.padding
2647
2648 fontName = if !isLocked(flags.font) then @interpreter.stringValueOf(@params.font) else messageObject.font.name
2649 fontSize = if !isLocked(flags.size) then @interpreter.numberValueOf(@params.size) else messageObject.font.size
2650 font = messageObject.font
2651
2652 if !isLocked(flags.font) or !isLocked(flags.size)
2653 messageObject.font = new Font(fontName, fontSize)
2654
2655 if !isLocked(flags.bold)
2656 messageObject.font.bold = @params.bold
2657 if !isLocked(flags.italic)
2658 messageObject.font.italic = @params.italic
2659 if !isLocked(flags.smallCaps)
2660 messageObject.font.smallCaps = @params.smallCaps
2661 if !isLocked(flags.underline)
2662 messageObject.font.underline = @params.underline
2663 if !isLocked(flags.strikeThrough)
2664 messageObject.font.strikeThrough = @params.strikeThrough
2665 if !isLocked(flags.color)
2666 messageObject.font.color = new Color(@params.color)
2667
2668 messageObject.font.color = if flags.color? and !isLocked(flags.color) then new Color(@params.color) else font.color
2669 messageObject.font.border = if flags.outline? and !isLocked(flags.outline) then @params.outline else font.border
2670 messageObject.font.borderColor = if flags.outlineColor? and !isLocked(flags.outlineColor) then new Color(@params.outlineColor) else new Color(font.borderColor)
2671 messageObject.font.borderSize = if flags.outlineSize? and !isLocked(flags.outlineSize) then (@params.outlineSize ? 4) else font.borderSize
2672 messageObject.font.shadow = if flags.shadow? and !isLocked(flags.shadow)then @params.shadow else font.shadow
2673 messageObject.font.shadowColor = if flags.shadowColor? and !isLocked(flags.shadowColor) then new Color(@params.shadowColor) else new Color(font.shadowColor)
2674 messageObject.font.shadowOffsetX = if flags.shadowOffsetX? and !isLocked(flags.shadowOffsetX) then (@params.shadowOffsetX ? 1) else font.shadowOffsetX
2675 messageObject.font.shadowOffsetY = if flags.shadowOffsetY? and !isLocked(flags.shadowOffsetY) then (@params.shadowOffsetY ? 1) else font.shadowOffsetY
2676
2677 if isLocked(flags.bold) then messageObject.font.bold = font.bold
2678 if isLocked(flags.italic) then messageObject.font.italic = font.italic
2679 if isLocked(flags.smallCaps) then messageObject.font.smallCaps = font.smallCaps
2680
2681 ###*
2682 * @method commandCreateMessageArea
2683 * @protected
2684 ###
2685 commandCreateMessageArea: ->
2686 number = @interpreter.numberValueOf(@params.number)
2687 scene = SceneManager.scene
2688 scene.behavior.changeMessageAreaDomain(@params.numberDomain)
2689 if !scene.messageAreas[number]
2690 messageArea = new gs.Object_MessageArea()
2691 messageArea.layout = ui.UIManager.createControlFromDescriptor(type: "ui.CustomGameMessage", id: "customGameMessage_"+number, params: { id: "customGameMessage_"+number }, messageArea)
2692 messageArea.message = gs.ObjectManager.current.objectById("customGameMessage_"+number+"_message")
2693 messageArea.message.domain = @params.numberDomain
2694 messageArea.addObject(messageArea.layout)
2695 messageArea.layout.dstRect.x = @params.box.x
2696 messageArea.layout.dstRect.y = @params.box.y
2697 messageArea.layout.dstRect.width = @params.box.size.width
2698 messageArea.layout.dstRect.height = @params.box.size.height
2699 messageArea.layout.needsUpdate = yes
2700 scene.messageAreas[number] = messageArea
2701
2702 ###*
2703 * @method commandEraseMessageArea
2704 * @protected
2705 ###
2706 commandEraseMessageArea: ->
2707 number = @interpreter.numberValueOf(@params.number)
2708 scene = SceneManager.scene
2709 scene.behavior.changeMessageAreaDomain(@params.numberDomain)
2710 area = scene.messageAreas[number]
2711 area?.layout.dispose()
2712 scene.messageAreas[number] = null
2713
2714 ###*
2715 * @method commandSetTargetMessage
2716 * @protected
2717 ###
2718 commandSetTargetMessage: ->
2719 message = @interpreter.targetMessage()
2720 message?.textRenderer.isWaiting = false
2721 message?.behavior.isWaiting = false
2722
2723 scene = SceneManager.scene
2724 scene.behavior.changeMessageAreaDomain(@params.numberDomain)
2725 target = { type: @params.type, id: null }
2726
2727 switch @params.type
2728 when 0 # Layout-based
2729 target.id = @params.id
2730 when 1 # Custom
2731 target.id = @interpreter.numberValueOf(@params.number)
2732
2733 @interpreter.settings.message.target = target
2734
2735 if @params.clear
2736 @interpreter.targetMessage()?.behavior.clear()
2737 @interpreter.targetMessage()?.visible = yes
2738
2739 ###*
2740 * @method commandBacklogVisibility
2741 * @protected
2742 ###
2743 commandBacklogVisibility: ->
2744 if @params.visible
2745 control = gs.ObjectManager.current.objectById("backlogBox")
2746 if not control? then control = gs.ObjectManager.current.objectById("backlog")
2747
2748 if control?
2749 control.dispose()
2750
2751 if @params.backgroundVisible
2752 control = SceneManager.scene.behavior.createControl(this, { descriptor: "ui.MessageBacklogBox" })
2753 else
2754 control = SceneManager.scene.behavior.createControl(this, { descriptor: "ui.MessageBacklog" })
2755 else
2756 control = gs.ObjectManager.current.objectById("backlogBox")
2757 if not control? then control = gs.ObjectManager.current.objectById("backlog")
2758 if not control? then control = gs.ObjectManager.current.objectById("backlogScrollView")
2759
2760 control?.dispose()
2761
2762 ###*
2763 * @method commandMessageVisibility
2764 * @protected
2765 ###
2766 commandMessageVisibility: ->
2767 defaults = GameManager.defaults.messageBox
2768 flags = @params.fieldFlags || {}
2769 isLocked = gs.CommandFieldFlags.isLocked
2770
2771 message = @interpreter.targetMessage()
2772 if not message? or @params.visible == message.visible then return
2773
2774 if @params.visible
2775 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.appearDuration
2776 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromObject(@params.easing) else gs.Easings.fromObject(defaults.appearEasing)
2777 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.appearAnimation
2778 message.animator.appear(message.dstRect.x, message.dstRect.y, @params.animation, easing, duration)
2779 else
2780 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.disappearDuration
2781 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromObject(@params.easing) else gs.Easings.fromObject(defaults.disappearEasing)
2782 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.disappearAnimation
2783 message.animator.disappear(animation, easing, duration, -> message.visible = no)
2784 message.update()
2785
2786 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
2787 @interpreter.isWaiting = yes
2788 @interpreter.waitCounter = duration
2789 gs.GameNotifier.postMinorChange()
2790 ###*
2791 * @method commandMessageBoxVisibility
2792 * @protected
2793 ###
2794 commandMessageBoxVisibility: ->
2795 defaults = GameManager.defaults.messageBox
2796 flags = @params.fieldFlags || {}
2797 isLocked = gs.CommandFieldFlags.isLocked
2798 messageBox = @interpreter.messageBoxObject(@interpreter.stringValueOf(@params.id))
2799 visible = @params.visible == 1
2800 if not messageBox? or visible == messageBox.visible then return
2801
2802 if @params.visible
2803 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.appearDuration
2804 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromObject(@params.easing) else gs.Easings.fromObject(defaults.appearEasing)
2805 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.appearAnimation
2806 messageBox.animator.appear(messageBox.dstRect.x, messageBox.dstRect.y, animation, easing, duration)
2807 else
2808 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.disappearDuration
2809 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromObject(@params.easing) else gs.Easings.fromObject(defaults.disappearEasing)
2810 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.disappearAnimation
2811 messageBox.animator.disappear(animation, easing, duration, -> messageBox.visible = no)
2812 messageBox.update()
2813
2814 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
2815 @interpreter.isWaiting = yes
2816 @interpreter.waitCounter = duration
2817 gs.GameNotifier.postMinorChange()
2818
2819 ###*
2820 * @method commandUIAccess
2821 * @protected
2822 ###
2823 commandUIAccess: ->
2824 flags = @params.fieldFlags || {}
2825 isLocked = gs.CommandFieldFlags.isLocked
2826
2827 if !isLocked(flags.generalMenu)
2828 GameManager.tempSettings.menuAccess = @interpreter.booleanValueOf(@params.generalMenu)
2829 if !isLocked(flags.saveMenu)
2830 GameManager.tempSettings.saveMenuAccess = @interpreter.booleanValueOf(@params.saveMenu)
2831 if !isLocked(flags.loadMenu)
2832 GameManager.tempSettings.loadMenuAccess = @interpreter.booleanValueOf(@params.loadMenu)
2833 if !isLocked(flags.backlog)
2834 GameManager.tempSettings.backlogAccess = @interpreter.booleanValueOf(@params.backlog)
2835
2836 ###*
2837 * @method commandUnlockCG
2838 * @protected
2839 ###
2840 commandUnlockCG: ->
2841 cg = RecordManager.cgGallery[@interpreter.stringValueOf(@params.cgId)]
2842
2843 if cg?
2844 GameManager.globalData.cgGallery[cg.index] = { unlocked: yes }
2845 GameManager.saveGlobalData()
2846
2847 ###*
2848 * @method commandL2DMove
2849 * @protected
2850 ###
2851 commandL2DMove: ->
2852 scene = SceneManager.scene
2853 character = scene.characters.first (v) => !v.disposed and v.rid == @params.characterId
2854 if not character instanceof vn.Object_Live2DCharacter then return
2855
2856 @interpreter.moveObject(character, @params.position, @params)
2857 gs.GameNotifier.postMinorChange()
2858
2859 ###*
2860 * @method commandL2DMotionGroup
2861 * @protected
2862 ###
2863 commandL2DMotionGroup: ->
2864 scene = SceneManager.scene
2865 character = scene.characters.first (v) => !v.disposed and v.rid == @params.characterId
2866 if not character instanceof vn.Object_Live2DCharacter then return
2867
2868 character.motionGroup = { name: @params.data.motionGroup, loop: @params.loop, playType: @params.playType }
2869 if @params.waitForCompletion and not @params.loop
2870 motions = character.model.motionsByGroup[character.motionGroup.name]
2871 if motions?
2872 @interpreter.isWaiting = yes
2873 @interpreter.waitCounter = motions.sum (m) -> m.getDurationMSec() / 16.6
2874 gs.GameNotifier.postMinorChange()
2875
2876 ###*
2877 * @method commandL2DMotion
2878 * @protected
2879 ###
2880 commandL2DMotion: ->
2881 defaults = GameManager.defaults.live2d
2882 flags = @params.fieldFlags || {}
2883 isLocked = gs.CommandFieldFlags.isLocked
2884 scene = SceneManager.scene
2885 character = scene.characters.first (v) => !v.disposed and v.rid == @params.characterId
2886 if not character instanceof vn.Object_Live2DCharacter then return
2887 fadeInTime = if !isLocked(flags.fadeInTime) then @params.fadeInTime else defaults.motionFadeInTime
2888 character.motion = { name: @params.data.motion, fadeInTime: fadeInTime, loop: @params.loop }
2889 character.motionGroup = null
2890
2891 if @params.waitForCompletion and not @params.loop
2892 motion = character.model.motions[character.motion.name]
2893 if motion?
2894 @interpreter.isWaiting = yes
2895 @interpreter.waitCounter = motion.getDurationMSec() / 16.6
2896 gs.GameNotifier.postMinorChange()
2897
2898 ###*
2899 * @method commandL2DExpression
2900 * @protected
2901 ###
2902 commandL2DExpression: ->
2903 defaults = GameManager.defaults.live2d
2904 flags = @params.fieldFlags || {}
2905 isLocked = gs.CommandFieldFlags.isLocked
2906 scene = SceneManager.scene
2907 character = scene.characters.first (v) => !v.disposed and v.rid == @params.characterId
2908 if not character instanceof vn.Object_Live2DCharacter then return
2909 fadeInTime = if !isLocked(flags.fadeInTime) then @params.fadeInTime else defaults.expressionFadeInTime
2910
2911 character.expression = { name: @params.data.expression, fadeInTime: fadeInTime }
2912 gs.GameNotifier.postMinorChange()
2913
2914 ###*
2915 * @method commandL2DExitScene
2916 * @protected
2917 ###
2918 commandL2DExitScene: ->
2919 defaults = GameManager.defaults.live2d
2920 @interpreter.commandCharacterExitScene.call(this, defaults)
2921 gs.GameNotifier.postMinorChange()
2922
2923 ###*
2924 * @method commandL2DSettings
2925 * @protected
2926 ###
2927 commandL2DSettings: ->
2928 flags = @params.fieldFlags || {}
2929 isLocked = gs.CommandFieldFlags.isLocked
2930
2931 scene = SceneManager.scene
2932 character = scene.characters.first (v) => !v.disposed and v.rid == @params.characterId
2933 if not character?.visual.l2dObject then return
2934
2935
2936 if !isLocked(flags.lipSyncSensitivity)
2937 character.visual.l2dObject.lipSyncSensitivity = @interpreter.numberValueOf(@params.lipSyncSensitivity)
2938 if !isLocked(flags.idleIntensity)
2939 character.visual.l2dObject.idleIntensity = @interpreter.numberValueOf(@params.idleIntensity)
2940 if !isLocked(flags.breathIntensity)
2941 character.visual.l2dObject.breathIntensity = @interpreter.numberValueOf(@params.breathIntensity)
2942 if !isLocked(flags["eyeBlink.enabled"])
2943 character.visual.l2dObject.eyeBlink.enabled = @params.eyeBlink.enabled
2944 if !isLocked(flags["eyeBlink.interval"])
2945 character.visual.l2dObject.eyeBlink.blinkIntervalMsec = @interpreter.numberValueOf(@params.eyeBlink.interval)
2946 if !isLocked(flags["eyeBlink.closedMotionTime"])
2947 character.visual.l2dObject.eyeBlink.closedMotionMsec = @interpreter.numberValueOf(@params.eyeBlink.closedMotionTime)
2948 if !isLocked(flags["eyeBlink.closingMotionTime"])
2949 character.visual.l2dObject.eyeBlink.closingMotionMsec = @interpreter.numberValueOf(@params.eyeBlink.closingMotionTime)
2950 if !isLocked(flags["eyeBlink.openingMotionTime"])
2951 character.visual.l2dObject.eyeBlink.openingMotionMsec = @interpreter.numberValueOf(@params.eyeBlink.openingMotionTime)
2952
2953 gs.GameNotifier.postMinorChange()
2954 ###*
2955 * @method commandL2DParameter
2956 * @protected
2957 ###
2958 commandL2DParameter: ->
2959 scene = SceneManager.scene
2960 character = scene.characters.first (v) => !v.disposed and v.rid == @params.characterId
2961 if not character instanceof vn.Object_Live2DCharacter then return
2962
2963 easing = gs.Easings.fromObject(@params.easing)
2964 duration = @interpreter.durationValueOf(@params.duration)
2965 character.animator.l2dParameterTo(@params.param.name, @interpreter.numberValueOf(@params.param.value), duration, easing)
2966
2967 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
2968 @interpreter.isWaiting = yes
2969 @interpreter.waitCounter = duration
2970 gs.GameNotifier.postMinorChange()
2971 ###*
2972 * @method commandL2DDefaults
2973 * @protected
2974 ###
2975 commandL2DDefaults: ->
2976 defaults = GameManager.defaults.live2d
2977 flags = @params.fieldFlags || {}
2978 isLocked = gs.CommandFieldFlags.isLocked
2979
2980 if !isLocked(flags.appearDuration) then defaults.appearDuration = @interpreter.durationValueOf(@params.appearDuration)
2981 if !isLocked(flags.disappearDuration) then defaults.disappearDuration = @interpreter.durationValueOf(@params.disappearDuration)
2982 if !isLocked(flags.zOrder) then defaults.zOrder = @interpreter.numberValueOf(@params.zOrder)
2983 if !isLocked(flags.motionFadeInTime) then defaults.motionFadeInTime = @interpreter.numberValueOf(@params.motionFadeInTime)
2984 if !isLocked(flags["appearEasing.type"]) then defaults.appearEasing = @params.appearEasing
2985 if !isLocked(flags["appearAnimation.type"]) then defaults.appearAnimation = @params.appearAnimation
2986 if !isLocked(flags["disappearEasing.type"]) then defaults.disappearEasing = @params.disappearEasing
2987 if !isLocked(flags["disappearAnimation.type"]) then defaults.disappearAnimation = @params.disappearAnimation
2988
2989 gs.GameNotifier.postMinorChange()
2990 ###*
2991 * @method commandL2DJoinScene
2992 * @protected
2993 ###
2994 commandL2DJoinScene: ->
2995 defaults = GameManager.defaults.live2d
2996 flags = @params.fieldFlags || {}
2997 isLocked = gs.CommandFieldFlags.isLocked
2998 scene = SceneManager.scene
2999 record = RecordManager.characters[@interpreter.stringValueOf(@params.characterId)]
3000 return if !record or scene.characters.first (v) -> !v.disposed and v.rid == record.index
3001
3002 if @params.positionType == 1
3003 x = @params.position.x
3004 y = @params.position.y
3005 else if @params.positionType == 2
3006 x = @interpreter.numberValueOf(@params.position.x)
3007 y = @interpreter.numberValueOf(@params.position.y)
3008
3009 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut) else gs.Easings.fromObject(defaults.appearEasing)
3010 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.appearDuration
3011 zIndex = if !isLocked(flags.zOrder) then @interpreter.numberValueOf(@params.zOrder) else defaults.zOrder
3012 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.appearAnimation
3013 motionBlur = if !isLocked(flags["motionBlur.enabled"]) then @params.motionBlur else defaults.motionBlur
3014 origin = if !isLocked(flags.origin) then @params.origin else defaults.origin
3015 instant = duration == 0 or @interpreter.isInstantSkip()
3016 noAnim = duration == 0 or GameManager.tempSettings.skip
3017
3018 if @params.waitForCompletion and not instant
3019 @interpreter.isWaiting = yes
3020 @interpreter.waitCounter = duration
3021
3022
3023 character = new vn.Object_Live2DCharacter(record)
3024 character.modelName = @params.model?.name || ""
3025 character.modelFolder = @params.model?.folderPath || "Live2D"
3026 character.model = ResourceManager.getLive2DModel("#{character.modelFolder ? "Live2D"}/#{character.modelName}")
3027 character.motion = { name: "", fadeInTime: 0, loop: true } if character.model.motions
3028 #character.expression = { name: Object.keys(character.model.expressions)[0], fadeInTime: 0 } if character.model.expressions
3029 character.dstRect.x = x
3030 character.dstRect.y = y
3031 character.anchor.x = if !origin then 0 else 0.5
3032 character.anchor.y = if !origin then 0 else 0.5
3033 character.blendMode = @interpreter.numberValueOf(@params.blendMode)
3034 character.zoom.x = @params.position.zoom.d
3035 character.zoom.y = @params.position.zoom.d
3036 character.zIndex = zIndex || 200
3037 character.model?.reset()
3038 character.setup()
3039 character.visual.l2dObject.idleIntensity = record.idleIntensity ? 1.0
3040 character.visual.l2dObject.breathIntensity = record.breathIntensity ? 1.0
3041 character.visual.l2dObject.lipSyncSensitivity = record.lipSyncSensitivity ? 1.0
3042
3043 character.update()
3044
3045 if @params.positionType == 0
3046 p = @interpreter.predefinedObjectPosition(@params.predefinedPositionId, character, @params)
3047 character.dstRect.x = p.x
3048 character.dstRect.y = p.y
3049
3050 scene.behavior.addCharacter(character, noAnim, { animation: animation, duration: duration, easing: easing, motionBlur: motionBlur})
3051
3052 if @params.viewport?.type == "ui"
3053 character.viewport = Graphics.viewport
3054
3055 gs.GameNotifier.postMinorChange()
3056 ###*
3057 * @method commandCharacterJoinScene
3058 * @protected
3059 ###
3060 commandCharacterJoinScene: ->
3061 defaults = GameManager.defaults.character
3062 flags = @params.fieldFlags || {}
3063 isLocked = gs.CommandFieldFlags.isLocked
3064 scene = SceneManager.scene
3065 characterId = @interpreter.stringValueOf(@params.characterId)
3066 expressionId = @interpreter.stringValueOf(@params.expressionId) || @params.expressionId
3067 record = RecordManager.characters[characterId]
3068
3069 return if !record or scene.characters.first (v) -> !v.disposed and v.rid == record.index and !v.disposed
3070
3071 character = new vn.Object_Character(record, null, scene)
3072 character.expression = RecordManager.characterExpressions[expressionId ? record.defaultExpressionId||0] #character.expression
3073 if character.expression?.idle[0]?.resource.name
3074 bitmap = ResourceManager.getBitmap(ResourceManager.getPath(character.expression.idle[0].resource))
3075 character.imageFolder = character.expression.idle[0].resource.folderPath
3076 mirror = no
3077 angle = 0
3078 zoom = 1
3079
3080 if @params.positionType == 1
3081 x = @interpreter.numberValueOf(@params.position.x)
3082 y = @interpreter.numberValueOf(@params.position.y)
3083 mirror = @params.position.horizontalFlip
3084 angle = @params.position.angle||0
3085 zoom = @params.position.data?.zoom || 1
3086 else if @params.positionType == 2
3087 x = @interpreter.numberValueOf(@params.position.x)
3088 y = @interpreter.numberValueOf(@params.position.y)
3089 mirror = no
3090 angle = 0
3091 zoom = 1
3092
3093 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut) else gs.Easings.fromObject(defaults.appearEasing)
3094 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.appearDuration
3095 origin = if !isLocked(flags.origin) then @params.origin else defaults.origin
3096 zIndex = if !isLocked(flags.zOrder) then @interpreter.numberValueOf(@params.zOrder) else defaults.zOrder
3097 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.appearAnimation
3098 motionBlur = if !isLocked(flags["motionBlur.enabled"]) then @params.motionBlur else defaults.motionBlur
3099 instant = duration == 0 or @interpreter.isInstantSkip()
3100 noAnim = duration == 0 or GameManager.tempSettings.skip
3101
3102 if @params.waitForCompletion and not instant
3103 @interpreter.isWaiting = yes
3104 @interpreter.waitCounter = duration
3105
3106 if character.expression?.idle[0]?.resource.name
3107 bitmap = ResourceManager.getBitmap(ResourceManager.getPath(character.expression.idle[0].resource))
3108 if origin == 1 and bitmap?
3109 x += (bitmap.width*zoom-bitmap.width)/2
3110 y += (bitmap.height*zoom-bitmap.height)/2
3111
3112 character.mirror = mirror
3113 character.anchor.x = if !origin then 0 else 0.5
3114 character.anchor.y = if !origin then 0 else 0.5
3115 character.zoom.x = zoom
3116 character.zoom.y = zoom
3117 character.dstRect.x = x
3118 character.dstRect.y = y
3119 character.zIndex = zIndex || 200
3120 character.blendMode = @interpreter.numberValueOf(@params.blendMode)
3121 character.angle = angle
3122 character.setup()
3123 character.update()
3124
3125 if @params.positionType == 0
3126 p = @interpreter.predefinedObjectPosition(@params.predefinedPositionId, character, @params)
3127 character.dstRect.x = p.x
3128 character.dstRect.y = p.y
3129
3130 scene.behavior.addCharacter(character, noAnim, { animation: animation, duration: duration, easing: easing, motionBlur: motionBlur})
3131
3132 if @params.viewport?.type == "ui"
3133 character.viewport = Graphics.viewport
3134
3135 gs.GameNotifier.postMinorChange()
3136
3137 ###*
3138 * @method commandCharacterExitScene
3139 * @protected
3140 ###
3141 commandCharacterExitScene: (defaults) ->
3142 defaults = defaults || GameManager.defaults.character
3143 flags = @params.fieldFlags || {}
3144 isLocked = gs.CommandFieldFlags.isLocked
3145 characterId = @interpreter.stringValueOf(@params.characterId)
3146
3147 scene = SceneManager.scene
3148 character = scene.characters.first (v) => !v.disposed and v.rid == characterId
3149
3150 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut) else gs.Easings.fromObject(defaults.disappearEasing)
3151 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.disappearDuration
3152 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.disappearAnimation
3153 instant = duration == 0 or @interpreter.isInstantSkip()
3154 noAnim = duration == 0 or GameManager.tempSettings.skip
3155
3156 if @params.waitForCompletion and not instant
3157 @interpreter.isWaiting = yes
3158 @interpreter.waitCounter = duration
3159
3160 scene.behavior.removeCharacter(character, noAnim, { animation: animation, duration: duration, easing: easing})
3161 gs.GameNotifier.postMinorChange()
3162
3163 ###*
3164 * @method commandCharacterChangeExpression
3165 * @protected
3166 ###
3167 commandCharacterChangeExpression: ->
3168 scene = SceneManager.scene
3169 characterId = @interpreter.stringValueOf(@params.characterId)
3170 character = scene.characters.first (v) => !v.disposed and v.rid == characterId
3171 if not character? then return
3172 defaults = GameManager.defaults.character
3173 flags = @params.fieldFlags || {}
3174 isLocked = gs.CommandFieldFlags.isLocked
3175
3176 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.expressionDuration
3177 expression = RecordManager.characterExpressions[@params.expressionId || 0]
3178 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromObject(@params.easing) else gs.Easings.fromObject(defaults.changeEasing)
3179 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.changeAnimation
3180
3181 character.behavior.changeExpression(expression, @params.animation, easing, duration)
3182
3183 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
3184 @interpreter.isWaiting = yes
3185 @interpreter.waitCounter = duration
3186
3187 gs.GameNotifier.postMinorChange()
3188
3189 ###*
3190 * @method commandCharacterSetParameter
3191 * @protected
3192 ###
3193 commandCharacterSetParameter: ->
3194 params = GameManager.characterParams[@interpreter.stringValueOf(@params.characterId)]
3195 if not params? or not @params.param? then return
3196
3197 switch @params.valueType
3198 when 0 # Number Value
3199 switch @params.param.type
3200 when 0 # Number
3201 params[@params.param.name] = @interpreter.numberValueOf(@params.numberValue)
3202 when 1 # Switch
3203 params[@params.param.name] = @interpreter.numberValueOf(@params.numberValue) > 0
3204 when 2 # Text
3205 params[@params.param.name] = @interpreter.numberValueOf(@params.numberValue).toString()
3206 when 1 # Switch Value
3207 switch @params.param.type
3208 when 0 # Number
3209 value = @interpreter.booleanValueOf(@params.switchValue)
3210 params[@params.param.name] = if value then 1 else 0
3211 when 1 # Switch
3212 params[@params.param.name] = @interpreter.booleanValueOf(@params.switchValue)
3213 when 2 # Text
3214 value = @interpreter.booleanValueOf(@params.switchValue)
3215 params[@params.param.name] = if value then "ON" else "OFF"
3216 when 2 # Text Value
3217 switch @params.param.type
3218 when 0 # Number
3219 value = @interpreter.stringValueOf(@params.textValue)
3220 params[@params.param.name] = value.length
3221 when 1 # Switch
3222 params[@params.param.name] = @interpreter.stringValueOf(@params.textValue) == "ON"
3223 when 2 # Text
3224 params[@params.param.name] = @interpreter.stringValueOf(@params.textValue)
3225
3226
3227
3228
3229 ###*
3230 * @method commandCharacterGetParameter
3231 * @protected
3232 ###
3233 commandCharacterGetParameter: ->
3234 params = GameManager.characterParams[@interpreter.stringValueOf(@params.characterId)]
3235 if not params? or not @params.param? then return
3236
3237 value = params[@params.param.name]
3238
3239 switch @params.valueType
3240 when 0 # Number Value
3241 switch @params.param.type
3242 when 0 # Number
3243 @interpreter.setNumberValueTo(@params.targetVariable, value)
3244 when 1 # Switch
3245 @interpreter.setNumberValueTo(@params.targetVariable, if value then 1 else 0)
3246 when 2 # Text
3247 @interpreter.setNumberValueTo(@params.targetVariable, if value? then value.length else 0)
3248 when 1 # Switch Value
3249 switch @params.param.type
3250 when 0 # Number
3251 @interpreter.setBooleanValueTo(@params.targetVariable, value > 0)
3252 when 1 # Switch
3253 @interpreter.setBooleanValueTo(@params.targetVariable, value)
3254 when 2 # Text
3255 @interpreter.setBooleanValueTo(@params.targetVariable, value == "ON")
3256
3257 when 2 # Text Value
3258 switch @params.param.type
3259 when 0 # Number
3260 @interpreter.setStringValueTo(@params.targetVariable, if value? then value.toString() else "")
3261 when 1 # Switch
3262 @interpreter.setStringValueTo(@params.targetVariable, if value then "ON" else "OFF")
3263 when 2 # Text
3264 @interpreter.setStringValueTo(@params.targetVariable, value)
3265
3266
3267
3268 ###*
3269 * @method commandCharacterMotionBlur
3270 * @protected
3271 ###
3272 commandCharacterMotionBlur: ->
3273 scene = SceneManager.scene
3274 characterId = @interpreter.stringValueOf(@params.characterId)
3275 character = scene.characters.first (v) => !v.disposed and v.rid == characterId
3276 if not character? then return
3277
3278 character.motionBlur.set(@params.motionBlur)
3279
3280 ###*
3281 * @method commandCharacterDefaults
3282 * @protected
3283 ###
3284 commandCharacterDefaults: ->
3285 defaults = GameManager.defaults.character
3286 flags = @params.fieldFlags || {}
3287 isLocked = gs.CommandFieldFlags.isLocked
3288
3289 if !isLocked(flags.appearDuration) then defaults.appearDuration = @interpreter.durationValueOf(@params.appearDuration)
3290 if !isLocked(flags.disappearDuration) then defaults.disappearDuration = @interpreter.durationValueOf(@params.disappearDuration)
3291 if !isLocked(flags.expressionDuration) then defaults.expressionDuration = @interpreter.durationValueOf(@params.expressionDuration)
3292 if !isLocked(flags.zOrder) then defaults.zOrder = @interpreter.numberValueOf(@params.zOrder)
3293 if !isLocked(flags["appearEasing.type"]) then defaults.appearEasing = @params.appearEasing
3294 if !isLocked(flags["appearAnimation.type"]) then defaults.appearAnimation = @params.appearAnimation
3295 if !isLocked(flags["disappearEasing.type"]) then defaults.disappearEasing = @params.disappearEasing
3296 if !isLocked(flags["disappearAnimation.type"]) then defaults.disappearAnimation = @params.disappearAnimation
3297 if !isLocked(flags["motionBlur.enabled"]) then defaults.motionBlur = @params.motionBlur
3298 if !isLocked(flags.origin) then defaults.origin = @params.origin
3299
3300 ###*
3301 * @method commandCharacterEffect
3302 * @protected
3303 ###
3304 commandCharacterEffect: ->
3305 scene = SceneManager.scene
3306 characterId = @interpreter.stringValueOf(@params.characterId)
3307 character = scene.characters.first (c) -> !c.disposed and c.rid == characterId
3308 if not character? then return
3309
3310 @interpreter.objectEffect(character, @params)
3311
3312 gs.GameNotifier.postMinorChange()
3313
3314 ###*
3315 * @method commandFlashCharacter
3316 * @protected
3317 ###
3318 commandFlashCharacter: ->
3319 scene = SceneManager.scene
3320 characterId = @interpreter.stringValueOf(@params.characterId)
3321 character = scene.characters.first (v) => !v.disposed and v.rid == characterId
3322 return if not character
3323
3324 duration = @interpreter.durationValueOf(@params.duration)
3325 character.animator.flash(new Color(@params.color), duration)
3326 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
3327 @interpreter.isWaiting = yes
3328 @interpreter.waitCounter = duration
3329
3330 gs.GameNotifier.postMinorChange()
3331
3332 ###*
3333 * @method commandTintCharacter
3334 * @protected
3335 ###
3336 commandTintCharacter: ->
3337 scene = SceneManager.scene
3338 characterId = @interpreter.stringValueOf(@params.characterId)
3339 character = scene.characters.first (v) => !v.disposed and v.rid == characterId
3340 easing = gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut)
3341 return if not character
3342
3343 duration = @interpreter.durationValueOf(@params.duration)
3344 character.animator.tintTo(@params.tone, duration, easing)
3345 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
3346 @interpreter.isWaiting = yes
3347 @interpreter.waitCounter = duration
3348
3349 gs.GameNotifier.postMinorChange()
3350
3351 ###*
3352 * @method commandZoomCharacter
3353 * @protected
3354 ###
3355 commandZoomCharacter: ->
3356 scene = SceneManager.scene
3357 characterId = @interpreter.stringValueOf(@params.characterId)
3358 character = scene.characters.first (v) => !v.disposed and v.rid == characterId
3359 if not character? then return
3360
3361 @interpreter.zoomObject(character, @params)
3362
3363 gs.GameNotifier.postMinorChange()
3364
3365 ###*
3366 * @method commandRotateCharacter
3367 * @protected
3368 ###
3369 commandRotateCharacter: ->
3370 scene = SceneManager.scene
3371 characterId = @interpreter.stringValueOf(@params.characterId)
3372 character = scene.characters.first (v) => !v.disposed and v.rid == characterId
3373 if not character? then return
3374
3375 @interpreter.rotateObject(character, @params)
3376
3377 gs.GameNotifier.postMinorChange()
3378
3379 ###*
3380 * @method commandBlendCharacter
3381 * @protected
3382 ###
3383 commandBlendCharacter: ->
3384 characterId = @interpreter.stringValueOf(@params.characterId)
3385 character = SceneManager.scene.characters.first (v) => !v.disposed and v.rid == characterId
3386 if not character? then return
3387
3388 @interpreter.blendObject(character, @params)
3389
3390 gs.GameNotifier.postMinorChange()
3391
3392 ###*
3393 * @method commandShakeCharacter
3394 * @protected
3395 ###
3396 commandShakeCharacter: ->
3397 characterId = @interpreter.stringValueOf(@params.characterId)
3398 character = SceneManager.scene.characters.first (v) => !v.disposed and v.rid == characterId
3399 if not character? then return
3400 @interpreter.shakeObject(character, @params)
3401
3402 gs.GameNotifier.postMinorChange()
3403
3404 ###*
3405 * @method commandMaskCharacter
3406 * @protected
3407 ###
3408 commandMaskCharacter: ->
3409 scene = SceneManager.scene
3410 characterId = @interpreter.stringValueOf(@params.characterId)
3411 character = scene.characters.first (v) => !v.disposed and v.rid == characterId
3412 if not character? then return
3413
3414 @interpreter.maskObject(character, @params)
3415
3416 gs.GameNotifier.postMinorChange()
3417
3418 ###*
3419 * @method commandMoveCharacter
3420 * @protected
3421 ###
3422 commandMoveCharacter: ->
3423 scene = SceneManager.scene
3424 characterId = @interpreter.stringValueOf(@params.characterId)
3425 character = scene.characters.first (v) => !v.disposed and v.rid == characterId
3426 if not character? then return
3427
3428 @interpreter.moveObject(character, @params.position, @params)
3429
3430 gs.GameNotifier.postMinorChange()
3431
3432 ###*
3433 * @method commandMoveCharacterPath
3434 * @protected
3435 ###
3436 commandMoveCharacterPath: ->
3437 scene = SceneManager.scene
3438 characterId = @interpreter.stringValueOf(@params.characterId)
3439 character = scene.characters.first (v) => !v.disposed and v.rid == characterId
3440 if not character? then return
3441
3442 @interpreter.moveObjectPath(character, @params.path, @params)
3443
3444 gs.GameNotifier.postMinorChange()
3445
3446 ###*
3447 * @method commandShakeBackground
3448 * @protected
3449 ###
3450 commandShakeBackground: ->
3451 background = SceneManager.scene.backgrounds[@interpreter.numberValueOf(@params.layer)]
3452 if not background? then return
3453
3454 @interpreter.shakeObject(background, @params)
3455
3456 gs.GameNotifier.postMinorChange()
3457
3458 ###*
3459 * @method commandScrollBackground
3460 * @protected
3461 ###
3462 commandScrollBackground: ->
3463 scene = SceneManager.scene
3464 duration = @interpreter.durationValueOf(@params.duration)
3465 horizontalSpeed = @interpreter.numberValueOf(@params.horizontalSpeed)
3466 verticalSpeed = @interpreter.numberValueOf(@params.verticalSpeed)
3467 easing = gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut)
3468 layer = @interpreter.numberValueOf(@params.layer)
3469 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
3470 @interpreter.isWaiting = yes
3471 @interpreter.waitCounter = duration
3472
3473 scene.backgrounds[layer]?.animator.move(horizontalSpeed, verticalSpeed, duration, easing)
3474
3475 gs.GameNotifier.postMinorChange()
3476
3477 ###*
3478 * @method commandScrollBackgroundTo
3479 * @protected
3480 ###
3481 commandScrollBackgroundTo: ->
3482 scene = SceneManager.scene
3483 duration = @interpreter.durationValueOf(@params.duration)
3484 x = @interpreter.numberValueOf(@params.background.location.x)
3485 y = @interpreter.numberValueOf(@params.background.location.y)
3486 easing = gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut)
3487 layer = @interpreter.numberValueOf(@params.layer)
3488 background = scene.backgrounds[layer]
3489 if !background then return
3490
3491 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
3492 @interpreter.isWaiting = yes
3493 @interpreter.waitCounter = duration
3494
3495 if @params.positionType == 0
3496 p = @interpreter.predefinedObjectPosition(@params.predefinedPositionId, background, @params)
3497 x = p.x
3498 y = p.y
3499
3500 background.animator.moveTo(x, y, duration, easing)
3501
3502 gs.GameNotifier.postMinorChange()
3503
3504 ###*
3505 * @method commandScrollBackgroundPath
3506 * @protected
3507 ###
3508 commandScrollBackgroundPath: ->
3509 scene = SceneManager.scene
3510 background = scene.backgrounds[@interpreter.numberValueOf(@params.layer)]
3511 return unless background?
3512
3513 @interpreter.moveObjectPath(background, @params.path, @params)
3514
3515 gs.GameNotifier.postMinorChange()
3516
3517 ###*
3518 * @method commandMaskBackground
3519 * @protected
3520 ###
3521 commandMaskBackground: ->
3522 scene = SceneManager.scene
3523 background = scene.backgrounds[@interpreter.numberValueOf(@params.layer)]
3524 return unless background?
3525
3526 @interpreter.maskObject(background, @params)
3527
3528 gs.GameNotifier.postMinorChange()
3529
3530 ###*
3531 * @method commandZoomBackground
3532 * @protected
3533 ###
3534 commandZoomBackground: ->
3535 scene = SceneManager.scene
3536 duration = @interpreter.durationValueOf(@params.duration)
3537 x = @interpreter.numberValueOf(@params.zooming.x)
3538 y = @interpreter.numberValueOf(@params.zooming.y)
3539 easing = gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut)
3540 layer = @interpreter.numberValueOf(@params.layer)
3541 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
3542 @interpreter.isWaiting = yes
3543 @interpreter.waitCounter = duration
3544
3545 scene.backgrounds[layer]?.animator.zoomTo(x / 100, y / 100, duration, easing)
3546
3547 gs.GameNotifier.postMinorChange()
3548
3549 ###*
3550 * @method commandRotateBackground
3551 * @protected
3552 ###
3553 commandRotateBackground: ->
3554 scene = SceneManager.scene
3555 background = scene.backgrounds[@interpreter.numberValueOf(@params.layer)]
3556
3557 if background
3558 @interpreter.rotateObject(background, @params)
3559
3560 gs.GameNotifier.postMinorChange()
3561
3562 ###*
3563 * @method commandTintBackground
3564 * @protected
3565 ###
3566 commandTintBackground: ->
3567 scene = SceneManager.scene
3568 layer = @interpreter.numberValueOf(@params.layer)
3569 background = scene.backgrounds[layer]
3570 if not background? then return
3571
3572 duration = @interpreter.durationValueOf(@params.duration)
3573 easing = gs.Easings.fromObject(@params.easing)
3574 background.animator.tintTo(@params.tone, duration, easing)
3575
3576 @interpreter.waitForCompletion(background, @params)
3577
3578 gs.GameNotifier.postMinorChange()
3579
3580 ###*
3581 * @method commandBlendBackground
3582 * @protected
3583 ###
3584 commandBlendBackground: ->
3585 layer = @interpreter.numberValueOf(@params.layer)
3586 background = SceneManager.scene.backgrounds[layer]
3587 if not background? then return
3588
3589 @interpreter.blendObject(background, @params)
3590
3591 gs.GameNotifier.postMinorChange()
3592
3593 ###*
3594 * @method commandBackgroundEffect
3595 * @protected
3596 ###
3597 commandBackgroundEffect: ->
3598 layer = @interpreter.numberValueOf(@params.layer)
3599 background = SceneManager.scene.backgrounds[layer]
3600 if not background? then return
3601
3602 @interpreter.objectEffect(background, @params)
3603
3604 gs.GameNotifier.postMinorChange()
3605
3606 ###*
3607 * @method commandBackgroundDefaults
3608 * @protected
3609 ###
3610 commandBackgroundDefaults: ->
3611 defaults = GameManager.defaults.background
3612 flags = @params.fieldFlags || {}
3613 isLocked = gs.CommandFieldFlags.isLocked
3614
3615 if !isLocked(flags.duration) then defaults.duration = @interpreter.durationValueOf(@params.duration)
3616 if !isLocked(flags.zOrder) then defaults.zOrder = @interpreter.numberValueOf(@params.zOrder)
3617 if !isLocked(flags["easing.type"]) then defaults.easing = @params.easing
3618 if !isLocked(flags["animation.type"]) then defaults.animation = @params.animation
3619 if !isLocked(flags.origin) then defaults.origin = @params.origin
3620 if !isLocked(flags.loopHorizontal) then defaults.loopHorizontal = @params.loopHorizontal
3621 if !isLocked(flags.loopVertical) then defaults.loopVertical = @params.loopVertical
3622
3623 ###*
3624 * @method commandBackgroundMotionBlur
3625 * @protected
3626 ###
3627 commandBackgroundMotionBlur: ->
3628 layer = @interpreter.numberValueOf(@params.layer)
3629 background = SceneManager.scene.backgrounds[layer]
3630 if not background? then return
3631
3632 background.motionBlur.set(@params.motionBlur)
3633
3634 ###*
3635 * @method commandChangeBackground
3636 * @protected
3637 ###
3638 commandChangeBackground: ->
3639 defaults = GameManager.defaults.background
3640 scene = SceneManager.scene
3641 flags = @params.fieldFlags || {}
3642 isLocked = gs.CommandFieldFlags.isLocked
3643 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.duration
3644 loopH = if !isLocked(flags.loopHorizontal) then @params.loopHorizontal else defaults.loopHorizontal
3645 loopV = if !isLocked(flags.loopVertical) then @params.loopVertical else defaults.loopVertical
3646 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.animation
3647 origin = if !isLocked(flags.origin) then @params.origin else defaults.origin
3648 zIndex = if !isLocked(flags.zOrder) then @interpreter.numberValueOf(@params.zOrder) else defaults.zOrder
3649
3650 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
3651 @interpreter.isWaiting = yes
3652 @interpreter.waitCounter = duration
3653
3654 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromObject(@params.easing) else gs.Easings.fromObject(defaults.easing)
3655 layer = @interpreter.numberValueOf(@params.layer)
3656 scene.behavior.changeBackground(@params.graphic, no, animation, easing, duration, 0, 0, layer, loopH, loopV)
3657
3658 if scene.backgrounds[layer]
3659 if @params.viewport?.type == "ui"
3660 scene.backgrounds[layer].viewport = Graphics.viewport
3661 scene.backgrounds[layer].anchor.x = if origin == 0 then 0 else 0.5
3662 scene.backgrounds[layer].anchor.y = if origin == 0 then 0 else 0.5
3663 scene.backgrounds[layer].blendMode = @interpreter.numberValueOf(@params.blendMode)
3664 scene.backgrounds[layer].zIndex = zIndex + layer
3665
3666 if origin == 1
3667 scene.backgrounds[layer].dstRect.x = scene.backgrounds[layer].dstRect.x# + scene.backgrounds[layer].bitmap.width/2
3668 scene.backgrounds[layer].dstRect.y = scene.backgrounds[layer].dstRect.y# + scene.backgrounds[layer].bitmap.height/2
3669 scene.backgrounds[layer].setup()
3670 scene.backgrounds[layer].update()
3671
3672 gs.GameNotifier.postMinorChange()
3673
3674 ###*
3675 * @method commandCallScene
3676 * @protected
3677 ###
3678 commandCallScene: ->
3679 @interpreter.callScene(@interpreter.stringValueOf(@params.scene.uid || @params.scene))
3680
3681 ###*
3682 * @method commandChangeScene
3683 * @protected
3684 ###
3685 commandChangeScene: ->
3686 if GameManager.inLivePreview then return
3687 GameManager.tempSettings.skip = no
3688
3689 if !@params.savePrevious
3690 SceneManager.clear()
3691
3692 scene = SceneManager.scene
3693 if !@params.erasePictures and !@params.savePrevious
3694 scene.removeObject(scene.pictureContainer)
3695 for picture in scene.pictures
3696 ResourceManager.context.remove("#{picture.imageFolder}/#{picture.image}") if picture
3697 if !@params.eraseTexts and !@params.savePrevious
3698 scene.removeObject(scene.textContainer)
3699 if !@params.eraseVideos and !@params.savePrevious
3700 scene.removeObject(scene.videoContainer)
3701 for video in scene.videos
3702 ResourceManager.context.remove("#{video.videoFolder}/#{video.video}") if video
3703
3704 if @params.scene
3705 paramScene = uid: @interpreter.stringValueOf(@params.scene.uid || @params.scene)
3706 if @params.savePrevious
3707 GameManager.sceneData = uid: uid = paramScene.uid, pictures: [], texts: [], videos: []
3708 else
3709 GameManager.sceneData = {
3710 uid: uid = paramScene.uid,
3711 pictures: scene.pictureContainer.subObjectsByDomain,
3712 texts: scene.textContainer.subObjectsByDomain,
3713 videos: scene.videoContainer.subObjectsByDomain
3714 }
3715
3716 flags = @params.fieldFlags || {}
3717 isLocked = gs.CommandFieldFlags.isLocked
3718 newScene = new vn.Object_Scene()
3719 if @params.savePrevious
3720 newScene.sceneData = uid: uid = paramScene.uid, pictures: [], texts: [], videos: [], backlog: GameManager.backlog
3721 else
3722 newScene.sceneData = uid: uid = paramScene.uid, pictures: scene.pictureContainer.subObjectsByDomain, texts: scene.textContainer.subObjectsByDomain, videos: scene.videoContainer.subObjectsByDomain
3723
3724 SceneManager.switchTo(newScene, @params.savePrevious, => @interpreter.isWaiting = no)
3725 else
3726 SceneManager.switchTo(null)
3727
3728 @interpreter.isWaiting = yes
3729
3730 ###*
3731 * @method commandReturnToPreviousScene
3732 * @protected
3733 ###
3734 commandReturnToPreviousScene: ->
3735 if GameManager.inLivePreview then return
3736 SceneManager.returnToPrevious(=> @interpreter.isWaiting = no)
3737
3738 @interpreter.isWaiting = yes
3739
3740
3741 ###*
3742 * @method commandSwitchToLayout
3743 * @protected
3744 ###
3745 commandSwitchToLayout: ->
3746 if GameManager.inLivePreview then return
3747 if ui.UIManager.layouts[@params.layout.name]?
3748 scene = new gs.Object_Layout(@params.layout.name)
3749 SceneManager.switchTo(scene, @params.savePrevious, => @interpreter.isWaiting = no)
3750 @interpreter.isWaiting = yes
3751
3752 ###*
3753 * @method commandChangeTransition
3754 * @protected
3755 ###
3756 commandChangeTransition: ->
3757 flags = @params.fieldFlags || {}
3758 isLocked = gs.CommandFieldFlags.isLocked
3759
3760 if !isLocked(flags.duration)
3761 SceneManager.transitionData.duration = @interpreter.durationValueOf(@params.duration)
3762 if !isLocked(flags.graphic)
3763 SceneManager.transitionData.graphic = @params.graphic
3764 if !isLocked(flags.vague)
3765 SceneManager.transitionData.vague = @params.vague
3766
3767 ###*
3768 * @method commandFreezeScreen
3769 * @protected
3770 ###
3771 commandFreezeScreen: ->
3772 Graphics.freeze()
3773
3774 ###*
3775 * @method commandScreenTransition
3776 * @protected
3777 ###
3778 commandScreenTransition: ->
3779 defaults = GameManager.defaults.scene
3780 flags = @params.fieldFlags || {}
3781 isLocked = gs.CommandFieldFlags.isLocked
3782 graphic = if !isLocked(flags.graphic) then @params.graphic else SceneManager.transitionData.graphic
3783
3784 if graphic
3785 bitmap = ResourceManager.getBitmap(ResourceManager.getPath(graphic))
3786 vague = if !isLocked(flags.vague) then @interpreter.numberValueOf(@params.vague) else SceneManager.transitionData.vague
3787 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else SceneManager.transitionData.duration
3788
3789 @interpreter.isWaiting = !GameManager.inLivePreview
3790 @interpreter.waitCounter = duration
3791
3792
3793 Graphics.transition(duration, bitmap, vague)
3794
3795 ###*
3796 * @method commandShakeScreen
3797 * @protected
3798 ###
3799 commandShakeScreen: ->
3800 if not SceneManager.scene.viewport? then return
3801
3802 @interpreter.shakeObject(SceneManager.scene.viewport, @params)
3803 gs.GameNotifier.postMinorChange()
3804
3805
3806 ###*
3807 * @method commandTintScreen
3808 * @protected
3809 ###
3810 commandTintScreen: ->
3811 duration = @interpreter.durationValueOf(@params.duration)
3812 SceneManager.scene.viewport.animator.tintTo(new Tone(@params.tone), duration, gs.Easings.EASE_LINEAR[0])
3813
3814 if @params.waitForCompletion and duration > 0
3815 @interpreter.isWaiting = yes
3816 @interpreter.waitCounter = duration
3817 gs.GameNotifier.postMinorChange()
3818
3819 ###*
3820 * @method commandZoomScreen
3821 * @protected
3822 ###
3823 commandZoomScreen: ->
3824 easing = gs.Easings.fromObject(@params.easing)
3825 duration = @interpreter.durationValueOf(@params.duration)
3826 scene = SceneManager.scene
3827
3828 SceneManager.scene.viewport.anchor.x = 0.5
3829 SceneManager.scene.viewport.anchor.y = 0.5
3830 SceneManager.scene.viewport.animator.zoomTo(@interpreter.numberValueOf(@params.zooming.x) / 100, @interpreter.numberValueOf(@params.zooming.y) / 100, duration, easing)
3831
3832 @interpreter.waitForCompletion(null, @params)
3833 gs.GameNotifier.postMinorChange()
3834
3835 ###*
3836 * @method commandPanScreen
3837 * @protected
3838 ###
3839 commandPanScreen: ->
3840 scene = SceneManager.scene
3841 duration = @interpreter.durationValueOf(@params.duration)
3842 easing = gs.Easings.fromObject(@params.easing)
3843 px = @params.position.x
3844 py = @params.position.y
3845 @interpreter.settings.screen.pan.x -= px
3846 @interpreter.settings.screen.pan.y -= py
3847 viewport = SceneManager.scene.viewport
3848
3849 viewport.animator.scrollTo(-px + viewport.dstRect.x, -py + viewport.dstRect.y, duration, easing)
3850 @interpreter.waitForCompletion(null, @params)
3851 gs.GameNotifier.postMinorChange()
3852
3853 ###*
3854 * @method commandRotateScreen
3855 * @protected
3856 ###
3857 commandRotateScreen: ->
3858 scene = SceneManager.scene
3859
3860 easing = gs.Easings.fromObject(@params.easing)
3861 duration = @interpreter.durationValueOf(@params.duration)
3862 pan = @interpreter.settings.screen.pan
3863
3864 SceneManager.scene.viewport.anchor.x = 0.5
3865 SceneManager.scene.viewport.anchor.y = 0.5
3866 SceneManager.scene.viewport.animator.rotate(@params.direction, @interpreter.numberValueOf(@params.speed) / 100, duration, easing)
3867
3868 @interpreter.waitForCompletion(null, @params)
3869 gs.GameNotifier.postMinorChange()
3870
3871 ###*
3872 * @method commandFlashScreen
3873 * @protected
3874 ###
3875 commandFlashScreen: ->
3876 duration = @interpreter.durationValueOf(@params.duration)
3877 SceneManager.scene.viewport.animator.flash(new Color(@params.color), duration, gs.Easings.EASE_LINEAR[0])
3878
3879 if @params.waitForCompletion and duration != 0
3880 @interpreter.isWaiting = yes
3881 @interpreter.waitCounter = duration
3882 gs.GameNotifier.postMinorChange()
3883
3884
3885 ###*
3886 * @method commandScreenEffect
3887 * @protected
3888 ###
3889 commandScreenEffect: ->
3890 scene = SceneManager.scene
3891 flags = @params.fieldFlags || {}
3892 isLocked = gs.CommandFieldFlags.isLocked
3893 duration = @interpreter.durationValueOf(@params.duration)
3894 easing = gs.Easings.fromObject(@params.easing)
3895
3896 if !gs.CommandFieldFlags.isLocked(flags.zOrder)
3897 zOrder = @interpreter.numberValueOf(@params.zOrder)
3898 else
3899 zOrder = SceneManager.scene.viewport.zIndex
3900
3901 viewport = scene.viewportContainer.subObjects.first (v) -> v.zIndex == zOrder
3902
3903 if !viewport
3904 viewport = new gs.Object_Viewport()
3905 viewport.zIndex = zOrder
3906 scene.viewportContainer.addObject(viewport)
3907
3908 switch @params.type
3909 when 0 # Wobble
3910 viewport.animator.wobbleTo(@params.wobble.power / 10000, @params.wobble.speed / 100, duration, easing)
3911 wobble = viewport.effects.wobble
3912 wobble.enabled = @params.wobble.power > 0
3913 wobble.vertical = @params.wobble.orientation == 0 or @params.wobble.orientation == 2
3914 wobble.horizontal = @params.wobble.orientation == 1 or @params.wobble.orientation == 2
3915 when 1 # Blur
3916 viewport.animator.blurTo(@params.blur.power / 100, duration, easing)
3917 viewport.effects.blur.enabled = yes
3918 when 2 # Pixelate
3919 viewport.animator.pixelateTo(@params.pixelate.size.width, @params.pixelate.size.height, duration, easing)
3920 viewport.effects.pixelate.enabled = yes
3921
3922 if @params.waitForCompletion and duration != 0
3923 @interpreter.isWaiting = yes
3924 @interpreter.waitCounter = duration
3925 gs.GameNotifier.postMinorChange()
3926
3927 ###*
3928 * @method commandVideoDefaults
3929 * @protected
3930 ###
3931 commandVideoDefaults: ->
3932 defaults = GameManager.defaults.video
3933 flags = @params.fieldFlags || {}
3934 isLocked = gs.CommandFieldFlags.isLocked
3935
3936 if !isLocked(flags.appearDuration) then defaults.appearDuration = @interpreter.durationValueOf(@params.appearDuration)
3937 if !isLocked(flags.disappearDuration) then defaults.disappearDuration = @interpreter.durationValueOf(@params.disappearDuration)
3938 if !isLocked(flags.zOrder) then defaults.zOrder = @interpreter.numberValueOf(@params.zOrder)
3939 if !isLocked(flags["appearEasing.type"]) then defaults.appearEasing = @params.appearEasing
3940 if !isLocked(flags["appearAnimation.type"]) then defaults.appearAnimation = @params.appearAnimation
3941 if !isLocked(flags["disappearEasing.type"]) then defaults.disappearEasing = @params.disappearEasing
3942 if !isLocked(flags["disappearAnimation.type"]) then defaults.disappearAnimation = @params.disappearAnimation
3943 if !isLocked(flags["motionBlur.enabled"]) then defaults.motionBlur = @params.motionBlur
3944 if !isLocked(flags.origin) then defaults.origin = @params.origin
3945
3946
3947 ###*
3948 * @method commandShowVideo
3949 * @protected
3950 ###
3951 commandShowVideo: ->
3952 defaults = GameManager.defaults.video
3953 flags = @params.fieldFlags || {}
3954 isLocked = gs.CommandFieldFlags.isLocked
3955 scene = SceneManager.scene
3956 scene.behavior.changeVideoDomain(@params.numberDomain)
3957 number = @interpreter.numberValueOf(@params.number)
3958 videos = scene.videos
3959 if not videos[number]? then videos[number] = new gs.Object_Video()
3960
3961 x = @interpreter.numberValueOf(@params.position.x)
3962 y = @interpreter.numberValueOf(@params.position.y)
3963
3964 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut) else gs.Easings.fromObject(defaults.appearEasing)
3965 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.appearDuration
3966 origin = if !isLocked(flags.origin) then @params.origin else defaults.origin
3967 zIndex = if !isLocked(flags.zOrder) then @interpreter.numberValueOf(@params.zOrder) else defaults.zOrder
3968 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.appearAnimation
3969
3970 video = videos[number]
3971 video.domain = @params.numberDomain
3972 video.video = @params.video?.name
3973 video.videoFolder = @params.video?.folderPath
3974 video.loop = @params.loop ? yes
3975 video.dstRect.x = x
3976 video.dstRect.y = y
3977 video.blendMode = @interpreter.numberValueOf(@params.blendMode)
3978 video.anchor.x = if origin == 0 then 0 else 0.5
3979 video.anchor.y = if origin == 0 then 0 else 0.5
3980 video.zIndex = zIndex || (1000 + number)
3981 if @params.viewport?.type == "scene"
3982 video.viewport = SceneManager.scene.behavior.viewport
3983 video.update()
3984
3985 if @params.positionType == 0
3986 p = @interpreter.predefinedObjectPosition(@params.predefinedPositionId, video, @params)
3987 video.dstRect.x = p.x
3988 video.dstRect.y = p.y
3989
3990 video.animator.appear(x, y, animation, easing, duration)
3991
3992 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
3993 @interpreter.isWaiting = yes
3994 @interpreter.waitCounter = duration
3995 gs.GameNotifier.postMinorChange()
3996
3997 ###*
3998 * @method commandMoveVideo
3999 * @protected
4000 ###
4001 commandMoveVideo: ->
4002 scene = SceneManager.scene
4003 scene.behavior.changeVideoDomain(@params.numberDomain)
4004 number = @interpreter.numberValueOf(@params.number)
4005 video = scene.videos[number]
4006 if not video? then return
4007
4008 @interpreter.moveObject(video, @params.picture.position, @params)
4009
4010 gs.GameNotifier.postMinorChange()
4011
4012 ###*
4013 * @method commandMoveVideoPath
4014 * @protected
4015 ###
4016 commandMoveVideoPath: ->
4017 scene = SceneManager.scene
4018 scene.behavior.changeVideoDomain(@params.numberDomain)
4019 number = @interpreter.numberValueOf(@params.number)
4020 video = scene.videos[number]
4021 if not video? then return
4022
4023 @interpreter.moveObjectPath(video, @params)
4024
4025 gs.GameNotifier.postMinorChange()
4026
4027 ###*
4028 * @method commandRotateVideo
4029 * @protected
4030 ###
4031 commandRotateVideo: ->
4032 scene = SceneManager.scene
4033 scene.behavior.changeVideoDomain(@params.numberDomain)
4034 number = @interpreter.numberValueOf(@params.number)
4035 video = scene.videos[number]
4036 if not video? then return
4037
4038 @interpreter.rotateObject(video, @params)
4039
4040 gs.GameNotifier.postMinorChange()
4041
4042 ###*
4043 * @method commandZoomVideo
4044 * @protected
4045 ###
4046 commandZoomVideo: ->
4047 scene = SceneManager.scene
4048 scene.behavior.changeVideoDomain(@params.numberDomain)
4049 number = @interpreter.numberValueOf(@params.number)
4050 video = scene.videos[number]
4051 if not video? then return
4052
4053 @interpreter.zoomObject(video, @params)
4054
4055 gs.GameNotifier.postMinorChange()
4056
4057 ###*
4058 * @method commandBlendVideo
4059 * @protected
4060 ###
4061 commandBlendVideo: ->
4062 SceneManager.scene.behavior.changeVideoDomain(@params.numberDomain)
4063 video = SceneManager.scene.videos[@interpreter.numberValueOf(@params.number)]
4064 if not video? then return
4065
4066 @interpreter.blendObject(video, @params)
4067
4068 gs.GameNotifier.postMinorChange()
4069
4070 ###*
4071 * @method commandTintVideo
4072 * @protected
4073 ###
4074 commandTintVideo: ->
4075 scene = SceneManager.scene
4076 scene.behavior.changeVideoDomain(@params.numberDomain)
4077 number = @interpreter.numberValueOf(@params.number)
4078 video = scene.videos[number]
4079 if not video? then return
4080
4081 @interpreter.tintObject(video, @params)
4082
4083 gs.GameNotifier.postMinorChange()
4084
4085 ###*
4086 * @method commandFlashVideo
4087 * @protected
4088 ###
4089 commandFlashVideo: ->
4090 scene = SceneManager.scene
4091 scene.behavior.changeVideoDomain(@params.numberDomain)
4092 number = @interpreter.numberValueOf(@params.number)
4093 video = scene.videos[number]
4094 if not video? then return
4095
4096 @interpreter.flashObject(video, @params)
4097
4098 gs.GameNotifier.postMinorChange()
4099
4100 ###*
4101 * @method commandCropVideo
4102 * @protected
4103 ###
4104 commandCropVideo: ->
4105 scene = SceneManager.scene
4106 scene.behavior.changeVideoDomain(@params.numberDomain)
4107 number = @interpreter.numberValueOf(@params.number)
4108 video = scene.videos[number]
4109 if not video? then return
4110
4111 @interpreter.cropObject(video, @params)
4112
4113
4114 ###*
4115 * @method commandVideoMotionBlur
4116 * @protected
4117 ###
4118 commandVideoMotionBlur: ->
4119 scene = SceneManager.scene
4120 scene.behavior.changeVideoDomain(@params.numberDomain)
4121 number = @interpreter.numberValueOf(@params.number)
4122 video = scene.videos[number]
4123 if not video? then return
4124
4125 @interpreter.objectMotionBlur(video, @params)
4126
4127 ###*
4128 * @method commandMaskVideo
4129 * @protected
4130 ###
4131 commandMaskVideo: ->
4132 scene = SceneManager.scene
4133 scene.behavior.changeVideoDomain(@params.numberDomain)
4134 number = @interpreter.numberValueOf(@params.number)
4135 video = scene.videos[number]
4136 if not video? then return
4137
4138 @interpreter.maskObject(video, @params)
4139
4140 gs.GameNotifier.postMinorChange()
4141
4142 ###*
4143 * @method commandVideoEffect
4144 * @protected
4145 ###
4146 commandVideoEffect: ->
4147 scene = SceneManager.scene
4148 scene.behavior.changeVideoDomain(@params.numberDomain)
4149 number = @interpreter.numberValueOf(@params.number)
4150 video = scene.videos[number]
4151 if not video? then return
4152
4153 @interpreter.objectEffect(video, @params)
4154 gs.GameNotifier.postMinorChange()
4155
4156 ###*
4157 * @method commandEraseVideo
4158 * @protected
4159 ###
4160 commandEraseVideo: ->
4161 defaults = GameManager.defaults.video
4162 flags = @params.fieldFlags || {}
4163 isLocked = gs.CommandFieldFlags.isLocked
4164 scene = SceneManager.scene
4165 scene.behavior.changeVideoDomain(@params.numberDomain)
4166 number = @interpreter.numberValueOf(@params.number)
4167 video = scene.videos[number]
4168 if not video? then return
4169
4170 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut) else gs.Easings.fromObject(defaults.disappearEasing)
4171 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.disappearDuration
4172 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.disappearAnimation
4173
4174 video.animator.disappear(animation, easing, duration, (sender) =>
4175 sender.dispose()
4176 scene.behavior.changeTextDomain(sender.domain)
4177 scene.videos[number] = null
4178 # sender.video.pause()
4179 )
4180
4181 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
4182 @interpreter.isWaiting = yes
4183 @interpreter.waitCounter = duration
4184 gs.GameNotifier.postMinorChange()
4185
4186 ###*
4187 * @method commandShowImageMap
4188 * @protected
4189 ###
4190 commandShowImageMap: ->
4191 flags = @params.fieldFlags || {}
4192 isLocked = gs.CommandFieldFlags.isLocked
4193 SceneManager.scene.behavior.changePictureDomain(@params.numberDomain)
4194 number = @interpreter.numberValueOf(@params.number)
4195 imageMap = SceneManager.scene.pictures[number]
4196 if imageMap
4197 imageMap.dispose()
4198 imageMap = new gs.Object_ImageMap()
4199 imageMap.visual.variableContext = @interpreter.context
4200 SceneManager.scene.pictures[number] = imageMap
4201 bitmap = ResourceManager.getBitmap(ResourceManager.getPath(@params.ground))
4202
4203 imageMap.dstRect.width = bitmap.width
4204 imageMap.dstRect.height = bitmap.height
4205
4206 if @params.positionType == 0
4207 p = @interpreter.predefinedObjectPosition(@params.predefinedPositionId, imageMap, @params)
4208 imageMap.dstRect.x = p.x
4209 imageMap.dstRect.y = p.y
4210 else
4211 imageMap.dstRect.x = @interpreter.numberValueOf(@params.position.x)
4212 imageMap.dstRect.y = @interpreter.numberValueOf(@params.position.y)
4213
4214 imageMap.anchor.x = if @params.origin == 1 then 0.5 else 0
4215 imageMap.anchor.y = if @params.origin == 1 then 0.5 else 0
4216 imageMap.zIndex = if !isLocked(flags.zOrder) then @interpreter.numberValueOf(@params.zOrder) else (700 + number)
4217 imageMap.blendMode = if !isLocked(flags.blendMode) then @params.blendMode else 0
4218 imageMap.hotspots = @params.hotspots
4219 imageMap.images = [
4220 @params.ground,
4221 @params.hover,
4222 @params.unselected,
4223 @params.selected,
4224 @params.selectedHover
4225 ]
4226
4227 imageMap.events.on "jumpTo", gs.CallBack("onJumpTo", @interpreter)
4228 imageMap.events.on "callCommonEvent", gs.CallBack("onCallCommonEvent", @interpreter)
4229
4230 imageMap.setup()
4231 imageMap.update()
4232
4233 @interpreter.showObject(imageMap, {x:0, y:0}, @params)
4234
4235 if @params.waitForCompletion
4236 @interpreter.waitCounter = 0
4237 @interpreter.isWaiting = yes
4238
4239 imageMap.events.on "finish", (sender) =>
4240 @interpreter.isWaiting = no
4241 # @interpreter.eraseObject(scene.imageMap, @params)
4242 gs.GameNotifier.postMinorChange()
4243
4244 ###*
4245 * @method commandEraseImageMap
4246 * @protected
4247 ###
4248 commandEraseImageMap: ->
4249 scene = SceneManager.scene
4250 scene.behavior.changePictureDomain(@params.numberDomain)
4251 number = @interpreter.numberValueOf(@params.number)
4252 imageMap = scene.pictures[number]
4253 if not imageMap? then return
4254
4255 imageMap.events.emit("finish", imageMap)
4256 imageMap.visual.active = no
4257 @interpreter.eraseObject(imageMap, @params, (sender) =>
4258 scene.behavior.changePictureDomain(sender.domain)
4259 scene.pictures[number] = null
4260 )
4261 gs.GameNotifier.postMinorChange()
4262
4263 ###*
4264 * @method commandAddHotspot
4265 * @protected
4266 ###
4267 commandAddHotspot: ->
4268 scene = SceneManager.scene
4269 scene.behavior.changeHotspotDomain(@params.numberDomain)
4270 number = @interpreter.numberValueOf(@params.number)
4271 hotspots = scene.hotspots
4272
4273 if not hotspots[number]?
4274 hotspots[number] = new gs.Object_Hotspot()
4275
4276 hotspot = hotspots[number]
4277 hotspot.domain = @params.numberDomain
4278 hotspot.data = { params: @params, bindValue: @interpreter.numberValueOf(@params.actions.onDrag.bindValue) }
4279
4280 switch @params.positionType
4281 when 0 # Direct
4282 hotspot.dstRect.x = @params.box.x
4283 hotspot.dstRect.y = @params.box.y
4284 hotspot.dstRect.width = @params.box.size.width
4285 hotspot.dstRect.height = @params.box.size.height
4286 when 1 # Calculated
4287 hotspot.dstRect.x = @interpreter.numberValueOf(@params.box.x)
4288 hotspot.dstRect.y = @interpreter.numberValueOf(@params.box.y)
4289 hotspot.dstRect.width = @interpreter.numberValueOf(@params.box.size.width)
4290 hotspot.dstRect.height = @interpreter.numberValueOf(@params.box.size.height)
4291 when 2 # Bind to Picture
4292 picture = scene.pictures[@interpreter.numberValueOf(@params.pictureNumber)]
4293 if picture?
4294 hotspot.target = picture
4295 when 3 # Bind to Text
4296 text = scene.texts[@interpreter.numberValueOf(@params.textNumber)]
4297 if text?
4298 hotspot.target = text
4299
4300 hotspot.behavior.shape = @params.shape ? gs.HotspotShape.RECTANGLE
4301
4302 if text?
4303 hotspot.images = null
4304 else
4305 hotspot.images = [
4306 @params.baseGraphic?.name || @interpreter.stringValueOf(@params.baseGraphic) || picture?.image,
4307 @params.hoverGraphic?.name || @interpreter.stringValueOf(@params.hoverGraphic),
4308 @params.selectedGraphic?.name || @interpreter.stringValueOf(@params.selectedGraphic),
4309 @params.selectedHoverGraphic?.name || @interpreter.stringValueOf(@params.selectedHoverGraphic),
4310 @params.unselectedGraphic?.name || @interpreter.stringValueOf(@params.unselectedGraphic)
4311 ]
4312
4313
4314 if @params.actions.onClick.type != 0 or @params.actions.onClick.label
4315 hotspot.events.on "click", gs.CallBack("onHotspotClick", @interpreter, { params: @params, bindValue: @interpreter.numberValueOf(@params.actions.onClick.bindValue) })
4316 if @params.actions.onEnter.type != 0 or @params.actions.onEnter.label
4317 hotspot.events.on "enter", gs.CallBack("onHotspotEnter", @interpreter, { params: @params, bindValue: @interpreter.numberValueOf(@params.actions.onEnter.bindValue) })
4318 if @params.actions.onLeave.type != 0 or @params.actions.onLeave.label
4319 hotspot.events.on "leave", gs.CallBack("onHotspotLeave", @interpreter, { params: @params, bindValue: @interpreter.numberValueOf(@params.actions.onLeave.bindValue) })
4320 if @params.actions.onDrag.type != 0 or @params.actions.onDrag.label
4321 hotspot.events.on "dragStart", gs.CallBack("onHotspotDragStart", @interpreter, { params: @params, bindValue: @interpreter.numberValueOf(@params.actions.onDrag.bindValue) })
4322 hotspot.events.on "drag", gs.CallBack("onHotspotDrag", @interpreter, { params: @params, bindValue: @interpreter.numberValueOf(@params.actions.onDrag.bindValue) })
4323 hotspot.events.on "dragEnd", gs.CallBack("onHotspotDragEnd", @interpreter, { params: @params, bindValue: @interpreter.numberValueOf(@params.actions.onDrag.bindValue) })
4324 if @params.actions.onSelect.type != 0 or @params.actions.onSelect.label or
4325 @params.actions.onDeselect.type != 0 or @params.actions.onDeselect.label
4326 hotspot.events.on "stateChanged", gs.CallBack("onHotspotStateChanged", @interpreter, @params)
4327 if @params.dragging.enabled
4328 hotspot.events.on "dragEnd", gs.CallBack("onHotspotDrop", @interpreter, { params: @params, bindValue: @interpreter.numberValueOf(@params.actions.onDrop.bindValue) })
4329 if @params.actions.onDropReceive.type != 0 or @params.actions.onDropReceive.label
4330 hotspot.events.on "dropReceived", gs.CallBack("onHotspotDropReceived", @interpreter, { params: @params, bindValue: @interpreter.numberValueOf(@params.actions.onDropReceive.bindValue) })
4331
4332 hotspot.selectable = yes
4333
4334
4335 if @params.dragging.enabled
4336 dragging = @params.dragging
4337 hotspot.draggable = {
4338 rect: new Rect(dragging.rect.x, dragging.rect.y, dragging.rect.size.width, dragging.rect.size.height),
4339 axisX: dragging.horizontal,
4340 axisY: dragging.vertical
4341 }
4342 hotspot.addComponent(new ui.Component_Draggable())
4343 hotspot.events.on "drag", (e) =>
4344 drag = e.sender.draggable
4345 GameManager.variableStore.setupTempVariables(@interpreter.context)
4346 if @params.dragging.horizontal
4347 @interpreter.setNumberValueTo(@params.dragging.variable, Math.round((e.sender.dstRect.x-drag.rect.x) / (drag.rect.width-e.sender.dstRect.width) * 100))
4348 else
4349 @interpreter.setNumberValueTo(@params.dragging.variable, Math.round((e.sender.dstRect.y-drag.rect.y) / (drag.rect.height-e.sender.dstRect.height) * 100))
4350
4351 hotspot.setup()
4352 ###*
4353 * @method commandChangeHotspotState
4354 * @protected
4355 ###
4356 commandChangeHotspotState: ->
4357 flags = @params.fieldFlags || {}
4358 isLocked = gs.CommandFieldFlags.isLocked
4359 scene = SceneManager.scene
4360 scene.behavior.changeHotspotDomain(@params.numberDomain)
4361 number = @interpreter.numberValueOf(@params.number)
4362 hotspot = scene.hotspots[number]
4363 return if !hotspot
4364
4365 if !isLocked(flags.selected) then hotspot.behavior.selected = @interpreter.booleanValueOf(@params.selected)
4366 if !isLocked(flags.enabled) then hotspot.behavior.enabled = @interpreter.booleanValueOf(@params.enabled)
4367
4368 hotspot.behavior.updateInput()
4369 hotspot.behavior.updateImage()
4370
4371 ###*
4372 * @method commandEraseHotspot
4373 * @protected
4374 ###
4375 commandEraseHotspot: ->
4376 scene = SceneManager.scene
4377 scene.behavior.changeHotspotDomain(@params.numberDomain)
4378 number = @interpreter.numberValueOf(@params.number)
4379
4380 if scene.hotspots[number]?
4381 scene.hotspots[number].dispose()
4382 scene.hotspotContainer.eraseObject(number)
4383
4384 ###*
4385 * @method commandChangeObjectDomain
4386 * @protected
4387 ###
4388 commandChangeObjectDomain: ->
4389 SceneManager.scene.behavior.changeObjectDomain(@interpreter.stringValueOf(@params.domain))
4390
4391 ###*
4392 * @method commandPictureDefaults
4393 * @protected
4394 ###
4395 commandPictureDefaults: ->
4396 defaults = GameManager.defaults.picture
4397 flags = @params.fieldFlags || {}
4398 isLocked = gs.CommandFieldFlags.isLocked
4399
4400 if !isLocked(flags.appearDuration) then defaults.appearDuration = @interpreter.durationValueOf(@params.appearDuration)
4401 if !isLocked(flags.disappearDuration) then defaults.disappearDuration = @interpreter.durationValueOf(@params.disappearDuration)
4402 if !isLocked(flags.zOrder) then defaults.zOrder = @interpreter.numberValueOf(@params.zOrder)
4403 if !isLocked(flags["appearEasing.type"]) then defaults.appearEasing = @params.appearEasing
4404 if !isLocked(flags["appearAnimation.type"]) then defaults.appearAnimation = @params.appearAnimation
4405 if !isLocked(flags["disappearEasing.type"]) then defaults.disappearEasing = @params.disappearEasing
4406 if !isLocked(flags["disappearAnimation.type"]) then defaults.disappearAnimation = @params.disappearAnimation
4407 if !isLocked(flags["motionBlur.enabled"]) then defaults.motionBlur = @params.motionBlur
4408 if !isLocked(flags.origin) then defaults.origin = @params.origin
4409
4410
4411 createPicture: (graphic, params) ->
4412 graphic = @stringValueOf(graphic)
4413 graphic = if typeof graphic == "string" then { name: gs.Path.basename(graphic), folderPath: gs.Path.dirname(graphic) } else graphic
4414 graphicName = if graphic?.name? then graphic.name else graphic
4415 bitmap = ResourceManager.getBitmap(ResourceManager.getPath(graphic))
4416 return null if bitmap && !bitmap.loaded
4417
4418 defaults = GameManager.defaults.picture
4419 flags = params.fieldFlags || {}
4420 isLocked = gs.CommandFieldFlags.isLocked
4421 scene = SceneManager.scene
4422 number = @numberValueOf(params.number)
4423 pictures = scene.pictures
4424 picture = pictures[number]
4425
4426 if not picture?
4427 picture = new gs.Object_Picture(null, null, params.visual?.type)
4428 picture.domain = params.numberDomain
4429 pictures[number] = picture
4430 switch params.visual?.type
4431 when 1
4432 picture.visual.looping.vertical = yes
4433 picture.visual.looping.horizontal = yes
4434 when 2
4435 picture.frameThickness = params.visual.frame.thickness
4436 picture.frameCornerSize = params.visual.frame.cornerSize
4437 when 3
4438 picture.visual.orientation = params.visual.threePartImage.orientation
4439 when 4
4440 picture.color = gs.Color.fromObject(params.visual.quad.color)
4441 when 5
4442 snapshot = Graphics.snapshot()
4443 #ResourceManager.addCustomBitmap(snapshot)
4444 picture.bitmap = snapshot
4445 picture.dstRect.width = snapshot.width
4446 picture.dstRect.height = snapshot.height
4447 picture.srcRect.set(0, 0, snapshot.width, snapshot.height)
4448 else
4449 picture.bitmap = null
4450
4451
4452 x = @numberValueOf(params.position.x)
4453 y = @numberValueOf(params.position.y)
4454 picture = pictures[number]
4455
4456 if !picture.bitmap
4457 picture.image = graphicName
4458 picture.imageFolder = graphic?.folderPath || "Graphics/Pictures"
4459 else
4460 picture.image = null
4461
4462 bitmap = picture.bitmap ? ResourceManager.getBitmap(ResourceManager.getPath(graphic))
4463 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@numberValueOf(params.easing.type), params.easing.inOut) else gs.Easings.fromObject(defaults.appearEasing)
4464 duration = if !isLocked(flags.duration) then @durationValueOf(params.duration) else defaults.appearDuration
4465 origin = if !isLocked(flags.origin) then params.origin else defaults.origin
4466 zIndex = if !isLocked(flags.zOrder) then @numberValueOf(params.zOrder) else defaults.zOrder
4467 animation = if !isLocked(flags["animation.type"]) then params.animation else defaults.appearAnimation
4468
4469 picture.mirror = params.position.horizontalFlip
4470 picture.angle = params.position.angle || 0
4471 picture.zoom.x = (params.position.data?.zoom||1)
4472 picture.zoom.y = (params.position.data?.zoom||1)
4473 picture.blendMode = @numberValueOf(params.blendMode)
4474
4475 if params.origin == 1 and bitmap?
4476 x += (bitmap.width*picture.zoom.x-bitmap.width)/2
4477 y += (bitmap.height*picture.zoom.y-bitmap.height)/2
4478
4479 picture.dstRect.x = x
4480 picture.dstRect.y = y
4481 picture.anchor.x = if origin == 1 then 0.5 else 0
4482 picture.anchor.y = if origin == 1 then 0.5 else 0
4483 picture.zIndex = zIndex || (700 + number)
4484
4485 if params.viewport?.type == "scene"
4486 picture.viewport = SceneManager.scene.behavior.viewport
4487
4488 if params.size?.type == 1
4489 picture.dstRect.width = @numberValueOf(params.size.width)
4490 picture.dstRect.height = @numberValueOf(params.size.height)
4491
4492 picture.update()
4493
4494 return picture
4495 ###*
4496 * @method commandShowPicture
4497 * @protected
4498 ###
4499 commandShowPicture: ->
4500 SceneManager.scene.behavior.changePictureDomain(@params.numberDomain || "")
4501 defaults = GameManager.defaults.picture
4502 flags = @params.fieldFlags || {}
4503 isLocked = gs.CommandFieldFlags.isLocked
4504 picture = @interpreter.createPicture(@params.graphic, @params)
4505 if !picture
4506 @interpreter.pointer--
4507 @interpreter.isWaiting = yes
4508 @interpreter.waitCounter = 1
4509 return
4510
4511 if @params.positionType == 0
4512 p = @interpreter.predefinedObjectPosition(@params.predefinedPositionId, picture, @params)
4513 picture.dstRect.x = p.x
4514 picture.dstRect.y = p.y
4515
4516 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut) else gs.Easings.fromObject(defaults.appearEasing)
4517 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.appearDuration
4518 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.appearAnimation
4519
4520 picture.animator.appear(picture.dstRect.x, picture.dstRect.y, animation, easing, duration)
4521
4522 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
4523 @interpreter.isWaiting = yes
4524 @interpreter.waitCounter = duration
4525
4526 gs.GameNotifier.postMinorChange()
4527
4528 ###*
4529 * @method commandPlayPictureAnimation
4530 * @protected
4531 ###
4532 commandPlayPictureAnimation: ->
4533 SceneManager.scene.behavior.changePictureDomain(@params.numberDomain || "")
4534
4535 defaults = GameManager.defaults.picture
4536 flags = @params.fieldFlags || {}
4537 isLocked = gs.CommandFieldFlags.isLocked
4538 picture = null
4539
4540 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut) else gs.Easings.fromObject(defaults.appearEasing)
4541 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.appearDuration
4542 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.appearAnimation
4543
4544 if @params.animationId?
4545 record = RecordManager.animations[@params.animationId]
4546 if record?
4547 picture = @interpreter.createPicture(record.graphic, @params)
4548
4549 component = picture.findComponent("Component_FrameAnimation")
4550 if component?
4551 component.refresh(record)
4552 component.start()
4553 else
4554 component = new gs.Component_FrameAnimation(record)
4555 picture.addComponent(component)
4556
4557 component.update()
4558
4559 if @params.positionType == 0
4560 p = @interpreter.predefinedObjectPosition(@params.predefinedPositionId, picture, @params)
4561 picture.dstRect.x = p.x
4562 picture.dstRect.y = p.y
4563
4564 picture.animator.appear(picture.dstRect.x, picture.dstRect.y, animation, easing, duration)
4565
4566 else
4567 picture = SceneManager.scene.pictures[@interpreter.numberValueOf(@params.number)]
4568 animation = picture?.findComponent("Component_FrameAnimation")
4569
4570 if animation?
4571 picture.removeComponent(animation)
4572 bitmap = ResourceManager.getBitmap("Graphics/Animations/#{picture.image}")
4573 if bitmap?
4574 picture.srcRect.set(0, 0, bitmap.width, bitmap.height)
4575 picture.dstRect.width = picture.srcRect.width
4576 picture.dstRect.height = picture.srcRect.height
4577
4578 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
4579 @interpreter.isWaiting = yes
4580 @interpreter.waitCounter = duration
4581
4582 gs.GameNotifier.postMinorChange()
4583
4584 ###*
4585 * @method commandMovePicturePath
4586 * @protected
4587 ###
4588 commandMovePicturePath: ->
4589 scene = SceneManager.scene
4590 scene.behavior.changePictureDomain(@params.numberDomain)
4591 number = @interpreter.numberValueOf(@params.number)
4592 picture = scene.pictures[number]
4593 if not picture? then return
4594
4595 @interpreter.moveObjectPath(picture, @params.path, @params)
4596
4597 gs.GameNotifier.postMinorChange()
4598
4599 ###*
4600 * @method commandMovePicture
4601 * @protected
4602 ###
4603 commandMovePicture: ->
4604 scene = SceneManager.scene
4605 scene.behavior.changePictureDomain(@params.numberDomain)
4606 number = @interpreter.numberValueOf(@params.number)
4607 picture = scene.pictures[number]
4608 if not picture? then return
4609
4610 @interpreter.moveObject(picture, @params.picture.position, @params)
4611
4612 gs.GameNotifier.postMinorChange()
4613
4614
4615 ###*
4616 * @method commandTintPicture
4617 * @protected
4618 ###
4619 commandTintPicture: ->
4620 scene = SceneManager.scene
4621 scene.behavior.changePictureDomain(@params.numberDomain || "")
4622 number = @interpreter.numberValueOf(@params.number)
4623 picture = scene.pictures[number]
4624 if not picture? then return
4625
4626 @interpreter.tintObject(picture, @params)
4627
4628 gs.GameNotifier.postMinorChange()
4629
4630 ###*
4631 * @method commandFlashPicture
4632 * @protected
4633 ###
4634 commandFlashPicture: ->
4635 scene = SceneManager.scene
4636 scene.behavior.changePictureDomain(@params.numberDomain || "")
4637 number = @interpreter.numberValueOf(@params.number)
4638 picture = scene.pictures[number]
4639 if not picture? then return
4640
4641 @interpreter.flashObject(picture, @params)
4642
4643 gs.GameNotifier.postMinorChange()
4644
4645 ###*
4646 * @method commandCropPicture
4647 * @protected
4648 ###
4649 commandCropPicture: ->
4650 scene = SceneManager.scene
4651 scene.behavior.changePictureDomain(@params.numberDomain || "")
4652 number = @interpreter.numberValueOf(@params.number)
4653 picture = scene.pictures[number]
4654 if not picture? then return
4655
4656 @interpreter.cropObject(picture, @params)
4657
4658 ###*
4659 * @method commandRotatePicture
4660 * @protected
4661 ###
4662 commandRotatePicture: ->
4663 scene = SceneManager.scene
4664 scene.behavior.changePictureDomain(@params.numberDomain || "")
4665 number = @interpreter.numberValueOf(@params.number)
4666 picture = scene.pictures[number]
4667 if not picture? then return
4668
4669 @interpreter.rotateObject(picture, @params)
4670
4671 gs.GameNotifier.postMinorChange()
4672
4673 ###*
4674 * @method commandZoomPicture
4675 * @protected
4676 ###
4677 commandZoomPicture: ->
4678 scene = SceneManager.scene
4679 scene.behavior.changePictureDomain(@params.numberDomain || "")
4680 number = @interpreter.numberValueOf(@params.number)
4681 picture = scene.pictures[number]
4682 if not picture? then return
4683
4684 @interpreter.zoomObject(picture, @params)
4685
4686 gs.GameNotifier.postMinorChange()
4687
4688 ###*
4689 * @method commandBlendPicture
4690 * @protected
4691 ###
4692 commandBlendPicture: ->
4693 SceneManager.scene.behavior.changePictureDomain(@params.numberDomain || "")
4694 picture = SceneManager.scene.pictures[@interpreter.numberValueOf(@params.number)]
4695 if not picture? then return
4696
4697 @interpreter.blendObject(picture, @params)
4698 gs.GameNotifier.postMinorChange()
4699
4700 ###*
4701 * @method commandShakePicture
4702 * @protected
4703 ###
4704 commandShakePicture: ->
4705 picture = SceneManager.scene.pictures[@interpreter.numberValueOf(@params.number)]
4706 if not picture? then return
4707
4708 @interpreter.shakeObject(picture, @params)
4709 gs.GameNotifier.postMinorChange()
4710
4711 ###*
4712 * @method commandMaskPicture
4713 * @protected
4714 ###
4715 commandMaskPicture: ->
4716 scene = SceneManager.scene
4717 scene.behavior.changePictureDomain(@params.numberDomain || "")
4718 number = @interpreter.numberValueOf(@params.number)
4719 picture = scene.pictures[number]
4720 if not picture? then return
4721
4722 @interpreter.maskObject(picture, @params)
4723 gs.GameNotifier.postMinorChange()
4724
4725
4726 ###*
4727 * @method commandPictureMotionBlur
4728 * @protected
4729 ###
4730 commandPictureMotionBlur: ->
4731 scene = SceneManager.scene
4732 scene.behavior.changePictureDomain(@params.numberDomain || "")
4733 number = @interpreter.numberValueOf(@params.number)
4734 picture = scene.pictures[number]
4735 if not picture? then return
4736
4737 @interpreter.objectMotionBlur(picture, @params)
4738
4739 gs.GameNotifier.postMinorChange()
4740
4741 ###*
4742 * @method commandPictureEffect
4743 * @protected
4744 ###
4745 commandPictureEffect: ->
4746 scene = SceneManager.scene
4747 scene.behavior.changePictureDomain(@params.numberDomain || "")
4748 number = @interpreter.numberValueOf(@params.number)
4749 picture = scene.pictures[number]
4750 if not picture? then return
4751
4752 @interpreter.objectEffect(picture, @params)
4753 gs.GameNotifier.postMinorChange()
4754
4755 ###*
4756 * @method commandErasePicture
4757 * @protected
4758 ###
4759 commandErasePicture: ->
4760 defaults = GameManager.defaults.picture
4761 flags = @params.fieldFlags || {}
4762 isLocked = gs.CommandFieldFlags.isLocked
4763
4764 scene = SceneManager.scene
4765 scene.behavior.changePictureDomain(@params.numberDomain || "")
4766 number = @interpreter.numberValueOf(@params.number)
4767 picture = scene.pictures[number]
4768 if not picture? then return
4769
4770 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut) else gs.Easings.fromObject(defaults.disappearEasing)
4771 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.disappearDuration
4772 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.disappearAnimation
4773
4774 picture.animator.disappear(animation, easing, duration,
4775 (sender) =>
4776 sender.dispose()
4777 scene.behavior.changePictureDomain(sender.domain)
4778 scene.pictures[number] = null
4779 )
4780
4781 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
4782 @interpreter.isWaiting = yes
4783 @interpreter.waitCounter = duration
4784
4785 gs.GameNotifier.postMinorChange()
4786
4787
4788 ###*
4789 * @method commandInputNumber
4790 * @protected
4791 ###
4792 commandInputNumber: ->
4793 scene = SceneManager.scene
4794 @interpreter.isWaiting = yes
4795 if @interpreter.isProcessingMessageInOtherContext()
4796 @interpreter.waitForMessage()
4797 return
4798
4799 if (GameManager.settings.allowChoiceSkip||@interpreter.preview) and GameManager.tempSettings.skip
4800 @interpreter.isWaiting = no
4801 @interpreter.messageObject().behavior.clear()
4802 @interpreter.setNumberValueTo(@params.variable, 0)
4803 return
4804
4805 $tempFields.digits = @params.digits
4806 scene.behavior.showInputNumber(@params.digits, gs.CallBack("onInputNumberFinish", @interpreter, @params))
4807
4808 @interpreter.waitingFor.inputNumber = @params
4809 gs.GameNotifier.postMinorChange()
4810
4811 ###*
4812 * @method commandChoiceTimer
4813 * @protected
4814 ###
4815 commandChoiceTimer: ->
4816 scene = SceneManager.scene
4817
4818 GameManager.tempFields.choiceTimer = scene.choiceTimer
4819 GameManager.tempFields.choiceTimerVisible = @params.visible
4820
4821 if @params.enabled
4822 scene.choiceTimer.behavior.seconds = @interpreter.numberValueOf(@params.seconds)
4823 scene.choiceTimer.behavior.minutes = @interpreter.numberValueOf(@params.minutes)
4824 scene.choiceTimer.behavior.start()
4825 scene.choiceTimer.events.on "finish", (sender) =>
4826 if scene.choiceWindow and scene.choices?.length > 0
4827 defaultChoice = (scene.choices.first (c) -> c.isDefault) || scene.choices[0]
4828 #scene.choiceWindow.events.emit("selectionAccept", scene.choiceWindow, { labelIndex: defaultChoice.action.labelIndex })
4829 scene.choiceWindow.events.emit("selectionAccept", scene.choiceWindow, defaultChoice)
4830 else
4831 scene.choiceTimer.stop()
4832
4833 ###*
4834 * @method commandShowChoices
4835 * @protected
4836 ###
4837 commandShowChoices: ->
4838 scene = SceneManager.scene
4839 pointer = @interpreter.pointer
4840 choices = scene.choices || []
4841
4842 if (GameManager.settings.allowChoiceSkip||@interpreter.previewData) and GameManager.tempSettings.skip
4843 messageObject = @interpreter.messageObject()
4844 if messageObject?.visible
4845 messageObject.behavior.clear()
4846 defaultChoice = (choices.first((c) -> c.isDefault)) || choices[0]
4847 if defaultChoice.action.labelIndex?
4848 @interpreter.pointer = defaultChoice.action.labelIndex
4849 else
4850 @interpreter.jumpToLabel(defaultChoice.action.label)
4851 scene.choices = []
4852 else
4853 if choices.length > 0
4854 @interpreter.isWaiting = yes
4855 scene.behavior.showChoices(gs.CallBack("onChoiceAccept", @interpreter, { pointer: pointer, params: @params }))
4856
4857 gs.GameNotifier.postMinorChange()
4858
4859 ###*
4860 * @method commandShowChoice
4861 * @protected
4862 ###
4863 commandShowChoice: ->
4864 scene = SceneManager.scene
4865 commands = @interpreter.object.commands
4866 command = null
4867 index = 0
4868 pointer = @interpreter.pointer
4869 choices = null
4870 dstRect = null
4871
4872 switch @params.positionType
4873 when 0 # Auto
4874 dstRect = null
4875 when 1 # Direct
4876 dstRect = new Rect(@params.box.x, @params.box.y, @params.box.size.width, @params.box.size.height)
4877
4878 if !scene.choices
4879 scene.choices = []
4880 choices = scene.choices
4881 choices.push({
4882 dstRect: dstRect,
4883 #text: lcs(@params.text),
4884 text: @params.text,
4885 index: index,
4886 action: @params.action,
4887 isSelected: no,
4888 isDefault: @params.defaultChoice,
4889 isEnabled: @interpreter.booleanValueOf(@params.enabled) })
4890
4891 ###*
4892 * @method commandOpenMenu
4893 * @protected
4894 ###
4895 commandOpenMenu: ->
4896 SceneManager.switchTo(new gs.Object_Layout("menuLayout"), true)
4897 @interpreter.waitCounter = 1
4898 @interpreter.isWaiting = yes
4899
4900 ###*
4901 * @method commandOpenLoadMenu
4902 * @protected
4903 ###
4904 commandOpenLoadMenu: ->
4905 SceneManager.switchTo(new gs.Object_Layout("loadMenuLayout"), true)
4906 @interpreter.waitCounter = 1
4907 @interpreter.isWaiting = yes
4908
4909 ###*
4910 * @method commandOpenSaveMenu
4911 * @protected
4912 ###
4913 commandOpenSaveMenu: ->
4914 SceneManager.switchTo(new gs.Object_Layout("saveMenuLayout"), true)
4915 @interpreter.waitCounter = 1
4916 @interpreter.isWaiting = yes
4917
4918 ###*
4919 * @method commandReturnToTitle
4920 * @protected
4921 ###
4922 commandReturnToTitle: ->
4923 SceneManager.clear()
4924 SceneManager.switchTo(new gs.Object_Layout("titleLayout"))
4925 @interpreter.waitCounter = 1
4926 @interpreter.isWaiting = yes
4927
4928
4929 ###*
4930 * @method commandPlayVideo
4931 * @protected
4932 ###
4933 commandPlayVideo: ->
4934 if (GameManager.inLivePreview or GameManager.settings.allowVideoSkip) and GameManager.tempSettings.skip then return
4935
4936 GameManager.tempSettings.skip = no
4937 scene = SceneManager.scene
4938
4939 if @params.video?.name?
4940 scene.video = ResourceManager.getVideo(ResourceManager.getPath(@params.video))
4941
4942 @videoSprite = new Sprite(Graphics.viewport)
4943 @videoSprite.srcRect = new Rect(0, 0, scene.video.width, scene.video.height)
4944 @videoSprite.video = scene.video
4945 @videoSprite.zoomX = Graphics.width / scene.video.width
4946 @videoSprite.zoomY = Graphics.height / scene.video.height
4947 @videoSprite.z = 99999999
4948 scene.video.onEnded = =>
4949 @interpreter.isWaiting = no
4950 @videoSprite.dispose()
4951 scene.video = null
4952 scene.video.volume = @params.volume / 100
4953 scene.video.playbackRate = @params.playbackRate / 100
4954 @interpreter.isWaiting = yes
4955 scene.video.play()
4956 gs.GameNotifier.postMinorChange()
4957 ###*
4958 * @method commandAudioDefaults
4959 * @protected
4960 ###
4961 commandAudioDefaults: ->
4962 defaults = GameManager.defaults.audio
4963 flags = @params.fieldFlags || {}
4964 isLocked = gs.CommandFieldFlags.isLocked
4965
4966 if !isLocked(flags.musicFadeInDuration) then defaults.musicFadeInDuration = @params.musicFadeInDuration
4967 if !isLocked(flags.musicFadeOutDuration) then defaults.musicFadeOutDuration = @params.musicFadeOutDuration
4968 if !isLocked(flags.musicVolume) then defaults.musicVolume = @params.musicVolume
4969 if !isLocked(flags.musicPlaybackRate) then defaults.musicPlaybackRate = @params.musicPlaybackRate
4970 if !isLocked(flags.soundVolume) then defaults.soundVolume = @params.soundVolume
4971 if !isLocked(flags.soundPlaybackRate) then defaults.soundPlaybackRate = @params.soundPlaybackRate
4972 if !isLocked(flags.voiceVolume) then defaults.voiceVolume = @params.voiceVolume
4973 if !isLocked(flags.voicePlaybackRate) then defaults.voicePlaybackRate = @params.voicePlaybackRate
4974
4975 ###*
4976 * @method commandPlayMusic
4977 * @protected
4978 ###
4979 commandPlayMusic: ->
4980 if not @params.music? then return
4981 defaults = GameManager.defaults.audio
4982 flags = @params.fieldFlags || {}
4983 isLocked = gs.CommandFieldFlags.isLocked
4984 music = null
4985
4986 if GameManager.settings.bgmEnabled
4987 fadeDuration = if !isLocked(flags.fadeInDuration) then @params.fadeInDuration else defaults.musicFadeInDuration
4988 volume = if !isLocked(flags["music.volume"]) then @params.music.volume else defaults.musicVolume
4989 playbackRate = if !isLocked(flags["music.playbackRate"]) then @params.music.playbackRate else defaults.musicPlaybackRate
4990 music = { name: @params.music.name, folderPath: @params.music.folderPath, volume: volume, playbackRate: playbackRate }
4991 if @params.playType == 1
4992 playTime = min: @params.playTime.min * 60, max: @params.playTime.max * 60
4993 playRange = start: @params.playRange.start * 60, end: @params.playRange.end * 60
4994 AudioManager.playMusicRandom(music, fadeDuration, @params.layer || 0, playTime, playRange)
4995 else
4996 music = AudioManager.playMusic(@params.music, volume, playbackRate, fadeDuration, @params.layer || 0, @params.loop)
4997
4998 if music and @params.waitForCompletion and !@params.loop
4999 @interpreter.isWaiting = yes
5000 @interpreter.waitCounter = Math.round(music.duration * Graphics.frameRate)
5001
5002 gs.GameNotifier.postMinorChange()
5003 ###*
5004 * @method commandStopMusic
5005 * @protected
5006 ###
5007 commandStopMusic: ->
5008 defaults = GameManager.defaults.audio
5009 flags = @params.fieldFlags || {}
5010 isLocked = gs.CommandFieldFlags.isLocked
5011 fadeDuration = if !isLocked(flags.fadeOutDuration) then @params.fadeOutDuration else defaults.musicFadeOutDuration
5012
5013 AudioManager.stopMusic(fadeDuration, @interpreter.numberValueOf(@params.layer))
5014
5015 gs.GameNotifier.postMinorChange()
5016 ###*
5017 * @method commandPauseMusic
5018 * @protected
5019 ###
5020 commandPauseMusic: ->
5021 defaults = GameManager.defaults.audio
5022 flags = @params.fieldFlags || {}
5023 isLocked = gs.CommandFieldFlags.isLocked
5024 fadeDuration = if !isLocked(flags.fadeOutDuration) then @params.fadeOutDuration else defaults.musicFadeOutDuration
5025
5026 AudioManager.stopMusic(fadeDuration, @interpreter.numberValueOf(@params.layer))
5027
5028 ###*
5029 * @method commandResumeMusic
5030 * @protected
5031 ###
5032 commandResumeMusic: ->
5033 defaults = GameManager.defaults.audio
5034 flags = @params.fieldFlags || {}
5035 isLocked = gs.CommandFieldFlags.isLocked
5036 fadeDuration = if !isLocked(flags.fadeInDuration) then @params.fadeInDuration else defaults.musicFadeInDuration
5037
5038 AudioManager.resumeMusic(fadeDuration, @interpreter.numberValueOf(@params.layer))
5039 gs.GameNotifier.postMinorChange()
5040 ###*
5041 * @method commandPlaySound
5042 * @protected
5043 ###
5044 commandPlaySound: ->
5045 defaults = GameManager.defaults.audio
5046 flags = @params.fieldFlags || {}
5047 isLocked = gs.CommandFieldFlags.isLocked
5048 sound = null
5049 if GameManager.settings.soundEnabled and !GameManager.tempSettings.skip
5050 volume = if !isLocked(flags["sound.volume"]) then @params.sound.volume else defaults.soundVolume
5051 playbackRate = if !isLocked(flags["sound.playbackRate"]) then @params.sound.playbackRate else defaults.soundPlaybackRate
5052
5053 sound = AudioManager.playSound(@params.sound, volume, playbackRate, @params.musicEffect, null, @params.loop)
5054 gs.GameNotifier.postMinorChange()
5055 if sound and @params.waitForCompletion and !@params.loop
5056 @interpreter.isWaiting = yes
5057 @interpreter.waitCounter = Math.round(sound.duration * Graphics.frameRate)
5058 ###*
5059 * @method commandStopSound
5060 * @protected
5061 ###
5062 commandStopSound: ->
5063 AudioManager.stopSound(@params.sound.name)
5064 gs.GameNotifier.postMinorChange()
5065 ###*
5066 * @method commandEndCommonEvent
5067 * @protected
5068 ###
5069 commandEndCommonEvent: ->
5070 eventId = @interpreter.stringValueOf(@params.commonEventId)
5071 event = GameManager.commonEvents[eventId]
5072 event?.behavior.stop()
5073
5074 ###*
5075 * @method commandResumeCommonEvent
5076 * @protected
5077 ###
5078 commandResumeCommonEvent: ->
5079 eventId = @interpreter.stringValueOf(@params.commonEventId)
5080 event = GameManager.commonEvents[eventId]
5081 event?.behavior.resume()
5082
5083 ###*
5084 * @method commandCallCommonEvent
5085 * @protected
5086 ###
5087 commandCallCommonEvent: ->
5088 scene = SceneManager.scene
5089 eventId = null
5090
5091 if @params.commonEventId.index?
5092 eventId = @interpreter.stringValueOf(@params.commonEventId)
5093 list = @interpreter.listObjectOf(@params.parameters.values[0])
5094 params = { values: list }
5095 else
5096 params = @params.parameters
5097 eventId = @params.commonEventId
5098
5099 @interpreter.callCommonEvent(eventId, params)
5100
5101
5102 ###*
5103 * @method commandChangeTextSettings
5104 * @protected
5105 ###
5106 commandChangeTextSettings: ->
5107 scene = SceneManager.scene
5108 scene.behavior.changeTextDomain(@params.numberDomain)
5109 number = @interpreter.numberValueOf(@params.number)
5110 texts = scene.texts
5111 if not texts[number]?
5112 texts[number] = new gs.Object_Text()
5113 texts[number].visible = no
5114
5115
5116 textSprite = texts[number]
5117 padding = textSprite.behavior.padding
5118 font = textSprite.font
5119 fontName = @interpreter.stringValueOf(textSprite.font.name)
5120 fontSize = @interpreter.numberValueOf(textSprite.font.size)
5121 flags = @params.fieldFlags || {}
5122 isLocked = gs.CommandFieldFlags.isLocked
5123 if !isLocked(flags.lineSpacing) then textSprite.textRenderer.lineSpacing = @params.lineSpacing ? textSprite.textRenderer.lineSpacing
5124 if !isLocked(flags.font) then fontName = @interpreter.stringValueOf(@params.font)
5125 if !isLocked(flags.size) then fontSize = @interpreter.numberValueOf(@params.size)
5126
5127 if !isLocked(flags.font) or !isLocked(flags.size)
5128 textSprite.font = new Font(fontName, fontSize)
5129
5130 padding.left = if !isLocked(flags["padding.0"]) then @params.padding?[0] else padding.left
5131 padding.top = if !isLocked(flags["padding.1"]) then @params.padding?[1] else padding.top
5132 padding.right = if !isLocked(flags["padding.2"]) then @params.padding?[2] else padding.right
5133 padding.bottom = if !isLocked(flags["padding.3"]) then @params.padding?[3] else padding.bottom
5134
5135 if !isLocked(flags.bold)
5136 textSprite.font.bold = @params.bold
5137 if !isLocked(flags.italic)
5138 textSprite.font.italic = @params.italic
5139 if !isLocked(flags.smallCaps)
5140 textSprite.font.smallCaps = @params.smallCaps
5141 if !isLocked(flags.underline)
5142 textSprite.font.underline = @params.underline
5143 if !isLocked(flags.strikeThrough)
5144 textSprite.font.strikeThrough = @params.strikeThrough
5145
5146 textSprite.font.color = if !isLocked(flags.color) then new Color(@params.color) else font.color
5147 textSprite.font.border = if !isLocked(flags.outline)then @params.outline else font.border
5148 textSprite.font.borderColor = if !isLocked(flags.outlineColor) then new Color(@params.outlineColor) else new Color(font.borderColor)
5149 textSprite.font.borderSize = if !isLocked(flags.outlineSize) then @params.outlineSize else font.borderSize
5150 textSprite.font.shadow = if !isLocked(flags.shadow)then @params.shadow else font.shadow
5151 textSprite.font.shadowColor = if !isLocked(flags.shadowColor) then new Color(@params.shadowColor) else new Color(font.shadowColor)
5152 textSprite.font.shadowOffsetX = if !isLocked(flags.shadowOffsetX) then @params.shadowOffsetX else font.shadowOffsetX
5153 textSprite.font.shadowOffsetY = if !isLocked(flags.shadowOffsetY) then @params.shadowOffsetY else font.shadowOffsetY
5154 textSprite.behavior.refresh()
5155 textSprite.update()
5156
5157 ###*
5158 * @method commandChangeTextSettings
5159 * @protected
5160 ###
5161 commandTextDefaults: ->
5162 defaults = GameManager.defaults.text
5163 flags = @params.fieldFlags || {}
5164 isLocked = gs.CommandFieldFlags.isLocked
5165
5166 if !isLocked(flags.appearDuration) then defaults.appearDuration = @interpreter.durationValueOf(@params.appearDuration)
5167 if !isLocked(flags.disappearDuration) then defaults.disappearDuration = @interpreter.durationValueOf(@params.disappearDuration)
5168 if !isLocked(flags.zOrder) then defaults.zOrder = @interpreter.numberValueOf(@params.zOrder)
5169 if !isLocked(flags["appearEasing.type"]) then defaults.appearEasing = @params.appearEasing
5170 if !isLocked(flags["appearAnimation.type"]) then defaults.appearAnimation = @params.appearAnimation
5171 if !isLocked(flags["disappearEasing.type"]) then defaults.disappearEasing = @params.disappearEasing
5172 if !isLocked(flags["disappearAnimation.type"]) then defaults.disappearAnimation = @params.disappearAnimation
5173 if !isLocked(flags["motionBlur.enabled"]) then defaults.motionBlur = @params.motionBlur
5174 if !isLocked(flags.origin) then defaults.origin = @params.origin
5175
5176 ###*
5177 * @method commandShowText
5178 * @protected
5179 ###
5180 commandShowText: ->
5181 defaults = GameManager.defaults.text
5182 flags = @params.fieldFlags || {}
5183 isLocked = gs.CommandFieldFlags.isLocked
5184 scene = SceneManager.scene
5185 scene.behavior.changeTextDomain(@params.numberDomain)
5186 number = @interpreter.numberValueOf(@params.number)
5187 text = @params.text
5188 texts = scene.texts
5189 if not texts[number]? then texts[number] = new gs.Object_Text()
5190
5191 x = @interpreter.numberValueOf(@params.position.x)
5192 y = @interpreter.numberValueOf(@params.position.y)
5193 textObject = texts[number]
5194 textObject.domain = @params.numberDomain
5195
5196 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut) else gs.Easings.fromObject(defaults.appearEasing)
5197 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.appearDuration
5198 origin = if !isLocked(flags.origin) then @params.origin else defaults.origin
5199 zIndex = if !isLocked(flags.zOrder) then @interpreter.numberValueOf(@params.zOrder) else defaults.zOrder
5200 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.appearAnimation
5201 positionAnchor = if !isLocked(flags.positionOrigin) then @interpreter.graphicAnchorPointsByConstant[@params.positionOrigin] || new gs.Point(0, 0) else @interpreter.graphicAnchorPointsByConstant[defaults.positionOrigin]
5202
5203 textObject.text = text
5204 textObject.dstRect.x = x
5205 textObject.dstRect.y = y
5206 textObject.blendMode = @interpreter.numberValueOf(@params.blendMode)
5207 textObject.anchor.x = if origin == 0 then 0 else 0.5
5208 textObject.anchor.y = if origin == 0 then 0 else 0.5
5209 textObject.positionAnchor.x = positionAnchor.x
5210 textObject.positionAnchor.y = positionAnchor.y
5211 textObject.zIndex = zIndex || (700 + number)
5212 textObject.sizeToFit = yes
5213 textObject.formatting = yes
5214 if @params.viewport?.type == "scene"
5215 textObject.viewport = SceneManager.scene.behavior.viewport
5216 textObject.update()
5217
5218 if @params.positionType == 0
5219 p = @interpreter.predefinedObjectPosition(@params.predefinedPositionId, textObject, @params)
5220 textObject.dstRect.x = p.x
5221 textObject.dstRect.y = p.y
5222
5223 textObject.animator.appear(x, y, animation, easing, duration)
5224
5225 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
5226 @interpreter.isWaiting = yes
5227 @interpreter.waitCounter = duration
5228
5229 gs.GameNotifier.postMinorChange()
5230 ###*
5231 * @method commandTextMotionBlur
5232 * @protected
5233 ###
5234 commandTextMotionBlur: ->
5235 scene = SceneManager.scene
5236 scene.behavior.changeTextDomain(@params.numberDomain)
5237 number = @interpreter.numberValueOf(@params.number)
5238 text = scene.texts[number]
5239 if not text? then return
5240
5241 text.motionBlur.set(@params.motionBlur)
5242
5243 ###*
5244 * @method commandRefreshText
5245 * @protected
5246 ###
5247 commandRefreshText: ->
5248 scene = SceneManager.scene
5249 scene.behavior.changeTextDomain(@params.numberDomain)
5250 number = @interpreter.numberValueOf(@params.number)
5251 texts = scene.texts
5252 if not texts[number]? then return
5253
5254 texts[number].behavior.refresh(yes)
5255
5256 ###*
5257 * @method commandMoveText
5258 * @protected
5259 ###
5260 commandMoveText: ->
5261 scene = SceneManager.scene
5262 scene.behavior.changeTextDomain(@params.numberDomain)
5263 number = @interpreter.numberValueOf(@params.number)
5264 text = scene.texts[number]
5265 if not text? then return
5266
5267 @interpreter.moveObject(text, @params.picture.position, @params)
5268
5269 gs.GameNotifier.postMinorChange()
5270 ###*
5271 * @method commandMoveTextPath
5272 * @protected
5273 ###
5274 commandMoveTextPath: ->
5275 scene = SceneManager.scene
5276 scene.behavior.changeTextDomain(@params.numberDomain)
5277 number = @interpreter.numberValueOf(@params.number)
5278 text = scene.texts[number]
5279 if not text? then return
5280
5281 @interpreter.moveObjectPath(text, @params.path, @params)
5282
5283 gs.GameNotifier.postMinorChange()
5284 ###*
5285 * @method commandRotateText
5286 * @protected
5287 ###
5288 commandRotateText: ->
5289 scene = SceneManager.scene
5290 scene.behavior.changeTextDomain(@params.numberDomain)
5291 number = @interpreter.numberValueOf(@params.number)
5292 text = scene.texts[number]
5293 if not text? then return
5294
5295 @interpreter.rotateObject(text, @params)
5296
5297 gs.GameNotifier.postMinorChange()
5298 ###*
5299 * @method commandZoomText
5300 * @protected
5301 ###
5302 commandZoomText: ->
5303 scene = SceneManager.scene
5304 scene.behavior.changeTextDomain(@params.numberDomain)
5305 number = @interpreter.numberValueOf(@params.number)
5306 text = scene.texts[number]
5307 if not text? then return
5308
5309 @interpreter.zoomObject(text, @params)
5310
5311 gs.GameNotifier.postMinorChange()
5312
5313 ###*
5314 * @method commandBlendText
5315 * @protected
5316 ###
5317 commandBlendText: ->
5318 SceneManager.scene.behavior.changeTextDomain(@params.numberDomain)
5319 text = SceneManager.scene.texts[@interpreter.numberValueOf(@params.number)]
5320 if not text? then return
5321
5322 @interpreter.blendObject(text, @params)
5323 gs.GameNotifier.postMinorChange()
5324 ###*
5325 * @method commandColorText
5326 * @protected
5327 ###
5328 commandColorText: ->
5329 scene = SceneManager.scene
5330 scene.behavior.changeTextDomain(@params.numberDomain)
5331 number = @interpreter.numberValueOf(@params.number)
5332 text = scene.texts[number]
5333 duration = @interpreter.durationValueOf(@params.duration)
5334 easing = gs.Easings.fromObject(@params.easing)
5335
5336 if text?
5337 text.animator.colorTo(new Color(@params.color), duration, easing)
5338 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
5339 @interpreter.isWaiting = yes
5340 @interpreter.waitCounter = duration
5341 gs.GameNotifier.postMinorChange()
5342 ###*
5343 * @method commandEraseText
5344 * @protected
5345 ###
5346 commandEraseText: ->
5347 defaults = GameManager.defaults.text
5348 flags = @params.fieldFlags || {}
5349 isLocked = gs.CommandFieldFlags.isLocked
5350 scene = SceneManager.scene
5351 scene.behavior.changeTextDomain(@params.numberDomain)
5352 number = @interpreter.numberValueOf(@params.number)
5353 text = scene.texts[number]
5354 if not text? then return
5355
5356 easing = if !isLocked(flags["easing.type"]) then gs.Easings.fromValues(@interpreter.numberValueOf(@params.easing.type), @params.easing.inOut) else gs.Easings.fromObject(defaults.disappearEasing)
5357 duration = if !isLocked(flags.duration) then @interpreter.durationValueOf(@params.duration) else defaults.disappearDuration
5358 animation = if !isLocked(flags["animation.type"]) then @params.animation else defaults.disappearAnimation
5359
5360
5361 text.animator.disappear(animation, easing, duration, (sender) =>
5362 sender.dispose()
5363 scene.behavior.changeTextDomain(sender.domain)
5364 scene.texts[number] = null
5365 )
5366
5367 if @params.waitForCompletion and not (duration == 0 or @interpreter.isInstantSkip())
5368 @interpreter.isWaiting = yes
5369 @interpreter.waitCounter = duration
5370 gs.GameNotifier.postMinorChange()
5371 ###*
5372 * @method commandTextEffect
5373 * @protected
5374 ###
5375 commandTextEffect: ->
5376 scene = SceneManager.scene
5377 scene.behavior.changeTextDomain(@params.numberDomain)
5378 number = @interpreter.numberValueOf(@params.number)
5379 text = scene.texts[number]
5380 if not text? then return
5381
5382 @interpreter.objectEffect(text, @params)
5383 gs.GameNotifier.postMinorChange()
5384 ###*
5385 * @method commandInputText
5386 * @protected
5387 ###
5388 commandInputText: ->
5389 scene = SceneManager.scene
5390 scene.behavior.changeTextDomain(@params.numberDomain)
5391 if (GameManager.settings.allowChoiceSkip||@interpreter.preview) and GameManager.tempSettings.skip
5392 @interpreter.messageObject().behavior.clear()
5393 @interpreter.setStringValueTo(@params.variable, "")
5394 return
5395
5396 @interpreter.isWaiting = yes
5397 if @interpreter.isProcessingMessageInOtherContext()
5398 @interpreter.waitForMessage()
5399 return
5400
5401 $tempFields.letters = @params.letters
5402 scene.behavior.showInputText(@params.letters, gs.CallBack("onInputTextFinish", @interpreter, @interpreter))
5403 @interpreter.waitingFor.inputText = @params
5404 gs.GameNotifier.postMinorChange()
5405 ###*
5406 * @method commandSavePersistentData
5407 * @protected
5408 ###
5409 commandSavePersistentData: -> GameManager.saveGlobalData()
5410
5411 ###*
5412 * @method commandSaveSettings
5413 * @protected
5414 ###
5415 commandSaveSettings: -> GameManager.saveSettings()
5416
5417 ###*
5418 * @method commandPrepareSaveGame
5419 * @protected
5420 ###
5421 commandPrepareSaveGame: ->
5422 if @interpreter.previewData? then return
5423
5424 @interpreter.pointer++
5425 GameManager.prepareSaveGame(@params.snapshot)
5426 @interpreter.pointer--
5427
5428 ###*
5429 * @method commandSaveGame
5430 * @protected
5431 ###
5432 commandSaveGame: ->
5433 if @interpreter.previewData? then return
5434
5435 thumbWidth = @interpreter.numberValueOf(@params.thumbWidth)
5436 thumbHeight = @interpreter.numberValueOf(@params.thumbHeight)
5437
5438 GameManager.save(@interpreter.numberValueOf(@params.slot) - 1, thumbWidth, thumbHeight)
5439
5440 ###*
5441 * @method commandLoadGame
5442 * @protected
5443 ###
5444 commandLoadGame: ->
5445 if @interpreter.previewData? then return
5446
5447 GameManager.load(@interpreter.numberValueOf(@params.slot) - 1)
5448
5449 ###*
5450 * @method commandWaitForInput
5451 * @protected
5452 ###
5453 commandWaitForInput: ->
5454 return if @interpreter.isInstantSkip()
5455
5456 gs.GlobalEventManager.offByOwner("mouseDown", @interpreter.object)
5457 gs.GlobalEventManager.offByOwner("mouseUp", @interpreter.object)
5458 gs.GlobalEventManager.offByOwner("keyDown", @interpreter.object)
5459 gs.GlobalEventManager.offByOwner("keyUp", @interpreter.object)
5460
5461 f = =>
5462 key = @interpreter.numberValueOf(@params.key)
5463 executeAction = no
5464 if Input.Mouse.isButton(@params.key)
5465 executeAction = Input.Mouse.buttons[@params.key] == @params.state
5466 else if @params.key == 100
5467 executeAction = yes if Input.keyDown and @params.state == 1
5468 executeAction = yes if Input.keyUp and @params.state == 2
5469 else if @params.key == 101
5470 executeAction = yes if Input.Mouse.buttonDown and @params.state == 1
5471 executeAction = yes if Input.Mouse.buttonUp and @params.state == 2
5472 else if @params.key == 102
5473 executeAction = yes if (Input.keyDown or Input.Mouse.buttonDown) and @params.state == 1
5474 executeAction = yes if (Input.keyUp or Input.Mouse.buttonUp) and @params.state == 2
5475 else
5476 key = if key > 100 then key - 100 else key
5477 executeAction = Input.keys[key] == @params.state
5478
5479
5480 if executeAction
5481 @interpreter.isWaiting = no
5482
5483 gs.GlobalEventManager.offByOwner("mouseDown", @interpreter.object)
5484 gs.GlobalEventManager.offByOwner("mouseUp", @interpreter.object)
5485 gs.GlobalEventManager.offByOwner("keyDown", @interpreter.object)
5486 gs.GlobalEventManager.offByOwner("keyUp", @interpreter.object)
5487
5488 gs.GlobalEventManager.on "mouseDown", f, null, @interpreter.object
5489 gs.GlobalEventManager.on "mouseUp", f, null, @interpreter.object
5490 gs.GlobalEventManager.on "keyDown", f, null, @interpreter.object
5491 gs.GlobalEventManager.on "keyUp", f, null, @interpreter.object
5492
5493 @interpreter.isWaiting = yes
5494
5495 ###*
5496 * @method commandGetInputData
5497 * @protected
5498 ###
5499 commandGetInputData: ->
5500 switch @params.field
5501 when 0 # Button A
5502 @interpreter.setNumberValueTo(@params.targetVariable, Input.keys[Input.A])
5503 when 1 # Button B
5504 @interpreter.setNumberValueTo(@params.targetVariable, Input.keys[Input.B])
5505 when 2 # Button X
5506 @interpreter.setNumberValueTo(@params.targetVariable, Input.keys[Input.X])
5507 when 3 # Button Y
5508 @interpreter.setNumberValueTo(@params.targetVariable, Input.keys[Input.Y])
5509 when 4 # Button L
5510 @interpreter.setNumberValueTo(@params.targetVariable, Input.keys[Input.L])
5511 when 5 # Button R
5512 @interpreter.setNumberValueTo(@params.targetVariable, Input.keys[Input.R])
5513 when 6 # Button START
5514 @interpreter.setNumberValueTo(@params.targetVariable, Input.keys[Input.START])
5515 when 7 # Button SELECT
5516 @interpreter.setNumberValueTo(@params.targetVariable, Input.keys[Input.SELECT])
5517 when 8 # Mouse X
5518 @interpreter.setNumberValueTo(@params.targetVariable, Input.Mouse.x)
5519 when 9 # Mouse Y
5520 @interpreter.setNumberValueTo(@params.targetVariable, Input.Mouse.y)
5521 when 10 # Mouse Wheel
5522 @interpreter.setNumberValueTo(@params.targetVariable, Input.Mouse.wheel)
5523 when 11 # Mouse Left
5524 @interpreter.setNumberValueTo(@params.targetVariable, Input.Mouse.buttons[Input.Mouse.LEFT])
5525 when 12 # Mouse Right
5526 @interpreter.setNumberValueTo(@params.targetVariable, Input.Mouse.buttons[Input.Mouse.RIGHT])
5527 when 13 # Mouse Middle
5528 @interpreter.setNumberValueTo(@params.targetVariable, Input.Mouse.buttons[Input.Mouse.MIDDLE])
5529 when 100 # Any Key
5530 anyKey = 0
5531 anyKey = 1 if Input.keyDown
5532 anyKey = 2 if Input.keyUp
5533 @interpreter.setNumberValueTo(@params.targetVariable, anyKey)
5534 when 101 # Any Button
5535 anyButton = 0
5536 anyButton = 1 if Input.Mouse.buttonDown
5537 anyButton = 2 if Input.Mouse.buttonUp
5538 @interpreter.setNumberValueTo(@params.targetVariable, anyButton)
5539 when 102 # Any Input
5540 anyInput = 0
5541 anyInput = 1 if Input.Mouse.buttonDown or Input.keyDown
5542 anyInput = 2 if Input.Mouse.buttonUp or Input.keyUp
5543 @interpreter.setNumberValueTo(@params.targetVariable, anyInput)
5544 else
5545 code = @params.field - 100
5546 @interpreter.setNumberValueTo(@params.targetVariable, Input.keys[code])
5547 ###*
5548 * @method commandGetGameData
5549 * @protected
5550 ###
5551 commandGetGameData: ->
5552 tempSettings = GameManager.tempSettings
5553 settings = GameManager.settings
5554
5555 switch @params.field
5556 when 0 # Scene ID
5557 @interpreter.setStringValueTo(@params.targetVariable, SceneManager.scene.sceneDocument.uid)
5558 when 1 # Game Time - Seconds
5559 @interpreter.setNumberValueTo(@params.targetVariable, Math.round(Graphics.frameCount / 60))
5560 when 2 # Game Time - Minutes
5561 @interpreter.setNumberValueTo(@params.targetVariable, Math.round(Graphics.frameCount / 60 / 60))
5562 when 3 # Game Time - Hours
5563 @interpreter.setNumberValueTo(@params.targetVariable, Math.round(Graphics.frameCount / 60 / 60 / 60))
5564 when 4 # Date - Day of Month
5565 @interpreter.setNumberValueTo(@params.targetVariable, new Date().getDate())
5566 when 5 # Date - Day of Week
5567 @interpreter.setNumberValueTo(@params.targetVariable, new Date().getDay())
5568 when 6 # Date - Month
5569 @interpreter.setNumberValueTo(@params.targetVariable, new Date().getMonth())
5570 when 7 # Date - Year
5571 @interpreter.setNumberValueTo(@params.targetVariable, new Date().getFullYear())
5572 when 8
5573 @interpreter.setBooleanValueTo(@params.targetVariable, settings.allowSkip)
5574 when 9
5575 @interpreter.setBooleanValueTo(@params.targetVariable, settings.allowSkipUnreadMessages)
5576 when 10
5577 @interpreter.setNumberValueTo(@params.targetVariable, settings.messageSpeed)
5578 when 11
5579 @interpreter.setBooleanValueTo(@params.targetVariable, settings.autoMessage.enabled)
5580 when 12
5581 @interpreter.setNumberValueTo(@params.targetVariable, settings.autoMessage.time)
5582 when 13
5583 @interpreter.setBooleanValueTo(@params.targetVariable, settings.autoMessage.waitForVoice)
5584 when 14
5585 @interpreter.setBooleanValueTo(@params.targetVariable, settings.autoMessage.stopOnAction)
5586 when 15
5587 @interpreter.setBooleanValueTo(@params.targetVariable, settings.timeMessageToVoice)
5588 when 16
5589 @interpreter.setBooleanValueTo(@params.targetVariable, settings.allowVideoSkip)
5590 when 17
5591 @interpreter.setBooleanValueTo(@params.targetVariable, settings.allowChoiceSkip)
5592 when 18
5593 @interpreter.setBooleanValueTo(@params.targetVariable, settings.skipVoiceOnAction)
5594 when 19
5595 @interpreter.setBooleanValueTo(@params.targetVariable, settings.fullScreen)
5596 when 20
5597 @interpreter.setBooleanValueTo(@params.targetVariable, settings.adjustAspectRatio)
5598 when 21
5599 @interpreter.setBooleanValueTo(@params.targetVariable, settings.confirmation)
5600 when 22
5601 @interpreter.setNumberValueTo(@params.targetVariable, settings.bgmVolume)
5602 when 23
5603 @interpreter.setNumberValueTo(@params.targetVariable, settings.voiceVolume)
5604 when 24
5605 @interpreter.setNumberValueTo(@params.targetVariable, settings.seVolume)
5606 when 25
5607 @interpreter.setBooleanValueTo(@params.targetVariable, settings.bgmEnabled)
5608 when 26
5609 @interpreter.setBooleanValueTo(@params.targetVariable, settings.voiceEnabled)
5610 when 27
5611 @interpreter.setBooleanValueTo(@params.targetVariable, settings.seEnabled)
5612 when 28 # Language - Code
5613 @interpreter.setStringValueTo(@params.targetVariable, LanguageManager.language?.code || "")
5614 when 29 # Language - Name
5615 @interpreter.setStringValueTo(@params.targetVariable, LanguageManager.language?.name || "")
5616 when 30
5617 @interpreter.setBooleanValueTo(@params.targetVariable, GameManager.tempSettings.skip)
5618
5619 ###*
5620 * @method commandSetGameData
5621 * @protected
5622 ###
5623 commandSetGameData: ->
5624 tempSettings = GameManager.tempSettings
5625 settings = GameManager.settings
5626
5627 switch @params.field
5628 when 0
5629 settings.allowSkip = @interpreter.booleanValueOf(@params.switchValue)
5630 when 1
5631 settings.allowSkipUnreadMessages = @interpreter.booleanValueOf(@params.switchValue)
5632 when 2
5633 settings.messageSpeed = @interpreter.numberValueOf(@params.decimalValue)
5634 when 3
5635 settings.autoMessage.enabled = @interpreter.booleanValueOf(@params.switchValue)
5636 when 4
5637 settings.autoMessage.time = @interpreter.numberValueOf(@params.numberValue)
5638 when 5
5639 settings.autoMessage.waitForVoice = @interpreter.booleanValueOf(@params.switchValue)
5640 when 6
5641 settings.autoMessage.stopOnAction = @interpreter.booleanValueOf(@params.switchValue)
5642 when 7
5643 settings.timeMessageToVoice = @interpreter.booleanValueOf(@params.switchValue)
5644 when 8
5645 settings.allowVideoSkip = @interpreter.booleanValueOf(@params.switchValue)
5646 when 9
5647 settings.allowChoiceSkip = @interpreter.booleanValueOf(@params.switchValue)
5648 when 10
5649 settings.skipVoiceOnAction = @interpreter.booleanValueOf(@params.switchValue)
5650 when 11
5651 settings.fullScreen = @interpreter.booleanValueOf(@params.switchValue)
5652 if settings.fullScreen
5653 SceneManager.scene.behavior.enterFullScreen()
5654 else
5655 SceneManager.scene.behavior.leaveFullScreen()
5656 when 12
5657 settings.adjustAspectRatio = @interpreter.booleanValueOf(@params.switchValue)
5658 Graphics.keepRatio = settings.adjustAspectRatio
5659 Graphics.onResize()
5660 when 13
5661 settings.confirmation = @interpreter.booleanValueOf(@params.switchValue)
5662 when 14
5663 settings.bgmVolume = @interpreter.numberValueOf(@params.numberValue)
5664 when 15
5665 settings.voiceVolume = @interpreter.numberValueOf(@params.numberValue)
5666 when 16
5667 settings.seVolume = @interpreter.numberValueOf(@params.numberValue)
5668 when 17
5669 settings.bgmEnabled = @interpreter.booleanValueOf(@params.switchValue)
5670 when 18
5671 settings.voiceEnabled = @interpreter.booleanValueOf(@params.switchValue)
5672 when 19
5673 settings.seEnabled = @interpreter.booleanValueOf(@params.switchValue)
5674 when 20
5675 code = @interpreter.stringValueOf(@params.textValue)
5676 language = LanguageManager.languages.first (l) => l.code == code
5677 LanguageManager.selectLanguage(language) if language
5678 when 21
5679 GameManager.tempSettings.skip = @interpreter.booleanValueOf(@params.switchValue)
5680
5681 ###*
5682 * @method commandGetObjectData
5683 * @protected
5684 ###
5685 commandGetObjectData: ->
5686 scene = SceneManager.scene
5687 switch @params.objectType
5688 when 0 # Picture
5689 scene.behavior.changePictureDomain(@params.numberDomain)
5690 object = SceneManager.scene.pictures[@interpreter.numberValueOf(@params.number)]
5691 when 1 # Background
5692 object = SceneManager.scene.backgrounds[@interpreter.numberValueOf(@params.layer)]
5693 when 2 # Text
5694 scene.behavior.changeTextDomain(@params.numberDomain)
5695 object = SceneManager.scene.texts[@interpreter.numberValueOf(@params.number)]
5696 when 3 # Movie
5697 scene.behavior.changeVideoDomain(@params.numberDomain)
5698 object = SceneManager.scene.videos[@interpreter.numberValueOf(@params.number)]
5699 when 4 # Character
5700 characterId = @interpreter.stringValueOf(@params.characterId)
5701 object = SceneManager.scene.characters.first (v) => !v.disposed and v.rid == characterId
5702 when 5 # Message Box
5703 object = gs.ObjectManager.current.objectById("messageBox")
5704 when 6 # Message Area
5705 scene.behavior.changeMessageAreaDomain(@params.numberDomain)
5706 area = SceneManager.scene.messageAreas[@interpreter.numberValueOf(@params.number)]
5707 object = area?.layout
5708 when 7 # Hotspot
5709 scene.behavior.changeHotspotDomain(@params.numberDomain)
5710 object = SceneManager.scene.hotspots[@interpreter.numberValueOf(@params.number)]
5711
5712
5713 field = @params.field
5714 if @params.objectType == 4 # Character
5715 switch @params.field
5716 when 0 # ID
5717 @interpreter.setStringValueTo(@params.targetVariable, RecordManager.characters[characterId]?.index || "")
5718 when 1 # Name
5719 @interpreter.setStringValueTo(@params.targetVariable, lcs(RecordManager.characters[characterId]?.name) || "")
5720 field -= 2
5721
5722 if @params.objectType == 6 # Message
5723 switch field
5724 when 0 # Position - X
5725 @interpreter.setNumberValueTo(@params.targetVariable, object.dstRect.x)
5726 when 1 # Position - Y
5727 @interpreter.setNumberValueTo(@params.targetVariable, object.dstRect.y)
5728 when 2 # Z-Index
5729 @interpreter.setNumberValueTo(@params.targetVariable, object.zIndex)
5730 when 3 # Opacity
5731 @interpreter.setNumberValueTo(@params.targetVariable, object.opacity)
5732 when 4 # Visible
5733 @interpreter.setBooleanValueTo(@params.targetVariable, object.visible)
5734
5735 else if object?
5736 if field >= 0
5737 switch field
5738 when 0 # Resource Name
5739 switch @params.objectType
5740 when 2
5741 @interpreter.setStringValueTo(@params.targetVariable, object.text || "")
5742 when 3
5743 @interpreter.setStringValueTo(@params.targetVariable, object.video || "")
5744 else
5745 @interpreter.setStringValueTo(@params.targetVariable, object.image || "")
5746 when 1 # Position - X
5747 @interpreter.setNumberValueTo(@params.targetVariable, object.dstRect.x)
5748 when 2 # Position - Y
5749 @interpreter.setNumberValueTo(@params.targetVariable, object.dstRect.y)
5750 when 3 # Anchor - X
5751 @interpreter.setNumberValueTo(@params.targetVariable, Math.round(object.anchor.x * 100))
5752 when 4 # Anchor - Y
5753 @interpreter.setNumberValueTo(@params.targetVariable, Math.round(object.anchor.y * 100))
5754 when 5 # Zoom - X
5755 @interpreter.setNumberValueTo(@params.targetVariable, Math.round(object.zoom.x * 100))
5756 when 6 # Zoom - Y
5757 @interpreter.setNumberValueTo(@params.targetVariable, Math.round(object.zoom.y * 100))
5758 when 7 # Size - Width
5759 @interpreter.setNumberValueTo(@params.targetVariable, object.dstRect.width)
5760 when 8 # Size - Height
5761 @interpreter.setNumberValueTo(@params.targetVariable, object.dstRect.height)
5762 when 9 # Z-Index
5763 @interpreter.setNumberValueTo(@params.targetVariable, object.zIndex)
5764 when 10 # Opacity
5765 @interpreter.setNumberValueTo(@params.targetVariable, object.opacity)
5766 when 11 # Angle
5767 @interpreter.setNumberValueTo(@params.targetVariable, object.angle)
5768 when 12 # Visible
5769 @interpreter.setBooleanValueTo(@params.targetVariable, object.visible)
5770 when 13 # Blend Mode
5771 @interpreter.setNumberValueTo(@params.targetVariable, object.blendMode)
5772 when 14 # Flipped
5773 @interpreter.setBooleanValueTo(@params.targetVariable, object.mirror)
5774
5775 ###*
5776 * @method commandSetObjectData
5777 * @protected
5778 ###
5779 commandSetObjectData: ->
5780 scene = SceneManager.scene
5781
5782 switch @params.objectType
5783 when 0 # Picture
5784 scene.behavior.changePictureDomain(@params.numberDomain)
5785 object = SceneManager.scene.pictures[@interpreter.numberValueOf(@params.number)]
5786 when 1 # Background
5787 object = SceneManager.scene.backgrounds[@interpreter.numberValueOf(@params.layer)]
5788 when 2 # Text
5789 scene.behavior.changeTextDomain(@params.numberDomain)
5790 object = SceneManager.scene.texts[@interpreter.numberValueOf(@params.number)]
5791 when 3 # Movie
5792 scene.behavior.changeVideoDomain(@params.numberDomain)
5793 object = SceneManager.scene.videos[@interpreter.numberValueOf(@params.number)]
5794 when 4 # Character
5795 characterId = @interpreter.stringValueOf(@params.characterId)
5796 object = SceneManager.scene.characters.first (v) => !v.disposed and v.rid == characterId
5797 when 5 # Message Box
5798 object = gs.ObjectManager.current.objectById("messageBox")
5799 when 6 # Message Area
5800 scene.behavior.changeMessageAreaDomain(@params.numberDomain)
5801 area = SceneManager.scene.messageAreas[@interpreter.numberValueOf(@params.number)]
5802 object = area?.layout
5803 when 7 # Hotspot
5804 scene.behavior.changeHotspotDomain(@params.numberDomain)
5805 object = SceneManager.scene.hotspots[@interpreter.numberValueOf(@params.number)]
5806
5807
5808 field = @params.field
5809 if @params.objectType == 4 # Character
5810 switch field
5811 when 0 # Name
5812 name = @interpreter.stringValueOf(@params.textValue)
5813 if object?
5814 object.name = name
5815 RecordManager.characters[characterId]?.name = name
5816 field--
5817
5818 if @params.objectType == 6 # Message
5819 switch field
5820 when 0 # Position - X
5821 object.dstRect.x = @interpreter.numberValueOf(@params.numberValue)
5822 when 1 # Position - Y
5823 object.dstRect.y = @interpreter.numberValueOf(@params.numberValue)
5824 when 2 # Z-Index
5825 object.zIndex = @interpreter.numberValueOf(@params.numberValue)
5826 when 3 # Opacity
5827 object.opacity= @interpreter.numberValueOf(@params.numberValue)
5828 when 4 # Visible
5829 object.visible = @interpreter.booleanValueOf(@params.switchValue)
5830
5831 else if object?
5832 if field >= 0
5833 switch field
5834 when 0 # Resource Name / Text
5835 switch @params.objectType
5836 when 2
5837 object.text = @interpreter.stringValueOf(@params.textValue)
5838 when 3
5839 object.video = @interpreter.stringValueOf(@params.textValue)
5840 else
5841 object.image = @interpreter.stringValueOf(@params.textValue)
5842 when 1 # Position - X
5843 object.dstRect.x = @interpreter.numberValueOf(@params.numberValue)
5844 when 2 # Position - Y
5845 object.dstRect.y = @interpreter.numberValueOf(@params.numberValue)
5846 when 3 # Anchor - X
5847 object.anchor.x = @interpreter.numberValueOf(@params.numberValue) / 100
5848 when 4 # Anchor - Y
5849 object.anchor.y = @interpreter.numberValueOf(@params.numberValue) / 100
5850 when 5 # Zoom - X
5851 object.zoom.x = @interpreter.numberValueOf(@params.numberValue) / 100
5852 when 6 # Zoom - Y
5853 object.zoom.y = @interpreter.numberValueOf(@params.numberValue) / 100
5854 when 7 # Z-Index
5855 object.zIndex = @interpreter.numberValueOf(@params.numberValue)
5856 when 8 # Opacity
5857 object.opacity= @interpreter.numberValueOf(@params.numberValue)
5858 when 9 # Angle
5859 object.angle = @interpreter.numberValueOf(@params.numberValue)
5860 when 10 # Visible
5861 object.visible = @interpreter.booleanValueOf(@params.switchValue)
5862 when 11 # Blend Mode
5863 object.blendMode = @interpreter.numberValueOf(@params.numberValue)
5864 when 12 # Flipped
5865 object.mirror = @interpreter.booleanValueOf(@params.switchValue)
5866
5867 ###*
5868 * @method commandChangeSounds
5869 * @protected
5870 ###
5871 commandChangeSounds: ->
5872 sounds = RecordManager.system.sounds
5873 fieldFlags = @params.fieldFlags || {}
5874
5875 for sound, i in @params.sounds
5876 if !gs.CommandFieldFlags.isLocked(fieldFlags["sounds."+i])
5877 sounds[i] = @params.sounds[i]
5878
5879 ###*
5880 * @method commandChangeColors
5881 * @protected
5882 ###
5883 commandChangeColors: ->
5884 colors = RecordManager.system.colors
5885 fieldFlags = @params.fieldFlags || {}
5886
5887 for color, i in @params.colors
5888 if !gs.CommandFieldFlags.isLocked(fieldFlags["colors."+i])
5889 colors[i] = new gs.Color(@params.colors[i])
5890
5891 ###*
5892 * @method commandChangeScreenCursor
5893 * @protected
5894 ###
5895 commandChangeScreenCursor: ->
5896 if @params.graphic?.name?
5897 bitmap = ResourceManager.getBitmap("#{@params.graphic?.folderPath ? "Graphics/Pictures"}/#{@params.graphic.name}")
5898 Graphics.setCursorBitmap(bitmap, @params.hx, @params.hy)
5899 else
5900 Graphics.setCursorBitmap(null, 0, 0)
5901
5902 ###*
5903 * @method commandResetGlobalData
5904 * @protected
5905 ###
5906 commandResetGlobalData: ->
5907 GameManager.resetGlobalData()
5908
5909 ###*
5910 * @method commandScript
5911 * @protected
5912 ###
5913 commandScript: ->
5914 try
5915 if !@params.scriptFunc
5916 @params.scriptFunc = eval("(function(){" + @params.script + "})")
5917
5918 @params.scriptFunc()
5919 catch ex
5920 console.log(ex)
5921
5922window.CommandInterpreter = Component_CommandInterpreter
5923gs.Component_CommandInterpreter = Component_CommandInterpreter
5924
5925