Game Studio 2.0 beta has ended and . There are breaking changes in the ContentPipeline.targets file, so I've updated the VBContentManager class to generate a Content.contentproj file that works within the new parameters. The usage of the class remains the same.
Works with Game Studio 2.0
Now outputs content to the appropriate Visual Studio bin location (i.e., bin\Debug or bin\Release, whichever you've set Visual Studio to)
Public Fonts As Hashtable(Of SpriteFont) Public Textures As Hashtable(Of Texture2D) Public SubTextures As Hashtable(Of Hashtable(Of Rectangle)) Public Sounds As Hashtable(Of SoundBank) Public Effects As Hashtable(Of Effect)
Private strContentprojFile, strProjectFolder, strExecutingFolder, strContentFolder As String Private objContent As List(Of ContentFile) Private intDupeSound, intDupeTexture, intDupeFont, intDupeEffect AsInteger
Public ContentType As ContentTypes Public File As System.IO.FileInfo Public Name As String
PublicSubNew(ByVal ContentType As ContentTypes, ByVal ContentFile As System.IO.FileInfo, ByVal Name As String) Me.ContentType = ContentType Me.File = ContentFile Me.Name = Name EndSub
EndStructure
''' <summary> ''' Creates a new ContentManager which has been extended with functionality to support a Visual Basic (or other non-C#) project ''' </summary> ''' <param name="ServiceProvider">Your game has a .Services property; send that in here.</param> ''' <param name="ContentFolder">Your content folder (a relative path, from your game's Project node as it appears in the Solution Explorer)</param> ''' <remarks></remarks> PublicSubNew(ByVal ServiceProvider As IServiceProvider, ByVal ContentFolder As String)
MyBase.New(ServiceProvider)
With System.Reflection.Assembly.GetEntryAssembly.Location Me.strExecutingFolder = .Substring(0, .LastIndexOf("\")) EndWith
Me.Fonts = New Hashtable(Of SpriteFont) Me.Textures = New Hashtable(Of Texture2D) Me.SubTextures = New Hashtable(Of Hashtable(Of Rectangle)) Me.Sounds = New Hashtable(Of SoundBank) Me.Effects = New Hashtable(Of Effect)
EndSub
''' <summary> ''' Attempts to load all assets which have been compiled by the Content Pipeline. Assets are placed into the respective Hash table (Fonts, Textures, et al) ''' </summary> ''' <remarks></remarks> PublicSub LoadAllContent()
Dim objCompiledContent AsNew List(Of IO.FileInfo) Dim strUnknownFiles As String = ""
ForEach file As IO.FileInfo InNew IO.DirectoryInfo(Me.strExecutingFolder).GetFiles("*.xnb", IO.SearchOption.AllDirectories)
'Is this a sheet w/ a rectangle map? If so, load the rectangle map
If IO.File.Exists(file.FullName.Replace(file.Extension, ".map")) Then Me.LoadMap(file.Name.Replace(file.Extension, ""), file.FullName.Replace(file.Extension, ".map")) EndIf
MsgBox("The VBContentManager was unable to determine the correct loader for:" & vbCrLf & _ strUnknownFiles & vbCrLf & vbCrLf & _ "Unless loaded by something else, the above content won't be available at runtime." & vbCrLf & vbCrLf & _ "This application may become unstable as a result.")
EndIf
EndSub
PrivateSub LoadMap(ByVal strTextureNameName As String, ByVal strMapFile As String)
Dim objReader As IO.StreamReader Dim strMapData As String Dim strLine() As String Dim strItem() As String
objReader = New IO.StreamReader(strMapFile)
Me.SubTextures.Add(strTextureNameName, New Hashtable(Of Rectangle))
Me.SubTextures(strTextureNameName).Add(strItem(0), New Rectangle(CInt(strItem(1)), CInt(strItem(2)), CInt(strItem(3)), CInt(strItem(4))))
Next
EndSub
''' <summary> ''' Compiles the VB Content Pipeline ''' </summary> ''' <param name="stealth">Hide/Show the MSBuild window during the compile process</param> ''' <param name="platform">If there's a way the Xbox360 will work with VB, you could pass in the Xbox parameter as a target platform to MSBuild. But it's Windows by default.</param> ''' <remarks></remarks> PublicSub CompileContent(ByVal stealth AsBoolean, OptionalByVal platform As Platform = VBContentManager.Platform.Windows)
Dim objProcess As Process Dim objPSI AsNew Diagnostics.ProcessStartInfo
Me.objContent = New List(Of ContentFile)
Me.HarvestContent()
IfMe.objContent.Count > 0 Then
Me.BuildContentProj(platform)
Try 'to write the content project file to disk
Using TempStreamWriter As System.IO.StreamWriter = New System.IO.StreamWriter(Me.strProjectFolder & "\Content.contentproj", False)
MsgBox("When building the pipeline, trying to run MSBuild.exe resulted in: " & ex.Message)
EndTry
Catch ex As Exception
MsgBox("When building the pipeline, trying to create the Content.contentproj file """ & Me.strProjectFolder & "\Content.contentproj"" resulted in: " & ex.Message)
EndTry
EndIf
EndSub
PrivateSub HarvestContent()
Dim objRoot As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Me.strContentFolder)
ForEach sound As System.IO.FileInfo In objRoot.GetFiles("*.xab", IO.SearchOption.AllDirectories) IfMe.objContent.Contains(New ContentFile(ContentTypes.Sounds, sound, sound.Name.Replace(sound.Extension, ""))) Then Me.intDupeSound += 1 Me.objContent.Add(New ContentFile(ContentTypes.Sounds, sound, sound.Name.Replace(sound.Extension, "") & Me.intDupeSound.ToString)) Else Me.objContent.Add(New ContentFile(ContentTypes.Sounds, sound, sound.Name.Replace(sound.Extension, ""))) EndIf Next
ForEach texture As System.IO.FileInfo In objRoot.GetFiles("*.png", IO.SearchOption.AllDirectories) IfMe.objContent.Contains(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, ""))) Then Me.intDupeTexture += 1 Me.objContent.Add(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, "") & Me.intDupeTexture.ToString)) Else Me.objContent.Add(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, ""))) EndIf Next
ForEach texture As System.IO.FileInfo In objRoot.GetFiles("*.jpg", IO.SearchOption.AllDirectories) IfMe.objContent.Contains(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, ""))) Then Me.intDupeTexture += 1 Me.objContent.Add(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, "") & Me.intDupeTexture.ToString)) Else Me.objContent.Add(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, ""))) EndIf Next
ForEach texture As System.IO.FileInfo In objRoot.GetFiles("*.gif", IO.SearchOption.AllDirectories) IfMe.objContent.Contains(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, ""))) Then Me.intDupeTexture += 1 Me.objContent.Add(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, "") & Me.intDupeTexture.ToString)) Else Me.objContent.Add(New ContentFile(ContentTypes.Textures, texture, texture.Name.Replace(texture.Extension, ""))) EndIf Next
ForEach font As System.IO.FileInfo In objRoot.GetFiles("*.spritefont", IO.SearchOption.AllDirectories) IfMe.objContent.Contains(New ContentFile(ContentTypes.Fonts, font, font.Name.Replace(font.Extension, ""))) Then Me.intDupeFont += 1 Me.objContent.Add(New ContentFile(ContentTypes.Fonts, font, font.Name.Replace(font.Extension, "") & Me.intDupeFont.ToString)) Else Me.objContent.Add(New ContentFile(ContentTypes.Fonts, font, font.Name.Replace(font.Extension, ""))) EndIf Next
ForEach effect As System.IO.FileInfo In objRoot.GetFiles("*.fx", IO.SearchOption.AllDirectories) IfMe.objContent.Contains(New ContentFile(ContentTypes.Effects, effect, effect.Name.Replace(effect.Extension, ""))) Then Me.intDupeEffect += 1 Me.objContent.Add(New ContentFile(ContentTypes.Effects, effect, effect.Name.Replace(effect.Extension, "") & Me.intDupeEffect.ToString)) Else Me.objContent.Add(New ContentFile(ContentTypes.Effects, effect, effect.Name.Replace(effect.Extension, ""))) EndIf Next
EndSub
PrivateSub BuildContentProj(ByVal platform As Platform)
If content.ContentType = ContentTypes.Textures Then
'If this texture is a sheet w/ a map, copy it's map out in the executable area 'along side the existing or eventual compiled texture
If IO.File.Exists(content.File.FullName.Replace(content.File.Extension, ".map")) Then
Try IO.File.Copy(content.File.FullName.Replace(content.File.Extension, ".map"), _ Me.strExecutingFolder & content.File.FullName.Replace(Me.strProjectFolder, "").Replace(content.File.Extension, ".map"), True) Catch ex As Exception 'I'm going to be optimistic and assume that if I can't copy 'it's because the file is already there, and life is just fine EndTry
EndIf
EndIf
Next
Me.strContentprojFile &= vbCrLf & vbTab & "<!-- To modify your build process, add your task inside one of the targets below and uncomment it. " & vbCrLf & _ vbTab & " Other similar extension points exist, see Microsoft.Common.targets." & vbCrLf & _ vbTab & "<Target Name=""BeforeBuild"">" & vbCrLf & _ vbTab & "</Target>" & vbCrLf & _ vbTab & "<Target Name=""AfterBuild"">" & vbCrLf & _ vbTab & "</Target>" & vbCrLf & _ vbTab & "-->" & vbCrLf & _ "</Project>"
0 comments: