예제 #1
0
        public override LevelBlueprint Process(LevelPackage input, ContentProcessorContext context)
        {
            var parser = new LevelParser(input.Content, x => input.Includes.FirstOrDefault(p => LevelBlueprint.IsIncludeMatch(p.Key, x)).Value);

            var lf = parser.Parse();

            BlueprintPreprocessor.ProcessLevel(lf);

            Console.WriteLine("Parsing file with " + lf.BlueprintCannons.Count + " cannon definitions");
            Console.WriteLine("Parsing file with " + lf.BlueprintVoidWalls.Count + " voidwall definitions");

            return(lf);
        }
예제 #2
0
        public static LevelBlueprint ParseLevelFromString(string text, Func <string, string> includesFunc, bool sim)
        {
            var fp = new LevelParser(text, includesFunc);
            var lf = fp.Parse();

            LastParsedIncludedSources = fp.IncludedSources;

            if (sim)
            {
                BlueprintPreprocessor.ProcessLevel(lf);
            }

            return(lf);
        }
예제 #3
0
        public static LevelBlueprint ParseLevelFromFile(string path, bool sim)
        {
            var folder = Path.GetDirectoryName(path) ?? "";

            var includes = Directory.EnumerateFiles(folder, "*.gsheader").ToDictionary(p => Path.GetFileName(p) ?? p, p => File.ReadAllText(p, Encoding.UTF8));
            Func <string, string> includesFunc = x => includes.FirstOrDefault(p => LevelBlueprint.IsIncludeMatch(p.Key, x)).Value;

            var fp = new LevelParser(File.ReadAllText(path), includesFunc);
            var lf = fp.Parse(Path.GetFileName(path));

            LastParsedIncludedSources = fp.IncludedSources;

            if (sim)
            {
                BlueprintPreprocessor.ProcessLevel(lf);
            }

            return(lf);
        }
예제 #4
0
        public LevelBlueprint CompileToBlueprint(GameHUD hud)
        {
            var bp = new LevelBlueprint();

            bp.UniqueID    = Guid.Parse($"b16b00b5-0001-4001-0000-{OnlineID:000000000000}");
            bp.WrapMode    = (byte)Geometry;
            bp.LevelWidth  = Width * 64;
            bp.LevelHeight = Height * 64;
            bp.LevelViewX  = CalculateViewCenter().X;
            bp.LevelViewY  = CalculateViewCenter().Y;
            bp.Name        = "0-" + OnlineID;
            bp.FullName    = Name;
            bp.KIType      = GetKIType();
            bp.CustomMusic = Music;

            byte cannonID = 0;

            foreach (var e in Elements)
            {
                e.InsertIntoBlueprint(bp, ref cannonID);
            }

            try
            {
                bp.ValidOrThrow();

                BlueprintPreprocessor.ProcessLevel(bp);

                return(bp);
            }
            catch (Exception e)
            {
                MonoSAMGame.CurrentInst.DispatchBeginInvoke(() =>
                {
                    hud.ShowToast("SCCMLD::CTB_1", L10N.T(L10NImpl.STR_LVLED_ERR_COMPILERERR), 64, FlatColors.Flamingo, FlatColors.Foreground, 3f);
                    SAMLog.Error("SCMMLD_CTBERR", "LevelBlueprint compiled to invalid", $"Exception: {e}\n\n\nData: {SerializeToString()}");
                });
                return(null);
            }
        }