// This file is part of the Noddybox.Emulation C# suite. // // Noddybox.Emulation is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Noddybox.Emulation is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Noddybox.Emulation. If not, see . // // Copyright (c) 2012 Ian Cowburn // using System; using System.IO; using System.Collections.Generic; namespace Noddybox.Emulation.Keyboard.Schema { /// /// Provides the schema for the keyboard definition. /// public class KeyboardDefinition { #region Version private const string magic = "KEYBDEF1.0"; #endregion #region Properties /// /// Get the list of keyboard key defintiions. /// public List Definitions {get; private set;} #endregion #region Load/Save /// /// Save this keybaord definition to the stream. /// /// The stream to write to. public void Save(BinaryWriter stream) { stream.Write(magic); stream.Write(Definitions.Count); foreach (KeyboardKey k in Definitions) { k.Save(stream); } } /// /// Load a keyboard definition from the passed stream. /// /// The stream to read from. /// The KeyboardDefinition object. public static KeyboardDefinition Load(BinaryReader stream) { if (stream.ReadString() != magic) { throw new ArgumentException("Stream has wrong magic"); } KeyboardDefinition keyboard = new KeyboardDefinition(); int count = stream.ReadInt32(); for(int f = 0; f < count ; f++) { keyboard.Definitions.Add(KeyboardKey.Load(stream)); } return keyboard; } #endregion #region Constructors public KeyboardDefinition() { Definitions = new List(); } #endregion } }