예제 #1
0
        public void CreateFunction(string directory)
        {
            string filepath = directory + funcName + ".mcfunction";

            if (File.Exists(filepath))
            {
                throw new Exception("Function '" + funcName + "'s .mcfunction already exists!");
            }
            else
            {
                string alldo = "";
                // There is a load rule, and the load function is this function
                if (Ruling.hasLoad && IntoAST.maintodo.Exists(x => x is LoadFuncRuling lf && lf.function == funcName))
                {
                    // Begin with the initialization
                    alldo = Reserved.InitializeDeclarationString();
                }

                // Open the file to the function
                StreamWriter sw = File.CreateText(filepath);

                foreach (IChildFunctionDeclaration icdf in todo)
                {
                    alldo += icdf.GetLine() + "\n";
                }

                // Write to file as text
                sw.Write(alldo);

                sw.Close();

                {}
            }
        }
예제 #2
0
        // Apply each type
        public void CreateFiles(string masterDir)
        {
            if (maintodo == null || maintodo.Count == 0)
            {
                throw new Exception("Cannot create files; Nothing specified/compiled");
            }
            else
            {
                // If no name is ruled
                if (!Ruling.hasName)
                {
                    throw new Exception("Name ruling has to be made !");
                }

                // Made a load tag function
                bool madeLoadTagFunc = false;
                // Made a description
                bool madeDesc = false;

                foreach (IChildMainFile icmf in maintodo)
                {
                    if (icmf is FunctionDeclaration fd)
                    {
                        fd.CreateFunction(masterDir + "data\\" + IntoAST.nameSpace + "\\functions\\");
                    }
                    else if (icmf is DescriptionRuling dr)
                    {
                        StreamWriter sw = new StreamWriter(masterDir + "pack.mcmeta");
                        sw.Write("{\n\t\"pack\": {\n\t\t\"pack_format\": 5,\n\t\t\"description\":\"" + dr.description + "\"\n\t}\n}");
                        sw.Close();

                        madeDesc = true;
                    }
                    //else if (icmf is DatapackNameRuling dr)
                    // Nothing is done, name ruling is for all the function's namespace
                    //else if (icmf is VariableDeclaration vd)
                    //else if (icmf is DesigDeclaration dd)
                    // Nothing is done, taken care of in the load ruling or after all IChildMainFile is taken care of
                    else if (icmf is LoadFuncRuling lf)
                    {
                        // Create load tag
                        string initString = "{\n\t\"replace\":false,\n\t\"values\":\n\t[\n\t\t\"" + IntoAST.nameSpace + ":" + lf.function + "\"\n\t]\n}";

                        StreamWriter sw = File.CreateText(masterDir + "data\\minecraft\\tags\\functions\\load.json");

                        sw.Write(initString);

                        sw.Close();

                        // Has a load tagged function
                        madeLoadTagFunc = true;
                    }
                    else if (icmf is TickFuncRuling tf)
                    {
                        // Create tick tag
                        string initString = "{\n\t\"replace\":false,\n\t\"values\":\n\t[\n\t\t\"" + IntoAST.nameSpace + ":" + tf.function + "\"\n\t]\n}";

                        StreamWriter sw = File.CreateText(masterDir + "data\\minecraft\\tags\\functions\\tick.json");

                        sw.Write(initString);

                        sw.Close();
                    }
                }

                // If didn't make a load tag function
                if (!madeLoadTagFunc)
                {
                    // Get commands to initialize variables and desigs
                    string initString = Reserved.InitializeDeclarationString();

                    // Create load function initall.mcfunction
                    StreamWriter sw = File.CreateText(masterDir + "data\\" + IntoAST.nameSpace + "\\functions\\initall.mcfunction");

                    sw.Write(initString);

                    sw.Close();

                    // Create load tag
                    initString = "{\n\t\"replace\":false,\n\t\"values\":\n\t[\n\t\t\"" + IntoAST.nameSpace + ":initall\"\n\t]\n}";

                    sw = File.CreateText(masterDir + "data\\minecraft\\tags\\functions\\load.json");

                    sw.Write(initString);

                    sw.Close();
                }

                // If didn't make a description
                if (!madeDesc)
                {
                    StreamWriter sw = new StreamWriter(masterDir + "pack.mcmeta");
                    sw.Write("{\n\t\"pack\": {\n\t\t\"pack_format\": 5,\n\t\t\"description\":\"generated\"\n\t}\n}");
                    sw.Close();
                }
            }
        }