Exemplo n.º 1
0
    public static void ConvertAllMaps(string toeeDir)
    {
        using var game = HeadlessGame.Start(new HeadlessGameOptions(toeeDir));

        var mapList = MapListParser.Parse(Tig.FS);

        foreach (var(mapId, mapEntry) in mapList)
        {
            Console.WriteLine($"Converting {mapId} ({mapEntry.name})");
            ConvertMap(mapEntry);
        }
    }
Exemplo n.º 2
0
    public static void ConvertMap(string toeeDir, int mapId)
    {
        using var game = HeadlessGame.Start(new HeadlessGameOptions(toeeDir));
        var mapList = MapListParser.Parse(Tig.FS);

        if (!mapList.TryGetValue(mapId, out var mapEntry))
        {
            Console.WriteLine("Unknown map: " + mapId);
            return;
        }

        ConvertMap(mapEntry);
    }
    internal static void Convert(string toeeDir)
    {
        using var game = HeadlessGame.Start(new HeadlessGameOptions(toeeDir));

        Directory.CreateDirectory("protos");

        var properties = new Dictionary <obj_f, object>();

        foreach (var protosFile in ProtoFileParser.EnumerateProtoFiles(Tig.FS))
        {
            var protos = ProtoFileParser.Parse(protosFile);

            foreach (var proto in protos)
            {
                var dir = Path.Join("protos", proto.type.ToString());
                Directory.CreateDirectory(dir);

                var file        = Path.Join(dir, proto.id.protoId + ".json");
                var displayName = GameSystems.MapObject.GetDisplayName(proto);

                properties.Clear();
                proto.ForEachField((field, value) =>
                {
                    // ForEachField will return ALL fields for a proto, unset fields will be null
                    if (value != null)
                    {
                        properties[field] = value;
                    }
                    return(true);
                });

                using var stream = new FileStream(file, FileMode.Create);
                using var writer = new Utf8JsonWriter(stream, new JsonWriterOptions
                {
                    Indented = true
                });

                writer.WriteStartObject();
                writer.WriteString("$comment", displayName);
                writer.WriteString("type", proto.type.ToString());
                writer.WriteNumber("id", proto.id.protoId);
                ObjectSerializer.WriteProperties(writer, properties, $"Proto for '{displayName}' ({proto.type})");
                writer.WriteEndObject();
            }
        }
    }