public override void LoadFrom(YamlMappingNode mapping) { base.LoadFrom(mapping); var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(this, x => x.ActionType, "actionType", ActionType.Error); if (ActionType == ActionType.Error) { Logger.ErrorS("action", "missing or invalid actionType for action with name {0}", Name); } // TODO: Split this class into server/client after RobustToolbox#1405 if (IoCManager.Resolve <IModuleManager>().IsClientModule) { return; } IActionBehavior behavior = null; serializer.DataField(ref behavior, "behavior", null); switch (behavior) { case null: BehaviorType = BehaviorType.None; Logger.ErrorS("action", "missing or invalid behavior for action with name {0}", Name); break; case IInstantAction instantAction: ValidateBehaviorType(BehaviorType.Instant, typeof(IInstantAction)); BehaviorType = BehaviorType.Instant; InstantAction = instantAction; break; case IToggleAction toggleAction: ValidateBehaviorType(BehaviorType.Toggle, typeof(IToggleAction)); BehaviorType = BehaviorType.Toggle; ToggleAction = toggleAction; break; case ITargetEntityAction targetEntity: ValidateBehaviorType(BehaviorType.TargetEntity, typeof(ITargetEntityAction)); BehaviorType = BehaviorType.TargetEntity; TargetEntityAction = targetEntity; break; case ITargetPointAction targetPointAction: ValidateBehaviorType(BehaviorType.TargetPoint, typeof(ITargetPointAction)); BehaviorType = BehaviorType.TargetPoint; TargetPointAction = targetPointAction; break; default: BehaviorType = BehaviorType.None; Logger.ErrorS("action", "unrecognized behavior type for action with name {0}", Name); break; } }
void ISerializationHooks.AfterDeserialization() { base.AfterDeserialization(); if (ActionType == ActionType.Error) { Logger.ErrorS("action", "missing or invalid actionType for action with name {0}", Name); } if (IoCManager.Resolve <IModuleManager>().IsClientModule) { return; } switch (Behavior) { case null: BehaviorType = BehaviorType.None; Logger.ErrorS("action", "missing or invalid behavior for action with name {0}", Name); break; case IInstantAction instantAction: ValidateBehaviorType(BehaviorType.Instant, typeof(IInstantAction)); BehaviorType = BehaviorType.Instant; InstantAction = instantAction; break; case IToggleAction toggleAction: ValidateBehaviorType(BehaviorType.Toggle, typeof(IToggleAction)); BehaviorType = BehaviorType.Toggle; ToggleAction = toggleAction; break; case ITargetEntityAction targetEntity: ValidateBehaviorType(BehaviorType.TargetEntity, typeof(ITargetEntityAction)); BehaviorType = BehaviorType.TargetEntity; TargetEntityAction = targetEntity; break; case ITargetPointAction targetPointAction: ValidateBehaviorType(BehaviorType.TargetPoint, typeof(ITargetPointAction)); BehaviorType = BehaviorType.TargetPoint; TargetPointAction = targetPointAction; break; default: BehaviorType = BehaviorType.None; Logger.ErrorS("action", "unrecognized behavior type for action with name {0}", Name); break; } }