Beispiel #1
0
 void FillItemInfo(json::Value& dst, json::Value& actors, GameBalance::Type::Item& item, std::string const& type, std::string const& slot) {
   SnoFile<Actor> actor(item.x108_ActorSno.name());
   if (!actor) return;
   std::map<uint32, uint32> tags;
   for (uint32 i = 1; i + 3 <= actor->x060_TagMap.size(); i += 3) {
     tags[actor->x060_TagMap[i + 1]] = actor->x060_TagMap[i + 2];
   }
   uint32 aid = 0;
   if (slot == "head") {
     dst["actor"] = MakeActor(actor, tags, actors, false, false, true);
   }
   if (slot == "legs" || slot == "feet" || slot == "torso" || slot == "hands") {
     dst["armortype"] = tags[66560];
     dst["look"] = tags[66561];
   }
   if (slot == "shoulders") {
     dst["actor"] = MakeActor(actor, tags, actors, false);
     dst["actor_r"] = MakeActor(actor, tags, actors, false, true);
   }
   if (slot == "mainhand" || slot == "offhand" || slot == "twohand" || slot == "onehand") {
     if (type == "quiver") return;
     dst["actor"] = MakeActor(actor, tags, actors, type == "source" || type == "mojo");
   }
 }
Beispiel #2
0
// NOTE: This function can return NULL if the actor should not be displayed.
// Callers should be aware of this and handle it appropriately.
Actor* ActorUtil::MakeActor( const RString &sPath_, Actor *pParentActor )
{
	RString sPath( sPath_ );

	FileType ft = GetFileType( sPath );
	switch( ft )
	{
	case FT_Lua:
		{
			auto_ptr<XNode> pNode( LoadXNodeFromLuaShowErrors(sPath) );
			if( pNode.get() == NULL )
			{
				// XNode will warn about the error
				return new Actor;
			}

			Actor *pRet = ActorUtil::LoadFromNode( pNode.get(), pParentActor );
			return pRet;
		}
	case FT_Xml:
		{
			// Legacy actors; only supported in quirks mode
			if ( !PREFSMAN->m_bQuirksMode )
				return new Actor;

			XNode xml;
			if ( !XmlFileUtil::LoadFromFileShowErrors(xml, sPath) )
				return new Actor;
			XmlFileUtil::CompileXNodeTree( &xml, sPath );
			XmlFileUtil::AnnotateXNodeTree( &xml, sPath );
			return LoadFromNode( &xml, pParentActor );
		}
	case FT_Directory:
		{
			if( sPath.Right(1) != "/" )
				sPath += '/';

			RString sXml = sPath + "default.xml";
			if (DoesFileExist(sXml))
				return MakeActor(sXml, pParentActor);

			XNode xml;
			xml.AppendAttr( "Class", "BGAnimation" );
			xml.AppendAttr( "AniDir", sPath );

			return ActorUtil::LoadFromNode( &xml, pParentActor );
		}
	case FT_Bitmap:
	case FT_Movie:
		{
			XNode xml;
			xml.AppendAttr( "Class", "Sprite" );
			xml.AppendAttr( "Texture", sPath );

			return ActorUtil::LoadFromNode( &xml, pParentActor );
		}
	case FT_Sprite:
		{
			// Legacy actor; only supported in quirks mode
			if( !PREFSMAN->m_bQuirksMode )
				return new Actor;

			IniFile ini;
			ini.ReadFile( sPath );
			XmlFileUtil::AnnotateXNodeTree( &ini, sPath );

			return ActorUtil::LoadFromNode( ini.GetChild("Sprite"), pParentActor );
		}
	case FT_Model:
		{
			XNode xml;
			xml.AppendAttr( "Class", "Model" );
			xml.AppendAttr( "Meshes", sPath );
			xml.AppendAttr( "Materials", sPath );
			xml.AppendAttr( "Bones", sPath );

			return ActorUtil::LoadFromNode( &xml, pParentActor );
		}
	default:
		{
			LOG->Warn( "File \"%s\" has unknown type, \"%s\".", sPath.c_str(), FileTypeToString(ft).c_str() );

			XNode xml;
			xml.AppendAttr( "Class", "Actor" );
			return ActorUtil::LoadFromNode( &xml, pParentActor );
		}
	}
}
Beispiel #3
0
Actor *ActorUtil::LoadFromNode( const XNode* _pNode, Actor *pParentActor )
{
	ASSERT( _pNode != NULL );

	XNode node = *_pNode;

	// Remove this in favor of using conditionals in Lua. -Chris
	// There are a number of themes out there that depend on this (including
	// sm-ssc default). Probably for the best to leave this in. -aj
	{
		bool bCond;
		if( node.GetAttrValue("Condition", bCond) && !bCond )
			return NULL;
	}

	RString sClass;
	bool bHasClass = node.GetAttrValue( "Class", sClass );
	if( !bHasClass )
		bHasClass = node.GetAttrValue( "Type", sClass );

	bool bLegacy = (node.GetAttr( "_LegacyXml" ) != NULL);
	if( !bHasClass && bLegacy )
		sClass = GetLegacyActorClass( &node );

	map<RString,CreateActorFn>::iterator iter = g_pmapRegistrees->find( sClass );
	if( iter == g_pmapRegistrees->end() )
	{
		RString sFile;
		if (bLegacy && node.GetAttrValue("File", sFile) && sFile != "")
		{
			RString sPath;
			// Handle absolute paths correctly
			if (sFile.Left(1) == "/")
				sPath = sFile;
			else
				sPath = Dirname(GetSourcePath(&node)) + sFile;
			if (ResolvePath(sPath, GetWhere(&node)))
			{
				Actor *pNewActor = MakeActor(sPath, pParentActor);
				if (pNewActor == NULL)
					return NULL;
				if (pParentActor)
					pNewActor->SetParent(pParentActor);
				pNewActor->LoadFromNode(&node);
				return pNewActor;
			}
		}

		// sClass is invalid
		RString sError = ssprintf( "%s: invalid Class \"%s\"",
			ActorUtil::GetWhere(&node).c_str(), sClass.c_str() );
		LuaHelpers::ReportScriptError(sError);
		return new Actor;	// Return a dummy object so that we don't crash in AutoActor later.
	}

	const CreateActorFn &pfn = iter->second;
	Actor *pRet = pfn();

	if( pParentActor )
		pRet->SetParent( pParentActor );

	pRet->LoadFromNode( &node );
	return pRet;
}