Пример #1
0
        public void TestLoad()
        {
            var mapScript = string.Join("\r\n", CoreSystemProvider.GetCoreSystemFiles().Select(file => $"do\r\n{File.ReadAllText(file)}\r\nend"));

            _vm.State.DoString(mapScript, "coresystem");

            const string identifier  = "System";
            var          systemTable = _vm.State.DoString($"return {identifier}").Single();

            Assert.IsTrue(systemTable != null);
        }
Пример #2
0
        private static void Main()
        {
            var stringProvider = new ExampleStringProvider();

            var mapInfo = MapInfo.Parse(FileProvider.GetFile(Path.Combine(stringProvider.BaseMapFilePath, MapInfo.FileName)));

            mapInfo.MapName            = stringProvider.MapName;
            mapInfo.MapDescription     = stringProvider.MapDescription;
            mapInfo.MapAuthor          = stringProvider.MapAuthor;
            mapInfo.RecommendedPlayers = stringProvider.RecommendedPlayers;

            mapInfo.MapFlags      &= ~MapFlags.MeleeMap;
            mapInfo.ScriptLanguage = ScriptLanguage.Lua;

            PlayerAndForceProperties.ApplyToMapInfo(mapInfo);

            var scriptCompilerOptions = new ScriptCompilerOptions(CoreSystemProvider.GetCoreSystemFiles().Append(@".\LuaLibs\PerlinNoise.lua"));

            scriptCompilerOptions.MapInfo         = mapInfo;
            scriptCompilerOptions.LobbyMusic      = stringProvider.LobbyMusic;
            scriptCompilerOptions.SourceDirectory = stringProvider.SourceProjectPath;
            scriptCompilerOptions.OutputDirectory = stringProvider.OutputDirectoryPath;

            // Note: do not use MpqFileFlags.SingleUnit, as it appears to be bugged.
            scriptCompilerOptions.DefaultFileFlags         = MpqFileFlags.Exists | MpqFileFlags.CompressedMulti;
            scriptCompilerOptions.FileFlags["war3map.wtg"] = 0;
            scriptCompilerOptions.FileFlags[mapInfo.ScriptLanguage == ScriptLanguage.Jass ? "war3map.lua" : "war3map.j"] = 0;
            scriptCompilerOptions.FileFlags[ListFile.Key] = MpqFileFlags.Exists | MpqFileFlags.Encrypted | MpqFileFlags.BlockOffsetAdjustedKey;
#if DEBUG
            scriptCompilerOptions.Debug = true;
#endif

            // Build and launch
            var mapName    = stringProvider.MapFileName;
            var mapBuilder = new MapBuilder(mapName);

            if (mapBuilder.Build(scriptCompilerOptions, stringProvider.AssetsDirectoryPath, stringProvider.BaseMapFilePath))
            {
                var mapPath         = Path.Combine(scriptCompilerOptions.OutputDirectory, mapName);
                var absoluteMapPath = new FileInfo(mapPath).FullName;
                Process.Start(stringProvider.Warcraft3ExecutablePath, $"{stringProvider.CommandLineArguments} -loadfile \"{absoluteMapPath}\"");
            }
        }