void ActionCreateAction::Update(WorldState& world) { if (mClassName == "" || mInstanceName == "") { throw std::exception("Class and instance name cannot be blank"); } if (!Search(mInstanceName)) { Entity* entity = GetContainer()->As<Entity>(); if (entity) { entity->CreateAction(mClassName, mInstanceName); return; } ActionList* actionList = GetContainer()->As<ActionList>(); if (actionList) { actionList->CreateAction(mClassName, mInstanceName); return; } throw std::exception("Current scope is not an action or an entity"); } }
bool ActionParseHelper::StartElementHandler(Library::XmlParseMaster::SharedData * sharedData, std::string& name, Library::HashMap<std::string, std::string> hashmap) { if (!sharedData) { return false; } ScopeSharedData * data = sharedData->As<ScopeSharedData>(); if (data) { mStringData = std::string(); if (name == CreateString) { if (!bIsParsing) { bIsParsing = true; auto providedName = hashmap.Find(NameString); if (providedName != hashmap.end()) { Entity * entity = data->GetWorld()->As<Entity>(); if (entity) { auto classType = hashmap.Find(ClassString); if (classType != hashmap.end()) { Action* action = entity->CreateAction(name, providedName->second); ActionCreateAction* actionCreate = action->As<ActionCreateAction>(); auto instanceName = hashmap.Find(InstanceString); if (instanceName != hashmap.end()) { if (actionCreate) { actionCreate->SetClassName(classType->second); actionCreate->SetInstanceName(instanceName->second); data->SetWorld(action); } } } else { throw std::exception("You are not providing a class type"); } } else { throw std::exception("You are not coming from a entity"); } } else { throw std::exception("You are not providing a name for this entity"); } return true; } } else if (name == DestroyString) { bIsParsing = true; auto providedName = hashmap.Find(NameString); if (providedName != hashmap.end()) { Entity * entity = data->GetWorld()->As<Entity>(); if (entity) { Action* action = entity->CreateAction(name, providedName->second); ActionDestroyAction* actionDestroy = action->As<ActionDestroyAction>(); auto instanceName = hashmap.Find(InstanceString); if (instanceName != hashmap.end()) { if (actionDestroy) { actionDestroy->SetInstanceName(instanceName->second); data->SetWorld(action); } } else { throw std::exception("You are not providing a class type"); } } else { throw std::exception("You are not coming from a entity"); } } else { throw std::exception("You are not providing a name for this entity"); } return true; } else if (name == ActionString) { if (!bIsParsing) { bIsParsing = true; auto providedName = hashmap.Find(NameString); if (providedName != hashmap.end()) { Entity * entity = data->GetWorld()->As<Entity>(); if (entity) { auto classType = hashmap.Find(ClassString); if (classType != hashmap.end()) { Action* action = entity->CreateAction(classType->second, providedName->second); auto instanceName = hashmap.Find(InstanceString); if (instanceName != hashmap.end()) { if (action) { ActionEvent* actionEvent = action->As <ActionEvent>(); ReactionAttributed* reactionAttributed = action->As<ReactionAttributed>(); if (actionEvent) { auto subtypeType = hashmap.Find(Subtype); if (subtypeType != hashmap.end()) { actionEvent->SetSubtype(subtypeType->second); } } if (reactionAttributed) { auto subtypeType = hashmap.Find(Subtype); if (subtypeType != hashmap.end()) { reactionAttributed->SetSubtype(subtypeType->second); } } data->SetWorld(action); } } } else { throw std::exception("You are not providing a class type"); } } else { throw std::exception("You are not coming from a entity"); } } else { throw std::exception("You are not providing a name for this entity"); } return true; } } } return false; }