コード例 #1
0
 /// <summary>
 /// Deletes the given stitch and cleans up stitch references.
 /// </summary>
 public void RemoveStitch(Stitch stitch)
 {
     // Stitch has references, so unpoint all stitches from this stitch
     if (stitch.RefCount != 0)
     {
         RepointStitchToStitch(stitch, null);
         if (stitch.RefCount != 0)
         {
             throw new System.Exception("Fixing ref-count on stitch removal failed.");
         }
     }
     stitch.Undivert();
     // Detach options
     for (int t = stitch.Options.Count - 1; t >= 0; t--)
     {
         stitch.RemoveOption(stitch.Options [t]);
     }
     RemovePageNumber(stitch);
     // Remove the stitch from its Story
     for (var t = 0; t < Story.Stitches.Count; ++t)
     {
         if (Story.Stitches [t] == stitch)
         {
             Story.Stitches.RemoveAt(t);
             return;
         }
     }
 }
コード例 #2
0
        public void InsertPageNumber(Stitch stitch)
        {
            if (stitch.VerticalDistanceFromPageNumberHeader < 2 ||
                PageSize(stitch.PageNumber) < StoryModel.maxPreferredPageLength / 2 ||
                HeaderWithinDistanceOfStitch(3, stitch))
            {
                return;
            }
            if (stitch.PageNumber != 0)
            {
                return;
            }
            var number   = stitch.PageNumber + 1;
            var stitches = Story.Stitches;

            for (var r = 0; r < stitches.Count; r++)
            {
                var i = stitches[r].PageNumber;
                if (i >= number)
                {
                    stitches [r].SetPageNumberLabel(this, i + 1);
                }
            }
            stitch.SetPageNumberLabel(this, number);
            ComputePageNumbers();
        }
コード例 #3
0
        /// <summary>
        /// Creates a new Stitch with the given body text and adds it
        /// to the current Story.
        /// </summary>
        public Stitch CreateStitch(string text)
        {
            Stitch s = new Stitch(text);

            Story.Stitches.Add(s);
            return(s);
        }
コード例 #4
0
 /// <summary>
 /// Replaces each reference to the source stitch with a reference
 /// to the target stitch. All stitches and options that link to
 /// the source stitch will be modified.
 /// </summary>
 public void RepointStitchToStitch(Stitch source, Stitch target)
 {
     foreach (var stitch in Story.Stitches)
     {
         // Find all stitches that link to the source stitch
         // and swap it with the target stitch
         if (stitch.DivertStitch == source)
         {
             stitch.Undivert();
             if (target != null)
             {
                 stitch.DivertTo(target);
             }
         }
         foreach (var option in stitch.Options)
         {
             // Find all options that link to the source stitch
             // and relink them to the target stitch
             if (option.LinkStitch == source)
             {
                 option.Unlink();
                 if (target != null)
                 {
                     option.CreateLinkStitch(target);
                 }
             }
         }
     }
 }
コード例 #5
0
 public void DivertTo(Stitch stitch)
 {
     if (stitch == this)
     {
         throw new System.Exception("Diverted a stitch back to itself");
     }
     if (DivertStitch != null)
     {
         DivertStitch.RefCount--;
     }
     DivertStitch = stitch;
     DivertStitch.RefCount++;
 }
コード例 #6
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            Stitch s = obj as Stitch;

            if ((System.Object)s == null)
            {
                return(false);
            }
            return(s.Name == Name);
        }
コード例 #7
0
        Stitch GetOrCreateStitch(Story story, string stitchName)
        {
            if (string.IsNullOrEmpty(stitchName))
            {
                return(null);
            }
            Stitch stitch = story.Stitches.FirstOrDefault(s => s.Name == stitchName);

            if (stitch == null)
            {
                stitch      = new Stitch();
                stitch.Name = stitchName;
                story.Stitches.Add(stitch);
            }
            return(stitch);
        }
コード例 #8
0
 public void CreateLinkStitch(Stitch target)
 {
     if (target == null)
     {
         return;
     }
     if (LinkStitch == target)
     {
         return;
     }
     if (LinkStitch != null)
     {
         LinkStitch.RefCount--;
     }
     LinkStitch = target;
     LinkStitch.RefCount++;
 }
コード例 #9
0
        void ReadOptionContentItem(JsonObject obj, Story story, Stitch stitch)
        {
            Option option = stitch.AddOption();

            foreach (var kvp in obj)
            {
                string property = kvp.Key;
                object value    = kvp.Value;
                switch (property)
                {
                case "option":
                    option.Text = (string)value;
                    break;

                case "linkPath":
                    option.LinkStitch = GetOrCreateStitch(story, (string)value);
                    break;

                case "ifConditions":
                    var ifConditionsArray = (JsonArray)value;
                    if (ifConditionsArray == null)
                    {
                        break;
                    }
                    foreach (var c in ifConditionsArray)
                    {
                        var val = (string)((JsonObject)c) ["ifCondition"];
                        option.IfConditions.Add(val);
                    }
                    break;

                case "notIfConditions":
                    var notIfConditionsArray = (JsonArray)value;
                    if (notIfConditionsArray == null)
                    {
                        break;
                    }
                    foreach (var c in notIfConditionsArray)
                    {
                        var val = (string)((JsonObject)c)["notIfCondition"];
                        option.NotIfConditions.Add(val);
                    }
                    break;
                }
            }
        }
コード例 #10
0
        public void RemovePageNumber(Stitch stitch)
        {
            var currentNumber = stitch.PageNumber;

            if (currentNumber <= 0)
            {
                return;
            }
            stitch.SetPageNumberLabel(this, -1);
            foreach (var s in Story.Stitches)
            {
                if (s.PageNumber > currentNumber)
                {
                    s.SetPageNumberLabel(this, s.PageNumber - 1);
                }
            }
            ComputePageNumbers();
        }
コード例 #11
0
        void ReadContentItem(JsonObject obj, Story story, Stitch stitch)
        {
            foreach (var kvp in obj)
            {
                string property = (string)kvp.Key;
                object value    = kvp.Value;
                switch (property)
                {
                case "runOn":
                    stitch.RunOn = (bool)value;
                    break;

                case "pageNum":
                    stitch.PageNumber = ParseInt(value);
                    break;

                case "pageLabel":
                    stitch.PageLabel = (string)value;
                    break;

                case "divert":
                    var divertStitch = GetOrCreateStitch(story, (string)value);
                    stitch.DivertTo(divertStitch);
                    break;

                case "image":
                    stitch.Image = (string)value;
                    break;

                case "flagName":
                    stitch.Flags.Add((string)value);
                    break;

                case "ifCondition":
                    stitch.IfConditions.Add((string)value);
                    break;

                case "notIfCondition":
                    stitch.NotIfConditions.Add((string)value);
                    break;
                }
            }
        }
コード例 #12
0
        public bool HeaderWithinDistanceOfStitch(int distance, Stitch stitch)
        {
//			var n = [],
//			r = [];
//			n.push(t);
//			for (var i = 0; i <= e; i++) {
//				for (var s = 0; s < n.length; s++) {
//					var o = n[s];
//					if (o) {
//						if (o.pageNumberLabel() > 0) return !0;
//						r.push(o.divertStitch);
//						for (var u = 0; u < o.options.length; u++) r.push(o.options[u]._linkStitch)
//						}
//				}
//				n = r, r = []
//			}
//			return !1

            // FIXME
            return(false);
        }
コード例 #13
0
 public bool Equals(Stitch s)
 {
     return(s.Name == Name);
 }
コード例 #14
0
 public Option(Stitch parent) : this()
 {
     ParentStitch = parent;
 }
コード例 #15
0
        /// <summary>
        /// Modify the values in the given flags array based on the flags contained in the given stitch.
        /// </summary>
        public static void ProcessFlagSetting(Stitch stitch, List <FlagValue> allFlags)
        {
            for (int n = 0; n < stitch.Flags.Count; n++)
            {
                string flag     = stitch.FlagByIndex(n);
                int    newValue = 1;              // true

                var match = Regex.Match(flag, @"^(.*?)\s*(\=|\+|\-)\s*(\b.*\b)\s*$");

                int  flagIndex = -1;
                bool isBoolean = false;

                if (match.Success)
                {
                    flag      = match.Groups [1].Value;
                    flagIndex = GetIndexOfFlag(flag, allFlags);
                    var matchedOperator = match.Groups [2].Value;
                    var matchedValue    = match.Groups [3].Value;

                    bool isValueNumerical = Regex.IsMatch(matchedValue, @"\d+");
                    if (isValueNumerical)
                    {
                        // Handle numerical value
                        isBoolean = false;
                        if (matchedOperator == "=")
                        {
                            newValue = int.Parse(matchedValue);
                        }
                        else
                        {
                            newValue = (flagIndex < 0) ? 0 : allFlags [flagIndex].value;
                            if (matchedOperator == "+")
                            {
                                newValue += int.Parse(matchedValue);
                            }
                            else if (matchedOperator == "-")
                            {
                                newValue -= int.Parse(matchedValue);
                            }
                        }
                    }
                    else
                    {
                        // Handle boolean value
                        // Can't add or subtract a boolean, can only check equality
                        isBoolean = true;
                        if (matchedOperator == "=")
                        {
                            newValue = ConvertStringToBoolean(matchedValue) ? 1 : 0;
                        }
                    }
                }
                else
                {
                    flagIndex = GetIndexOfFlag(flag, allFlags);
                }

                // Update global flags
                var newFlag = isBoolean ? new FlagValue(flag, newValue == 1 ? true : false) : new FlagValue(flag, newValue);
                if (flagIndex >= 0)
                {
                    allFlags[flagIndex] = newFlag;
                }
                else
                {
                    allFlags.Add(newFlag);
                }
            }
        }
コード例 #16
0
 /// <summary>
 /// Removes an option from the given stitch.
 /// </summary>
 public void RemoveOption(Stitch stitch, Option option)
 {
     stitch.RemoveOption(option);
 }
コード例 #17
0
        /// <summary>
        /// Appends a new and empty Option to the given Stitch.
        /// </summary>
        public Option CreateOption(Stitch stitch)
        {
            var t = stitch.AddOption();

            return(t);
        }