示例#1
0
        public void Resolve(Tank tank)
        {
            if (!_isResolved)
            {
                switch (_tankObjectType)
                {
                case "vehicle":
                    _tankObject = tank.GetTankObject <Tank>(this._key);
                    break;

                case "chassis":
                    _tankObject = tank.GetTankObject <Chassis>(this._key);
                    break;

                case "gun":
                    _tankObject = tank.GetTankObject <Gun>(this._key);
                    break;

                case "engine":
                    _tankObject = tank.GetTankObject <Engine>(this._key);
                    break;

                case "radio":
                    _tankObject = tank.GetTankObject <Radio>(this._key);
                    break;

                case "turret":
                    _tankObject = tank.GetTankObject <Turret>(this._key);
                    break;

                default:
                    throw new NotSupportedException();
                }

                _isResolved = true;
            }
        }
示例#2
0
        internal TModule DeserializeModules <TModule>(XmlReader reader, Dictionary <string, TModule> storage, Func <TModule> factory, TankObject owner = null)
            where TModule : Module, ICloneable
        {
            var sharedModules = this.Nation.GetSharedObjects <TModule>();

            TModule firstModule = null;

            while (reader.IsStartElement())
            {
                if (sharedModules.TryGetValue(reader.Name, out TModule module))
                {
                    module = (TModule)module.Clone();
                }
                else
                {
                    module = factory();
                }

                module.Owner = owner == null ? this : owner;

                module.Deserialize(reader);

                if (firstModule == null)
                {
                    firstModule = module;
                }

                storage.Add(module.Key, module);
                this.Nation.RegisterModule(module);
            }

            return(firstModule);
        }