示例#1
0
        private void ResolveFlowOverrides()
        {
            foreach (var labelFlowPair in flowOverrides)
            {
                UpperString      label       = labelFlowPair.Key;
                ActorFlowControl flowControl = labelFlowPair.Value;

                if (!Labels.Contains(label))
                {
                    Log.Error($"Unable to find label {label} in actor {definition.Name}");
                    continue;
                }

                switch (flowControl.FlowType)
                {
                case ActorStateBranch.Goto:
                    int newOffset = ResolveOverrideGotoOffset(flowControl) ?? 0;
                    Labels.Add(label, newOffset);
                    break;

                case ActorStateBranch.Stop:
                    Labels.Remove(label);
                    break;

                default:
                    Log.Error($"Cannot apply flow override branch type {flowControl.FlowType} to label {label} in actor {definition.Name}");
                    break;
                }
            }
        }
示例#2
0
        private int?ResolveOverrideGotoOffset(ActorFlowControl flowControl)
        {
            if (!flowControl.Label)
            {
                return(null);
            }

            int?        index;
            UpperString label = flowControl.Label.Value;

            if (flowControl.Parent)
            {
                index = GetSuperOrParent(flowControl.Parent.Value, label);
            }
            else
            {
                index = Labels[label];
            }

            if (index == null)
            {
                return(null);
            }
            return(index.Value + flowControl.Offset);
        }
示例#3
0
        private int?LabelToOffset(ActorFrame frame)
        {
            ActorFlowControl flowControl = frame.FlowControl;
            ActorStateBranch type        = flowControl.FlowType;

            Debug.Assert(type == ActorStateBranch.Goto || type == ActorStateBranch.Loop, "Expected Goto or Loop label here only");

            int?        index;
            UpperString label = flowControl.Label.Value;

            if (type == ActorStateBranch.Goto && flowControl.Parent)
            {
                UpperString parent = flowControl.Parent.Value;
                index = GetSuperOrParent(parent, label);

                if (index == null)
                {
                    Log.Error($"Unable to find label: {parent}::{label}");
                    return(null);
                }
            }
            else
            {
                index = Labels[label];
                if (index == null)
                {
                    Log.Error($"Unable to find label: {label}");
                    return(null);
                }
            }

            // The offset to the label is the delta from our current position,
            // plus any extra offset that the flow control will have provided.
            return(index.Value - frame.FrameIndex + flowControl.Offset);
        }
示例#4
0
 public ActorFlowControl(ActorFlowControl other)
 {
     FlowType = other.FlowType;
     Label    = new Optional <UpperString>(other.Label.Value);
     Parent   = new Optional <UpperString>(other.Parent.Value);
     Offset   = other.Offset;
 }
示例#5
0
 public ActorFrame(ActorFrame other)
 {
     FrameIndex      = other.FrameIndex;
     Sprite          = other.Sprite;
     Ticks           = other.Ticks;
     Properties      = new ActorFrameProperties(other.Properties);
     ActionFunction  = other.ActionFunction.Map(af => new ActorActionFunction(af));
     FlowControl     = new ActorFlowControl(other.FlowControl);
     NextStateOffset = other.NextStateOffset;
 }
示例#6
0
 public ActorFrame(int frameIndex, UpperString sprite, int ticks, ActorFrameProperties properties,
                   Optional <ActorActionFunction> actionFunction, ActorFlowControl flowControl = null,
                   int nextStateOffset = OffsetNotSet)
 {
     FrameIndex      = frameIndex;
     Sprite          = sprite;
     Ticks           = ticks;
     Properties      = properties;
     ActionFunction  = actionFunction;
     FlowControl     = flowControl ?? new ActorFlowControl();
     NextStateOffset = nextStateOffset;
 }