示例#1
0
    private static string getFlags(Thing thing)
    {
      var flags = new StringBuilder("TAKEBIT");

      if (thing.DisplayName.StartsWithVowel())
      {
        flags.Append(" VOWELBIT");
      }

      if (thing.Contents.Any())
      {
        flags.Append(" CONTBIT");
      }

      return flags.ToString();
    }
示例#2
0
        private void ExportThings(TextWriter writer, List<Thing> things, Thing container, int indent)
        {
            foreach (var thing in things)
              {
            if (thing.Container != container)
            {
              // match only the container we're given, or lack thereof
              continue;
            }

            writer.WriteLine("Object {0} {1} {2}", repeat("-> ", indent), thing.ExportName, toI6String(stripOddCharacters(thing.DisplayName, ' ', '-').Trim(), DOUBLE_QUOTE));
            writer.Write("  with  name {0}", toI6Words(stripOddCharacters(thing.DisplayName, ' ', '-')));
            if (thing.Contents.Count > 0)
            {
              writer.WriteLine(",");
              writer.WriteLine("   has open container;");
            }
            else
            {
              writer.WriteLine(";");
            }
            writer.WriteLine();

            ExportThings(writer, thing.Contents, thing, indent + 1);
              }
        }
示例#3
0
    private static void exportThings(TextWriter writer, List<Thing> things, Thing container, int indent)
    {
      foreach (var thing in things.Where(p=>p.Container == container))
      {
        writer.WriteLine();
        writer.WriteLine($"<OBJECT {thing.ExportName}");

        if (thing.Container == null)
          writer.WriteLine($"    (IN {thing.Location.ExportName})");
        else
          writer.WriteLine($"    (IN {thing.Container.ExportName})");

        writer.WriteLine($"    (DESC {toZILString(thing.DisplayName)})");

        var words = getObjectWords(thing);
        if (words.Count > 0) {
          writer.WriteLine($"    (SYNONYM {words[words.Count - 1]})");
        }
        if (words.Count > 1) {
          writer.WriteLine($"    (ADJECTIVE {Join($"{SPACE}", words.Take(words.Count - 1))})");
        }

        writer.WriteLine($"    (FLAGS {getFlags(thing)})>");
        writer.WriteLine();

        if (thing.Contents.Any())
          exportThings(writer,thing.Contents,thing,indent++);
      }
    }
示例#4
0
    private static IList<string> getObjectWords(Thing thing)
    {
      string synonyms = Empty;
      var list = new List<string>();

      var words = thing.DisplayName.Split(' ').ToList();

      words.ForEach(p=>list.Add(stripOddCharacters(p).ToUpper()));

      return list;
    }
示例#5
0
 public Thing(string displayName, string exportName, Location location, Thing container, int indent)
 {
     DisplayName = displayName;
     ExportName = exportName;
     Location = location;
     Container = container;
     Debug.Assert(container == null || container.Location == location, "Thing's container is not located in the same room as the thing.");
     container?.Contents.Add(this);
     Indent = indent;
     Contents = new List<Thing>();
 }
示例#6
0
        private void findThings()
        {
            var mapExportNameToThing = new Dictionary<string, Thing>(StringComparer.InvariantCultureIgnoreCase);

              // prevent use of reserved words
              foreach (var reservedWord in ReservedWords)
              {
            mapExportNameToThing.Add(reservedWord, null);
              }

              foreach (var rooms in LocationsInExportOrder)
              {
            mapExportNameToThing.Add(rooms.ExportName, null);
              }

              foreach (var region in RegionsInExportOrder)
              {
            mapExportNameToThing.Add(region.ExportName, null);
              }

              foreach (var location in LocationsInExportOrder)
              {
            var objectsText = location.Room.Objects;
            if (string.IsNullOrEmpty(objectsText))
            {
              continue;
            }

            var objectNames = objectsText.Replace("\r", string.Empty).Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
            foreach (var objectName in objectNames)
            {
              // the display name is simply the object name without indentation
              var displayName = objectName.Trim();

              if (string.IsNullOrEmpty(displayName))
              {
            continue;
              }

              // assign each thing a unique export name.
              var exportName = GetExportName(displayName, null);
              var index = 2;
              while (mapExportNameToThing.ContainsKey(exportName))
              {
            exportName = GetExportName(displayName, index++);
              }

              // on each line, indentation denotes containment;
              // work out how much indentation there is
              var indent = 0;
              while (indent < objectName.Length && objectName[indent] == ' ')
              {
            ++indent;
              }

              // compare indentations to deduce containment
              Thing container = null;
              for (var thingIndex = location.Things.Count - 1; thingIndex >= 0; --thingIndex)
              {
            var priorThing = location.Things[thingIndex];
            if (indent > priorThing.Indent)
            {
              container = priorThing;
              break;
            }
              }

              var thing = new Thing(displayName, exportName, location, container, indent);
              mapExportNameToThing.Add(exportName, thing);
              location.Things.Add(thing);
            }
              }
        }
示例#7
0
        private void ExportThings(StreamWriter writer, List<Thing> things, Thing container, int indent)
        {
            foreach (var thing in things)
            {
                if (thing.Container != container)
                {
                    // match only the container we're given, or lack thereof
                    continue;
                }

                writer.WriteLine("{0} {1}: {3} {2} {2}", Repeat('+', indent), thing.ExportName, ToTadsString(StripOddCharacters(thing.DisplayName, ' ', '-').Trim(), SingleQuote), thing.Contents.Count > 0 ? "Container" : "Thing");
                writer.WriteLine(";");
                writer.WriteLine();

                ExportThings(writer, thing.Contents, thing, indent + 1);
            }
        }
示例#8
0
        private static void exportThings(TextWriter writer, List<Thing> things, Thing container, int indent)
        {
            foreach (var thing in things.Where(thing => thing.Container == container)) {
                writer.WriteLine("object {0}", thing.ExportName);
                writer.WriteLine("{");
                writer.WriteLine("\tin {0}", thing.Location.ExportName);
                writer.WriteLine("}");
                writer.WriteLine();

                exportThings(writer, thing.Contents, thing, indent + 1);
              }
        }
示例#9
0
        private static void exportThings(TextWriter writer, List<Thing> things, Thing container, int indent)
        {
            foreach (var thing in things.Where(thing => thing.Container == container)) {
            writer.WriteLine("{0} {1}: {3} {2} {2}", repeat('+', indent), thing.ExportName, toTadsString(stripOddCharacters(thing.DisplayName, ' ', '-').Trim(), SINGLE_QUOTE), thing.Contents.Count > 0 ? "Container" : "Thing");
            writer.WriteLine(";");
            writer.WriteLine();

            exportThings(writer, thing.Contents, thing, indent + 1);
              }
        }