Esempio n. 1
0
        /// <summary>
        /// Parses a .muffin file and puts it into a MuffinDefinition
        /// </summary>
        /// <param name="nameOfMuffin">The name of the muffin to load. This will be used as a filename</param>
        /// <param name="worldDef">
        /// If you've already got a muffin definition, pass it here and this method will add to it
        /// instead of making a new one.
        /// </param>
        /// <returns>A muffin definition with the stuff from the specified muffin file.</returns>
        public MuffinDefinition ParseByName(string nameOfMuffin, MuffinDefinition worldDef = null)
        {
            // the initial level before we start loading one is "null", so we need to avoid doing anything with that.
            if (nameOfMuffin == null) {
                MuffinDefinition emptyDef = new MuffinDefinition(string.Empty);
                emptyDef.EnumTokens["type"] = ThingEnum.EmptyLevel;
                emptyDef.Finish();
                return emptyDef;
            }

            // make the file path
            string filePath = Settings.Default.MuffinFileLocation + nameOfMuffin + Settings.Default.MuffinFileExtension;
            // if the muffin file was not found
            if (!File.Exists(filePath)) {
                throw new ArgumentException(nameOfMuffin + ".muffin not found!", "nameOfMuffin");
            }

            return ParseByFile(filePath, worldDef);
        }
Esempio n. 2
0
        /// <summary>
        /// Parses a .muffin file and puts it into a MuffinDefinition
        /// </summary>
        /// <param name="filePath">The filepath of the muffin to load.</param>
        /// <param name="worldDef">
        /// If you've already got a muffin definition, pass it here and this method will add to it
        /// instead of making a new one.
        /// </param>
        /// <returns>A muffin definition with the stuff from the specified muffin file.</returns>
        public MuffinDefinition ParseByFile(string filePath, MuffinDefinition worldDef = null)
        {
            string fileContents = string.Empty;

            if (LogManager.Singleton != null)
                LogManager.Singleton.LogMessage("[MuffinImporter] Importing and parsing world: " + filePath);
            Debug.WriteLine("[MuffinImporter] Importing and parsing world: " + filePath);

            // read stuff
            using (var fileStream = File.Open(filePath, FileMode.Open)) {
                using (var reader = new StreamReader(fileStream)) {
                    // for each line in the file
                    while (!reader.EndOfStream) {
                        fileContents += reader.ReadLine() + Environment.NewLine;
                    }
                    reader.Close();
                }
                fileStream.Close();
            }

            extraFiles = new Collection<string>();

            Parser p = new Parser();
            root = p.Parse(fileContents);

            if (worldDef == null)
                worldDef = new MuffinDefinition(filePath);

            Parse(worldDef);

            foreach (var file in extraFiles) {
                worldDef.ExtraFiles.Add(file);
            }

            worldDef.Finish();

            return worldDef;
        }
Esempio n. 3
0
        /// <summary>
        /// Shape blocks
        /// </summary>
        void ParseBlock(MuffinDefinition worldDef, RuleInstance block)
        {
            Token nameTok = (block.Children[0] as RuleInstance).Children[0] as Token;

            ThingBlock thingBlock = new ThingBlock(nameTok.Image, worldDef);

            for (int a = 2; a < block.Children.Length - 1; a++) {
                RuleInstance rule = block.Children[a] as RuleInstance;
                if (rule.Type == NodeType.Rule_Property)
                    ParseProperty(thingBlock, rule.Children[0] as RuleInstance);
            }
            worldDef.ThingBlocks.Add(thingBlock);
        }
Esempio n. 4
0
 /// <summary>
 /// Parses right from the root
 /// </summary>
 void Parse(MuffinDefinition worldDef)
 {
     for (int a = 0; a < root.Children.Length; a++) {
         Node prop = root.Children[a];
         switch (prop.Type) {
             case NodeType.Rule_Property:
                 ParseProperty(worldDef, (prop as RuleInstance).Children[0] as RuleInstance);
                 break;
             case NodeType.Rule_Block:
                 ParseBlock(worldDef, prop as RuleInstance);
                 break;
         }
     }
 }
Esempio n. 5
0
 public ThingBlock(string thingName, MuffinDefinition owner)
 {
     ThingName = thingName;
     Owner = owner;
     SetUpDictionaries();
 }
Esempio n. 6
0
        private void importButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".muffin";
            dlg.Filter = "Lymph Muffin files|*.muffin";

            bool? result = dlg.ShowDialog();

            if (result == true) {
                originalFilename = dlg.FileName;

                definition = new MuffinImporter().ParseByFile(dlg.FileName);

                MessageBox.Show("Import successful!", originalFilename, MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }