public ClipSlot(string name, Clip clip, ChainedCommand command, ushort id) { Name = name; Clip = clip; ChainedCommand = command; Id = id; }
public static ProcessResultArray <Clip> ProcessChainedCommand(ChainedCommand chainedCommand) { Clip[] sourceClips = chainedCommand.SourceClips.Where(c => c.Notes.Count > 0).ToArray(); if (sourceClips.Length < 1) { return(new ProcessResultArray <Clip>("No clips or empty clips specified. Aborting.")); } var currentSourceClips = sourceClips; var resultContainer = new ProcessResultArray <Clip>("No commands specified"); var warnings = new List <string>(); foreach (var command in chainedCommand.Commands) { resultContainer = ProcessCommand(command, currentSourceClips, chainedCommand.TargetMetaData); if (resultContainer.Success) { currentSourceClips = resultContainer.Result; if (resultContainer.WarningMessage.Length > 0) { warnings.Add(resultContainer.WarningMessage); } } else { break; } } if (warnings.Count > 0) { resultContainer = new ProcessResultArray <Clip>(resultContainer.Success, resultContainer.Result, resultContainer.ErrorMessage, string.Join(System.Environment.NewLine, warnings)); } return(resultContainer); }
public override EventResult HandleEvent(EventContext context, MessageAnswerSelectedEvent @event) { context.PlayerInput.Suspend(); ChainedCommand moveActorCommand = Commands .Chain(Commands .ActorInstanceMove(_actorInstance, MoveDirection.Right) .Repeat(TimeSpan.FromMilliseconds(100), 9)) .And(Commands.Delay(TimeSpan.FromMilliseconds(100))) .And(Commands.ActorInstanceMove(_actorInstance, MoveDirection.Down)) .And(Commands.Delay(TimeSpan.FromMilliseconds(500))) .And(Commands.PlaySoundEffect(context.GetSoundEffectById(ExplodeSoundEffect.SoundEffectId), Volume.Full)) .And(Commands.RemoveSprite(context.CurrentBoard.ForegroundLayer, new Coordinate(50, 11))) .And(Commands.ActorInstanceDestroy(_actorInstance)) .And(Commands.PlayerResumeInput()); if (context.Player.Coordinate == new Coordinate(_actorInstance.Coordinate.X + 1, _actorInstance.Coordinate.Y)) { ChainedCommand command = Commands .Chain(Commands.Delay(TimeSpan.FromSeconds(1))) .And(Commands.PlaySoundEffect(context.GetSoundEffectById(SlapSoundEffect.SoundEffectId), Volume.Full)) .And(Commands.PlayerMove(MoveDirection.Down)) .And(Commands.Message(Message.Build(Color.DarkRed, new EventHandlerCollection(new SlapMessageClosedEventHandler(moveActorCommand))).Text(Color.Yellow, "WHAP!"))) .And(Commands.Delay(TimeSpan.FromSeconds(1))); context.EnqueueCommand(command); return(EventResult.Completed); } context.EnqueueCommand(moveActorCommand); return(EventResult.Completed); }
public static ProcessResult <ChainedCommand> ParseFormulaToChainedCommand(string formula, List <Clip> clips, ClipMetaData metadata) { var valid = new char[] { '[', ']' }.All(c => formula.IndexOf(c) >= 0); if (!valid) { return(new ProcessResult <ChainedCommand>($"Invalid formula: {formula}")); } var lexer = new Lexer(formula, clips); var result = lexer.GetTokens(); if (!result.Success) { return(new ProcessResult <ChainedCommand>(result.ErrorMessage)); } Token[] commandTokens = result.Result; var commandTokensLists = new List <List <Token> >(); var activeCommandTokenList = new List <Token>(); var sourceClips = commandTokens.TakeWhile(x => x.Type == TokenType.InlineClip).Select(x => x.Clip).ToArray(); var tokensToProcess = commandTokens.Skip(sourceClips.Count()).ToArray(); if (tokensToProcess.Length == 0) { // Empty command, assume concat tokensToProcess = new Token[] { new Token(TokenType.Concat, "concat", 0), }; } foreach (var token in tokensToProcess) { if (token.IsCommand) { if (activeCommandTokenList.Count == 0) { activeCommandTokenList.Add(token); } else { commandTokensLists.Add(activeCommandTokenList); activeCommandTokenList = new List <Token> { token }; } } else { activeCommandTokenList.Add(token); } } commandTokensLists.Add(activeCommandTokenList); // add last command token list var commands = commandTokensLists.Select(x => ParseTokensToCommand(x)).ToList(); var chainedCommand = new ChainedCommand(commands, sourceClips, metadata); return(new ProcessResult <ChainedCommand>(chainedCommand)); }
public static ProcessResult <ChainedCommand> ParseFormulaToChainedCommand(string formula, List <Clip> clips, ClipMetaData metadata) { var valid = new char[] { '[', ']' }.All(c => formula.IndexOf(c) >= 0); if (!valid) { return(new ProcessResult <ChainedCommand>($"Invalid formula: {formula}")); } var lexer = new Lexer(formula, clips); var(success, tokens, errorMessage) = lexer.GetTokens(); if (!success) { return(new ProcessResult <ChainedCommand>(errorMessage)); } TreeToken syntaxTree; (success, syntaxTree, errorMessage) = CreateSyntaxTree(tokens); if (!success) { return(new ProcessResult <ChainedCommand>(errorMessage)); } // remaining steps: // convert any nested statements to inline clips - might involve some refactoring where parsing to commands and applying these can be done selectively and not as part of the fixed pipeline we have now Token[] commandTokens; (success, commandTokens, errorMessage) = ResolveAndFlattenSyntaxTree(syntaxTree); if (!success) { return(new ProcessResult <ChainedCommand>(errorMessage)); } var sourceClips = commandTokens.TakeWhile(x => x.Type == TokenType.InlineClip).Select(x => x.Clip).ToArray(); var tokensToProcess = commandTokens.Skip(sourceClips.Length).ToArray(); var commandTokensLists = ExtractCommandTokensLists(tokensToProcess); var commands = commandTokensLists.Select(ParseTokensToCommand).ToList(); var chainedCommand = new ChainedCommand(commands, sourceClips, metadata); return(new ProcessResult <ChainedCommand>(chainedCommand)); }
public static ProcessResult <ChainedCommand> ParseFormulaToChainedCommand(string formula, List <Clip> clips, ClipMetaData metadata) { var valid = new char[] { '[', ']' }.All(c => formula.IndexOf(c) >= 0); if (!valid) { return(new ProcessResult <ChainedCommand>($"Invalid formula: {formula}")); } var lexer = new Lexer(formula, clips); var(success, tokens, errorMessage) = lexer.GetTokens(); if (!success) { return(new ProcessResult <ChainedCommand>(errorMessage)); } TreeToken syntaxTree; (success, syntaxTree, errorMessage) = CreateSyntaxTree(tokens); if (!success) { return(new ProcessResult <ChainedCommand>(errorMessage)); } Token[] commandTokens; (success, commandTokens, errorMessage) = ResolveAndFlattenSyntaxTree(syntaxTree); if (!success) { return(new ProcessResult <ChainedCommand>(errorMessage)); } var sourceClips = commandTokens.TakeWhile(x => x.Type == TokenType.InlineClip).Select(x => x.Clip).ToArray(); var tokensToProcess = commandTokens.Skip(sourceClips.Length).ToArray(); var commandTokensLists = ExtractCommandTokensLists(tokensToProcess); var commands = commandTokensLists.Select(ParseTokensToCommand).ToList(); var chainedCommand = new ChainedCommand(commands, sourceClips, metadata); return(new ProcessResult <ChainedCommand>(chainedCommand)); }
public override EventResult HandleEvent(EventContext context, PlayerTouchedActorInstanceEvent @event) { Color indent0 = Color.Yellow; Color indent1 = Color.White; MessageBuilder messageBuilder = Message .Build(Color.DarkBlue) .Text(indent0, "Actors", 1) .Text(indent1, " - Provide a template for actor instances", 1) .Text(indent1, " - Don't have any behavior or event handlers"); context.EnqueueCommand(Commands.Message(messageBuilder)); if (_handledOnce) { return(EventResult.Canceled); } _handledOnce = true; Actor actor = context.GetActorById(@event.Target.ActorId); ActorInstance actorInstance = actor.CreateActorInstance(BoardId, ExitCoordinates[0], new EventHandlerCollection(new PlayerTouchedActorsActorCopyEventHandler())); ActorInstanceCreateCommand actorInstanceCreateCommand = Commands.ActorInstanceCreate(context.GetBoardById(BoardId), actorInstance); context.EnqueueCommand(actorInstanceCreateCommand); ChainedCommand chainedCommand = Commands .Chain(Commands.Delay(TimeSpan.FromMilliseconds(200))) .And(Commands .ActorInstanceMove(actorInstance, MoveDirection.Down) .Repeat(TimeSpan.FromMilliseconds(200), 2)) .And(Commands.Delay(TimeSpan.FromMilliseconds(200))) .And(Commands .ActorInstanceMove(actorInstance, MoveDirection.Right) .Repeat(TimeSpan.FromMilliseconds(200), 5)); context.EnqueueCommand(chainedCommand); return(EventResult.Completed); }