Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using WTF.DeckFileFormat;
- using WTF.DeckFileFormat.Metadata;
- var metadata = new DeckMetadata
- {
- Name = "Example Deck",
- Description = "This is an example deck for demonstration purposes.",
- Version = 1,
- LastChanged = DateTime.Now,
- UserDeck = true
- };
- var cards = new Dictionary<Guid, CardMetadata>
- {
- {
- Guid.NewGuid(),
- new CardMetadata
- {
- Uuid = Guid.NewGuid(),
- Question = "What is the capital of France?",
- Answer = "Paris",
- MaterialId = 0
- }
- },
- {
- Guid.NewGuid(),
- new CardMetadata
- {
- Uuid = Guid.NewGuid(),
- Question = "What is 2 + 2?",
- Answer = "4",
- MaterialId = 1
- }
- }
- };
- var materials = new Dictionary<ushort, string>
- {
- {
- 0,
- "Plaster"
- },
- {
- 1,
- "Rubber"
- }
- };
- var buildings = new Dictionary<ushort, string>
- {
- {
- 0,
- "The Royal Palace, England"
- },
- {
- 1,
- "The Effle Tower, France"
- },
- {
- 2,
- "Bean, Chicago, USA"
- }
- };
- var file = new DeckFileFormat
- {
- Metadata = metadata,
- Cards = cards,
- Materials = materials,
- Buildings = buildings
- };
- byte[] content = file.Generate(true);
- // Save to file
- Console.WriteLine("Saved to output.txt");
- using var writer = new FileStream("output.txt", FileMode.Create, FileAccess.Write);
- writer.Write(content, 0, content.Length);
- writer.Close();
- // Load from buffer
- Console.WriteLine("Loading from buffer");
- DeckFileFormat loadedFile = DeckFileFormat.From(content, true);
- Console.WriteLine("Metadata:");
- Console.WriteLine(loadedFile.Metadata.Name);
- Console.WriteLine(loadedFile.Metadata.Description);
- Console.WriteLine(loadedFile.Metadata.Version);
- Console.WriteLine(loadedFile.Metadata.LastChanged);
- Console.WriteLine(loadedFile.Metadata.UserDeck);
- Console.WriteLine("Cards:");
- foreach (var cardKv in loadedFile.Cards)
- {
- Console.WriteLine(cardKv.Value.Question);
- Console.WriteLine(cardKv.Value.Answer);
- Console.WriteLine(cardKv.Value.MaterialId);
- }
- Console.WriteLine("Materials:");
- foreach (var materialKv in loadedFile.Materials)
- {
- Console.WriteLine(materialKv.Key);
- Console.WriteLine(materialKv.Value);
- }
- Console.WriteLine("Buildings:");
- foreach (var buildingKv in loadedFile.Buildings)
- {
- Console.WriteLine(buildingKv.Key);
- Console.WriteLine(buildingKv.Value);
- }
- // Wait for user input before exiting
- Console.WriteLine("Press any key to exit...");
- Console.ReadKey();
Advertisement
Add Comment
Please, Sign In to add comment