From a47326d22b6ecffb135c9d0165edb11c5cd7c8c5 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 11 Mar 2014 17:13:47 +0000 Subject: [PATCH] Moved command classes into a separate namespace to avoid them appearing in code completion popups. --- Assets/Fungus/Scripts/Commands.cs | 1158 ++++++++++++----------- Assets/Fungus/Scripts/GameController.cs | 52 +- 2 files changed, 608 insertions(+), 602 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands.cs b/Assets/Fungus/Scripts/Commands.cs index 8f22f202..315d3cf5 100644 --- a/Assets/Fungus/Scripts/Commands.cs +++ b/Assets/Fungus/Scripts/Commands.cs @@ -5,737 +5,743 @@ using System.Collections.Generic; namespace Fungus { - /** - * Call a delegate method on execution. - * This command can be used to schedule arbitrary script code. + /** + * Command classes have their own namespace to prevent them popping up in code completion */ - public class CallCommand : CommandQueue.Command + namespace Command { - Action callAction; - - public CallCommand(Action _callAction) + /** + * Call a delegate method on execution. + * This command can be used to schedule arbitrary script code. + */ + public class CallCommand : CommandQueue.Command { - if (_callAction == null) - { - Debug.LogError("Action must not be null."); - return; - } + Action callAction; - callAction = _callAction; - } - - public override void Execute(CommandQueue commandQueue, Action onComplete) - { - if (callAction != null) + public CallCommand(Action _callAction) { - callAction(); - } - - // Execute next command - onComplete(); - } - } + if (_callAction == null) + { + Debug.LogError("Action must not be null."); + return; + } - /** - * Wait for a period of time. - */ - public class WaitCommand : CommandQueue.Command - { - float duration; - - public WaitCommand(float _duration) - { - duration = _duration; - } - - public override void Execute(CommandQueue commandQueue, Action onComplete) - { - commandQueue.StartCoroutine(WaitCoroutine(duration, onComplete)); - } - - IEnumerator WaitCoroutine(float duration, Action onComplete) - { - yield return new WaitForSeconds(duration); - if (onComplete != null) + callAction = _callAction; + } + + public override void Execute(CommandQueue commandQueue, Action onComplete) { + if (callAction != null) + { + callAction(); + } + + // Execute next command onComplete(); - } + } } - } - /** - * Sets the currently active view immediately. - * The main camera snaps to the active view. - */ - public class SetViewCommand : CommandQueue.Command - { - View view; - - public SetViewCommand(View _view) + /** + * Wait for a period of time. + */ + public class WaitCommand : CommandQueue.Command { - if (_view == null) + float duration; + + public WaitCommand(float _duration) { - Debug.LogError("View must not be null"); + duration = _duration; } - - view = _view; - } - - public override void Execute(CommandQueue commandQueue, Action onComplete) - { - Game game = Game.GetInstance(); - - game.cameraController.SnapToView(view); - game.activeView = view; - - // Set the first page component found (if any) as the active page - Page page = view.gameObject.GetComponentInChildren(); - if (page != null) + + public override void Execute(CommandQueue commandQueue, Action onComplete) { - Game.GetInstance().activePage = page; + commandQueue.StartCoroutine(WaitCoroutine(duration, onComplete)); } - - if (onComplete != null) + + IEnumerator WaitCoroutine(float duration, Action onComplete) { - onComplete(); + yield return new WaitForSeconds(duration); + if (onComplete != null) + { + onComplete(); + } } - } - } - - /** - * Sets the currently active page for text rendering. - */ - public class SetPageCommand : CommandQueue.Command - { - Page page; - - public SetPageCommand(Page _page) - { - page = _page; } - - public override void Execute(CommandQueue commandQueue, Action onComplete) + + /** + * Sets the currently active view immediately. + * The main camera snaps to the active view. + */ + public class SetViewCommand : CommandQueue.Command { - Game.GetInstance().activePage = page; - if (onComplete != null) + View view; + + public SetViewCommand(View _view) { - onComplete(); + if (_view == null) + { + Debug.LogError("View must not be null"); + } + + view = _view; } - } - } + + public override void Execute(CommandQueue commandQueue, Action onComplete) + { + Game game = Game.GetInstance(); - /** - * Sets the currently active Page Style for rendering Pages. - */ - public class SetPageStyleCommand : CommandQueue.Command - { - PageStyle pageStyle; - - public SetPageStyleCommand(PageStyle _pageStyle) - { - pageStyle = _pageStyle; + game.cameraController.SnapToView(view); + game.activeView = view; + + // Set the first page component found (if any) as the active page + Page page = view.gameObject.GetComponentInChildren(); + if (page != null) + { + Game.GetInstance().activePage = page; + } + + if (onComplete != null) + { + onComplete(); + } + } } - - public override void Execute(CommandQueue commandQueue, Action onComplete) + + /** + * Sets the currently active page for text rendering. + */ + public class SetPageCommand : CommandQueue.Command { - Game.GetInstance().activePageStyle = pageStyle; - if (onComplete != null) + Page page; + + public SetPageCommand(Page _page) { - onComplete(); + page = _page; } - } - } - - /** - * Sets the title text displayed at the top of the active page. - */ - public class TitleCommand : CommandQueue.Command - { - string titleText; - - public TitleCommand(string _titleText) - { - titleText = _titleText; + + public override void Execute(CommandQueue commandQueue, Action onComplete) + { + Game.GetInstance().activePage = page; + if (onComplete != null) + { + onComplete(); + } + } } - - public override void Execute(CommandQueue commandQueue, Action onComplete) + + /** + * Sets the currently active Page Style for rendering Pages. + */ + public class SetPageStyleCommand : CommandQueue.Command { - Page page = Game.GetInstance().activePage; - if (page == null) - { - Debug.LogError("Active page must not be null"); - } - else + PageStyle pageStyle; + + public SetPageStyleCommand(PageStyle _pageStyle) { - page.SetTitle(titleText); + pageStyle = _pageStyle; } - if (onComplete != null) + + public override void Execute(CommandQueue commandQueue, Action onComplete) { - onComplete(); - } - } - } - - /** - * Writes story text to the currently active page. - * A 'continue' button is displayed when the text has fully appeared. - */ - public class SayCommand : CommandQueue.Command - { - string storyText; - - public SayCommand(string _storyText) - { - storyText = _storyText; + Game.GetInstance().activePageStyle = pageStyle; + if (onComplete != null) + { + onComplete(); + } + } } - public override void Execute(CommandQueue commandQueue, Action onComplete) + /** + * Sets the title text displayed at the top of the active page. + */ + public class TitleCommand : CommandQueue.Command { - Page page = Game.GetInstance().activePage; - if (page == null) + string titleText; + + public TitleCommand(string _titleText) { - Debug.LogError("Active page must not be null"); + titleText = _titleText; } - else + + public override void Execute(CommandQueue commandQueue, Action onComplete) { - page.Say(storyText, onComplete); - } + Page page = Game.GetInstance().activePage; + if (page == null) + { + Debug.LogError("Active page must not be null"); + } + else + { + page.SetTitle(titleText); + } + if (onComplete != null) + { + onComplete(); + } + } } - } - /** - * Adds an option button to the current list of options. - * Use the Choose command to display added options. - */ - public class AddOptionCommand : CommandQueue.Command - { - string optionText; - Action optionAction; - - public AddOptionCommand(string _optionText, Action _optionAction) - { - optionText = _optionText; - optionAction = _optionAction; - } - - public override void Execute(CommandQueue commandQueue, Action onComplete) + /** + * Writes story text to the currently active page. + * A 'continue' button is displayed when the text has fully appeared. + */ + public class SayCommand : CommandQueue.Command { - Page page = Game.GetInstance().activePage; - if (page == null) - { - Debug.LogError("Active page must not be null"); - } - else + string storyText; + + public SayCommand(string _storyText) { - page.AddOption(optionText, optionAction); + storyText = _storyText; } - if (onComplete != null) + + public override void Execute(CommandQueue commandQueue, Action onComplete) { - onComplete(); + Page page = Game.GetInstance().activePage; + if (page == null) + { + Debug.LogError("Active page must not be null"); + } + else + { + page.Say(storyText, onComplete); + } } - } - } - - /** - * Displays all previously added options. - */ - public class ChooseCommand : CommandQueue.Command - { - string chooseText; - - public ChooseCommand(string _chooseText) - { - chooseText = _chooseText; } - - public override void Execute(CommandQueue commandQueue, Action onComplete) + + /** + * Adds an option button to the current list of options. + * Use the Choose command to display added options. + */ + public class AddOptionCommand : CommandQueue.Command { - Page page = Game.GetInstance().activePage; - if (page == null) + string optionText; + Action optionAction; + + public AddOptionCommand(string _optionText, Action _optionAction) { - Debug.LogError("Active page must not be null"); + optionText = _optionText; + optionAction = _optionAction; } - else + + public override void Execute(CommandQueue commandQueue, Action onComplete) { - page.Choose(chooseText); - } - // Choose always clears commandQueue, so no need to call onComplete() - } - } - - /** - * Changes the active room to a different room - */ - public class MoveToRoomCommand : CommandQueue.Command - { - Room room; + Page page = Game.GetInstance().activePage; + if (page == null) + { + Debug.LogError("Active page must not be null"); + } + else + { + page.AddOption(optionText, optionAction); + } + if (onComplete != null) + { + onComplete(); + } + } + } - public MoveToRoomCommand(Room _room) + /** + * Displays all previously added options. + */ + public class ChooseCommand : CommandQueue.Command { - if (_room == null) + string chooseText; + + public ChooseCommand(string _chooseText) { - Debug.LogError("Room must not be null."); - return; + chooseText = _chooseText; } - - room = _room; - } - - public override void Execute(CommandQueue commandQueue, Action onComplete) - { - Game.GetInstance().MoveToRoom(room); - - // MoveToRoom always resets the command queue so no need to call onComplete + + public override void Execute(CommandQueue commandQueue, Action onComplete) + { + Page page = Game.GetInstance().activePage; + if (page == null) + { + Debug.LogError("Active page must not be null"); + } + else + { + page.Choose(chooseText); + } + // Choose always clears commandQueue, so no need to call onComplete() + } } - } - - /** - * Sets a global boolean flag value - */ - public class SetFlagCommand : CommandQueue.Command - { - string key; - bool value; - public SetFlagCommand(string _key, bool _value) + /** + * Changes the active room to a different room + */ + public class MoveToRoomCommand : CommandQueue.Command { - key = _key; - value = _value; - } + Room room; - public override void Execute(CommandQueue commandQueue, Action onComplete) - { - Game.GetInstance().state.SetFlag(key, value); - if (onComplete != null) + public MoveToRoomCommand(Room _room) { - onComplete(); - } - } - } + if (_room == null) + { + Debug.LogError("Room must not be null."); + return; + } - /** - * Sets a global integer counter value - */ - public class SetCounterCommand : CommandQueue.Command - { - string key; - int value; - - public SetCounterCommand(string _key, int _value) - { - key = _key; - value = _value; - } - - public override void Execute(CommandQueue commandQueue, Action onComplete) - { - Game.GetInstance().state.SetCounter(key, value); - if (onComplete != null) - { - onComplete(); + room = _room; } - } - } - - /** - * Sets a global inventory count value - */ - public class SetInventoryCommand : CommandQueue.Command - { - string key; - int value; - - public SetInventoryCommand(string _key, int _value) - { - key = _key; - value = _value; - } - - public override void Execute(CommandQueue commandQueue, Action onComplete) - { - Game.GetInstance().state.SetInventory(key, value); - if (onComplete != null) + + public override void Execute(CommandQueue commandQueue, Action onComplete) { - onComplete(); - } - } - } + Game.GetInstance().MoveToRoom(room); - /** - * Fades a sprite to a given alpha value over a period of time - */ - public class FadeSpriteCommand : CommandQueue.Command - { - SpriteRenderer spriteRenderer; - Color targetColor; - float fadeDuration; - Vector2 slideOffset = Vector2.zero; - - public FadeSpriteCommand(SpriteRenderer _spriteRenderer, - Color _targetColor, - float _fadeDuration, - Vector2 _slideOffset) - { - if (_spriteRenderer == null) - { - Debug.LogError("Sprite renderer must not be null."); - return; + // MoveToRoom always resets the command queue so no need to call onComplete } - - spriteRenderer = _spriteRenderer; - targetColor = _targetColor; - fadeDuration = _fadeDuration; - slideOffset = _slideOffset; } - - public override void Execute(CommandQueue commandQueue, Action onComplete) + + /** + * Sets a global boolean flag value + */ + public class SetFlagCommand : CommandQueue.Command { - SpriteFader.FadeSprite(spriteRenderer, targetColor, fadeDuration, slideOffset); + string key; + bool value; - // Fade is asynchronous, but command completes immediately. - // If you need to wait for the fade to complete, just use an additional Wait() command - if (onComplete != null) + public SetFlagCommand(string _key, bool _value) { - onComplete(); + key = _key; + value = _value; } - } - } - /** - * Sets an animator trigger to change the animator state for an animated sprite - */ - public class SetAnimatorTriggerCommand : CommandQueue.Command - { - Animator animator; - string triggerName; - - public SetAnimatorTriggerCommand(Animator _animator, - string _triggerName) - { - if (_animator == null) + public override void Execute(CommandQueue commandQueue, Action onComplete) { - Debug.LogError("Animator must not be null."); - return; - } - - animator = _animator; - triggerName = _triggerName; + Game.GetInstance().state.SetFlag(key, value); + if (onComplete != null) + { + onComplete(); + } + } } - - public override void Execute(CommandQueue commandQueue, Action onComplete) - { - animator.SetTrigger(triggerName); - - if (onComplete != null) - { - onComplete(); - } - } - } - - /** - * Makes a sprite behave as a clickable button - */ - public class AddButtonCommand : CommandQueue.Command - { - SpriteRenderer spriteRenderer; - bool autoDisplay; - Action buttonAction; - public AddButtonCommand(SpriteRenderer _spriteRenderer, - Action _buttonAction, - bool _autoDisplay) + /** + * Sets a global integer counter value + */ + public class SetCounterCommand : CommandQueue.Command { - if (_spriteRenderer == null) + string key; + int value; + + public SetCounterCommand(string _key, int _value) { - Debug.LogError("Sprite renderer must not be null."); - return; + key = _key; + value = _value; } - spriteRenderer = _spriteRenderer; - autoDisplay = _autoDisplay; - buttonAction = _buttonAction; + public override void Execute(CommandQueue commandQueue, Action onComplete) + { + Game.GetInstance().state.SetCounter(key, value); + if (onComplete != null) + { + onComplete(); + } + } } - - public override void Execute(CommandQueue commandQueue, Action onComplete) + + /** + * Sets a global inventory count value + */ + public class SetInventoryCommand : CommandQueue.Command { - Button.MakeButton(spriteRenderer, autoDisplay, buttonAction); + string key; + int value; - if (onComplete != null) + public SetInventoryCommand(string _key, int _value) { - onComplete(); + key = _key; + value = _value; } - } - } - - /** - * Makes a sprite stop behaving as a clickable button - */ - public class RemoveButtonCommand : CommandQueue.Command - { - SpriteRenderer spriteRenderer; + + public override void Execute(CommandQueue commandQueue, Action onComplete) + { + Game.GetInstance().state.SetInventory(key, value); + if (onComplete != null) + { + onComplete(); + } + } + } - public RemoveButtonCommand(SpriteRenderer _spriteRenderer) + /** + * Fades a sprite to a given alpha value over a period of time + */ + public class FadeSpriteCommand : CommandQueue.Command { - if (_spriteRenderer == null) + SpriteRenderer spriteRenderer; + Color targetColor; + float fadeDuration; + Vector2 slideOffset = Vector2.zero; + + public FadeSpriteCommand(SpriteRenderer _spriteRenderer, + Color _targetColor, + float _fadeDuration, + Vector2 _slideOffset) { - Debug.LogError("Sprite renderer must not be null."); - return; + if (_spriteRenderer == null) + { + Debug.LogError("Sprite renderer must not be null."); + return; + } + + spriteRenderer = _spriteRenderer; + targetColor = _targetColor; + fadeDuration = _fadeDuration; + slideOffset = _slideOffset; } - spriteRenderer = _spriteRenderer; + public override void Execute(CommandQueue commandQueue, Action onComplete) + { + SpriteFader.FadeSprite(spriteRenderer, targetColor, fadeDuration, slideOffset); + + // Fade is asynchronous, but command completes immediately. + // If you need to wait for the fade to complete, just use an additional Wait() command + if (onComplete != null) + { + onComplete(); + } + } } - - public override void Execute(CommandQueue commandQueue, Action onComplete) + + /** + * Sets an animator trigger to change the animator state for an animated sprite + */ + public class SetAnimatorTriggerCommand : CommandQueue.Command { - Button button = spriteRenderer.gameObject.GetComponent