override public void checkAndUpdateDependences(List <Trait> previouslyBoundVars, StoryData world) { base.checkAndUpdateDependences(previouslyBoundVars, world); //Additionally, check that trait names exist in the class of object that this is constrained on //Check to make sure all trait or relationships exist on the object to be edited List <Trait> traitListToCompare = new List <Trait>(); PlotFragment parentFrag = world.findPlotFragmentById(_parentPlotFragmentId); if (_matchingEntityTypeId == world.CharTypeId) { if (world.Characters.Count > 0) { traitListToCompare = world.Characters[0].Traits; } } else if (_matchingEntityTypeId == world.EnvTypeId) { if (world.Environments.Count > 0) { traitListToCompare = world.Environments[0].Traits; } } else { PlotPointType currType = world.findPlotPointTypeById(_matchingEntityTypeId); if (currType != null) { traitListToCompare = currType.Traits; } else { throw new Exception("A Trait constraint within a precondition statement within Plot Fragment \"" + parentFrag.Name + "\" refers to a Plot Point type that no longer exists."); } } //look for trait we are editing if (null == Utilities.findTraitByNameAndType(traitListToCompare, _comparisonValue.Name, _comparisonValue.Type)) { throw new Exception("A Trait constraint within a precondition statement within Plot Fragment \"" + parentFrag.Name + "\" refers to a trait with name \"" + _comparisonValue.Name + "\" and type \"" + Trait.TraitDataTypeToString(_comparisonValue.Type) + "\" that no longer exists."); } }
override public void checkAndUpdateDependences(List <Trait> previouslyBoundVars, StoryData world) { PlotFragment parentFrag = world.findPlotFragmentById(_parentPlotFragmentId); if (parentFrag == null) { throw new Exception("Delete Object Action not have parent Plot Fragment"); } //check for variables bound to object references List <string> names = null; string objectTypeString = ""; if (_varObjectTypeId == world.CharTypeId) { names = parentFrag.getPreviouslyBoundCharacterVarNames(this); objectTypeString = "Character"; } else if (_varObjectTypeId == world.EnvTypeId) { names = parentFrag.getPreviouslyBoundEnvironmentVarNames(this); objectTypeString = "Environment"; } else { PlotPointType currType = world.findPlotPointTypeById(_varObjectTypeId); if (currType != null) { names = parentFrag.getPreviouslyBoundPlotPointTypeVarNames(currType, this); objectTypeString = currType.Description; } else { throw new Exception("Edit Plot Point Action in Plot Fragment \"" + parentFrag.Name + "\" " + "uses a Plot Point Type which no longer exists."); } } if (!(names.Contains(_varObjectName))) { throw new Exception("Edit Object Action in Plot Fragment \"" + parentFrag.Name + "\" refers to saved " + objectTypeString + " \"" + _varObjectName + "\", \nwhich has a different type or does not exist in any previous Author Goal parameters, precondition statements, or actions ."); } //make sure variable for relationship target edit exists if ((_mode == ObjectEditingMode.RelationshipTarget) && !(names.Contains((string)_newTarget.LiteralValueOrBoundVarName))) { throw new Exception("Edit Object Action in Plot Fragment \"" + parentFrag.Name + "\" refers to saved " + objectTypeString + " \"" + (string)_newTarget.LiteralValueOrBoundVarName + "\", \nwhich has a different type or does not exist in any previous Author Goal parameters, precondition statements, or actions ."); } //Check for bound primitive variables when saving trait or relationship strength if ( ((_mode == ObjectEditingMode.RelationshipStrength) || (_mode == ObjectEditingMode.Trait)) && (_newValue.ValueIsBoundToVariable == true) ) { bool foundIt = false; foreach (Trait traitItem in previouslyBoundVars) { if ( (traitItem.Name == (string)_newValue.LiteralValueOrBoundVarName) && (traitItem.Type == _newValue.Type) ) { foundIt = true; break; } } if (!foundIt) { throw new Exception("Edit Object Action in Plot Fragment \"" + parentFrag.Name + "\" refers to variable \"" + (string)_newValue.LiteralValueOrBoundVarName + "\", \nwhich has a different type or does not exist in any previous Author Goal parameters, precondition statements, or actions ."); } } //Check to make sure all trait or relationships exist on the object to be edited List <Trait> traitListToCompare = new List <Trait>(); List <Relationship> relListToCompare = new List <Relationship>(); if (_varObjectTypeId == world.CharTypeId) { if (world.Characters.Count > 0) { traitListToCompare = world.Characters[0].Traits; relListToCompare = world.Characters[0].Relationships; } } else if (_varObjectTypeId == world.EnvTypeId) { if (world.Environments.Count > 0) { traitListToCompare = world.Environments[0].Traits; relListToCompare = world.Environments[0].Relationships; } } else { PlotPointType currType = world.findPlotPointTypeById(_varObjectTypeId); if (currType != null) { traitListToCompare = currType.Traits; } else { throw new Exception("Edit Object Action in Plot Fragment \"" + parentFrag.Name + "\" refers to a Plot Point type that no longer exists."); } } if (_mode == ObjectEditingMode.Trait) { //look for trait we are editing if (null == Utilities.findTraitByNameAndType(traitListToCompare, _newValue.Name, _newValue.Type)) { throw new Exception("Edit Object Action in Plot Fragment \"" + parentFrag.Name + "\" refers to a trait with name \"" + _newValue.Name + "\" and type \"" + Trait.TraitDataTypeToString(_newValue.Type) + "\" that no longer exists."); } } else { //look for relationship we are editing if (null == Utilities.findRelationshipByName(relListToCompare, _newValue.Name)) { throw new Exception("Edit Object Action in Plot Fragment \"" + parentFrag.Name + "\" refers to a relationship with name \"" + _newValue.Name + " that no longer exists."); } } //No new variables to add to the binding list, so we can just exit after all the error checks }