// // This file is part of the Tremble package by Tiny Goose. // Copyright (c) 2024-2026 TinyGoose Ltd., All Rights Reserved. // using System.IO; namespace TinyGoose.Tremble { public static class EntityEnumWriter { public static void WriteCSharp(this EnumDefinition enumDefinition, string file, string namespaceOrNull) { using FileStream classFile = new(file, FileMode.Create, FileAccess.Write); using StreamWriter writer = new(classFile); writer.WriteLine($"// Enum '{enumDefinition.Name}'"); writer.WriteLine($"// Generated by Tremble v{TrembleConsts.VERSION_STRING}"); writer.WriteLine(); writer.WriteLine("using UnityEngine;"); writer.WriteLine("using TinyGoose.Tremble;"); writer.WriteLine(); bool hasNamespace = !namespaceOrNull.IsNullOrEmpty(); if (hasNamespace) { writer.WriteLine($"namespace {namespaceOrNull}"); writer.WriteLine("{"); } if (hasNamespace) { writer.Write("\t"); } writer.WriteLine($"public enum {enumDefinition.Name}"); if (hasNamespace) { writer.Write("\t"); } writer.WriteLine("{"); for (int i = 0; i < enumDefinition.Values.Length; i++) { string value = enumDefinition.Values[i]; writer.Write("\t"); if (hasNamespace) { writer.Write("\t"); } writer.WriteLine($"{value} = {i},"); } if (hasNamespace) { writer.Write("\t"); } writer.WriteLine("}"); if (hasNamespace) { writer.WriteLine("}"); } } } }