コード例 #1
0
ファイル: Program.cs プロジェクト: sungaila/uebersetzerbauSWP
        public static CodeGen.ZStoryFile GenStoryFile(Tree tree)
        {
            Logger.LogUserOutput("Create story file ...");
            CodeGen.ZStoryFile storyFile = new CodeGen.ZStoryFile();

            Logger.LogUserOutput("Add instructions to story file ...");
            storyFile.ImportObjectTree(tree);

            return storyFile;
        }
コード例 #2
0
 public TreeValidator(Tree tree)
 {
     _tree = tree;
 }
コード例 #3
0
        public void ImportObjectTree(Tree tree)
        {
            _symbolTable = new ZSymbolTable();
            _routineTable = new ZRoutineTable();

            Passage startPassage = null;
            IEnumerable<Passage> passages = null;
            try
            {
                _passages = tree.Passages.Select(entry => entry.Value);
                startPassage = tree.StartPassage;
                passages = tree.Passages.Where(passage => passage.Key.ToLower() != "start" &&
                                               passage.Key.ToLower() != "storyauthor" &&
                                               passage.Key.ToLower() != "storytitle").Select(entry => entry.Value);
            }
            catch (Exception ex)
            {
                throw new Exception("Start passage not found.", ex);
            }

            string storyTitle = tree.StoryTitle.PassageContentList.First().PassageText.Text.Trim();
            string storyAuthor = tree.StoryAuthor.PassageContentList.First().PassageText.Text.Trim();

            List<ZRoutine> routines = new List<ZRoutine>();

            routines.Add(new ZRoutine(new ZInstruction[] {
                new Store (_symbolTable.GetSymbol("%turns%"), -1), // sets the turns counter to -1
                new Store(_symbolTable.GetSymbol("%previous%"), _routineTable.GetRoutine(startPassage.Name)),
                new Call1n(new ZRoutineLabel(startPassage.Name))
            }) { Label = new ZRoutineLabel("main") });

            try
            {
                _routineTable.AddRoutine(startPassage.Name);
                routines.Add(ConvertPassageToRoutine(startPassage, storyTitle, storyAuthor));

                foreach (Passage passage in passages)
                {
                    _routineTable.AddRoutine(passage.Name);
                    routines.Add(ConvertPassageToRoutine(passage, storyTitle, storyAuthor));
                }

                List<ZInstruction> instructions = new List<ZInstruction>();
                ZLocalVariable local = new ZLocalVariable(0);
                instructions.Add(new Store(local, _symbolTable.GetSymbol("%previous%")));
                instructions.Add(new Store(_symbolTable.GetSymbol("%previous%"), _symbolTable.GetSymbol("%nextprevious%")));

                foreach (var keyValuePair in _routineTable._routines)
                {
                    Guid nextCheck = Guid.NewGuid();
                    instructions.Add(new Je(local, keyValuePair.Value, new ZBranchLabel(nextCheck.ToString()) { BranchOn = false }));
                    instructions.Add(new Call1n(new ZRoutineLabel(keyValuePair.Key)));
                    instructions.Add(new Nop() { Label = new ZLabel(nextCheck.ToString()) });
                }

                instructions.Add(new Print("(ERROR) The given routine id "));
                instructions.Add(new PrintNum(local));
                instructions.Add(new Print(" has not been found. Terminating game." + System.Environment.NewLine));
                instructions.Add(new Quit());
                routines.Add(new ZRoutine(instructions, 1) { Label = new ZRoutineLabel("routineCallTable") });
            }
            catch (Exception ex)
            {
                Twee2Z.Utils.Logger.LogError("Could not convert passage into routine.");
                Twee2Z.Utils.Logger.LogError(ex.Message);
                throw ex;
            }

            _zMemory.SetRoutines(routines);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: sungaila/uebersetzerbauSWP
 public static bool ValidateTree(Tree tree)
 {
     TreeValidator validator = new TreeValidator(tree);
     return validator.ValidateTree();
 }
コード例 #5
0
 public TweeBuilder()
 {
     _tree = new Tree();
 }