darraghd493

NEA Third & Fourth Test Program

Jul 16th, 2025
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | Source Code | 0 0
  1. using WTF.DeckFileFormat;
  2. using WTF.DeckFileFormat.Metadata;
  3.  
  4. var metadata = new DeckMetadata
  5. {
  6.     Name = "Example Deck",
  7.     Description = "This is an example deck for demonstration purposes.",
  8.     Version = 1,
  9.     LastChanged = DateTime.Now,
  10.     UserDeck = true
  11. };
  12.  
  13. var cards = new Dictionary<Guid, CardMetadata>
  14. {
  15.     {
  16.         Guid.NewGuid(),
  17.         new CardMetadata
  18.         {
  19.             Uuid = Guid.NewGuid(),
  20.             Question = "What is the capital of France?",
  21.             Answer = "Paris",
  22.             MaterialId = 0
  23.         }
  24.     },
  25.     {
  26.         Guid.NewGuid(),
  27.         new CardMetadata
  28.         {
  29.             Uuid = Guid.NewGuid(),
  30.             Question = "What is 2 + 2?",
  31.             Answer = "4",
  32.             MaterialId = 1
  33.         }
  34.     }
  35. };
  36.  
  37. var materials = new Dictionary<ushort, string>
  38. {
  39.     {
  40.         0,
  41.         "Plaster"
  42.     },
  43.     {
  44.         1,
  45.         "Rubber"
  46.     }
  47. };
  48.  
  49. var buildings = new Dictionary<ushort, string>
  50. {
  51.     {
  52.         0,
  53.         "The Royal Palace, England"
  54.     },
  55.     {
  56.         1,
  57.         "The Effle Tower, France"
  58.     },
  59.     {
  60.         2,
  61.         "Bean, Chicago, USA"
  62.     }
  63. };
  64.  
  65. var file = new DeckFileFormat
  66. {
  67.     Metadata = metadata,
  68.     Cards = cards,
  69.     Materials = materials,
  70.     Buildings = buildings
  71. };
  72.  
  73. byte[] content = file.Generate(true);
  74.  
  75. // Save to file
  76. Console.WriteLine("Saved to output.txt");
  77. using var writer = new FileStream("output.txt", FileMode.Create, FileAccess.Write);
  78. writer.Write(content, 0, content.Length);
  79. writer.Close();
  80.  
  81. // Load from buffer
  82. Console.WriteLine("Loading from buffer");
  83. DeckFileFormat loadedFile = DeckFileFormat.From(content, true);
  84.  
  85. Console.WriteLine("Metadata:");
  86. Console.WriteLine(loadedFile.Metadata.Name);
  87. Console.WriteLine(loadedFile.Metadata.Description);
  88. Console.WriteLine(loadedFile.Metadata.Version);
  89. Console.WriteLine(loadedFile.Metadata.LastChanged);
  90. Console.WriteLine(loadedFile.Metadata.UserDeck);
  91.  
  92. Console.WriteLine("Cards:");
  93. foreach (var cardKv in loadedFile.Cards)
  94. {
  95.     Console.WriteLine(cardKv.Value.Question);
  96.     Console.WriteLine(cardKv.Value.Answer);
  97.     Console.WriteLine(cardKv.Value.MaterialId);
  98. }
  99.  
  100. Console.WriteLine("Materials:");
  101. foreach (var materialKv in loadedFile.Materials)
  102. {
  103.     Console.WriteLine(materialKv.Key);
  104.     Console.WriteLine(materialKv.Value);
  105. }
  106.  
  107. Console.WriteLine("Buildings:");
  108. foreach (var buildingKv in loadedFile.Buildings)
  109. {
  110.     Console.WriteLine(buildingKv.Key);
  111.     Console.WriteLine(buildingKv.Value);
  112. }
  113.  
  114. // Wait for user input before exiting
  115. Console.WriteLine("Press any key to exit...");
  116. Console.ReadKey();
Advertisement
Add Comment
Please, Sign In to add comment