@@ -44,7 +44,7 @@ class BuildProject {
4444 [string ] $buildCachePath
4545 [string ] $cookerOutputPath
4646 [string ] $makeFingerprintsPath
47- [string []] $thismodpackages
47+ [string []] $modScriptPackages
4848 [bool ] $isHl
4949 [bool ] $cookHL
5050 [PSCustomObject ] $contentOptions
@@ -102,25 +102,42 @@ class BuildProject {
102102 $this._ConfirmPaths ()
103103 $this._SetupUtils ()
104104 $this._LoadContentOptions ()
105- $this._PerformStep ({ ($_ )._CleanAdditional() }, " Cleaning" , " Cleaned" , " additional mods" )
105+
106+ if ($this._HasScriptPackages ()) {
107+ $this._PerformStep ({ ($_ )._CleanAdditional() }, " Cleaning" , " Cleaned" , " additional mods" )
108+ }
109+
106110 $this._PerformStep ({ ($_ )._CopyModToSdk() }, " Mirroring" , " Mirrored" , " mod to SDK" )
107111 $this._PerformStep ({ ($_ )._ConvertLocalization() }, " Converting" , " Converted" , " Localization UTF-8 -> UTF-16" )
108- $this._PerformStep ({ ($_ )._CopyToSrc() }, " Populating" , " Populated" , " Development\Src folder" )
109- $this._PerformStep ({ ($_ )._RunPreMakeHooks() }, " Running" , " Ran" , " Pre-Make hooks" )
110- $this._PerformStep ({ ($_ )._CheckCleanCompiled() }, " Verifying" , " Verified" , " compiled script packages" )
111- $this._PerformStep ({ ($_ )._RunMakeBase() }, " Compiling" , " Compiled" , " base-game script packages" )
112- $this._PerformStep ({ ($_ )._RunMakeMod() }, " Compiling" , " Compiled" , " mod script packages" )
113- $this._RecordCoreTimestamp ()
114- if ($this.isHl ) {
115- if (-not $this.debug ) {
116- $this._PerformStep ({ ($_ )._RunCookHL() }, " Cooking" , " Cooked" , " Highlander packages" )
117- } else {
118- Write-Host " Skipping cooking as debug build"
112+
113+ if ($this._ShouldCompileBase ()) {
114+ $this._PerformStep ({ ($_ )._CopyToSrc() }, " Populating" , " Populated" , " Development\Src folder" )
115+ $this._PerformStep ({ ($_ )._RunPreMakeHooks() }, " Running" , " Ran" , " Pre-Make hooks" )
116+ $this._PerformStep ({ ($_ )._CheckCleanCompiled() }, " Verifying" , " Verified" , " compiled script packages" )
117+ $this._PerformStep ({ ($_ )._RunMakeBase() }, " Compiling" , " Compiled" , " base-game script packages" )
118+ }
119+
120+ if ($this._HasScriptPackages ()) {
121+ $this._PerformStep ({ ($_ )._RunMakeMod() }, " Compiling" , " Compiled" , " mod script packages" )
122+ }
123+
124+ if ($this._ShouldCompileBase ()) {
125+ $this._RecordCoreTimestamp ()
126+ }
127+
128+ if ($this._HasScriptPackages ()) {
129+ if ($this.isHl ) {
130+ if (-not $this.debug ) {
131+ $this._PerformStep ({ ($_ )._RunCookHL() }, " Cooking" , " Cooked" , " Highlander packages" )
132+ } else {
133+ Write-Host " Skipping HL cooking as debug build"
134+ }
119135 }
136+
137+ $this._PerformStep ({ ($_ )._CopyScriptPackages() }, " Copying" , " Copied" , " compiled script packages" )
120138 }
121- $this._PerformStep ({ ($_ )._CopyScriptPackages() }, " Copying" , " Copied" , " compiled script packages" )
122-
123- # The shader step needs to happen before cooking - precompiler gets confused by some inlined materials
139+
140+ # The shader step needs to happen before asset cooking - precompiler gets confused by some inlined materials
124141 $this._PerformStep ({ ($_ )._PrecompileShaders() }, " Precompiling" , " Precompiled" , " shaders" )
125142
126143 $this._PerformStep ({ ($_ )._RunCookAssets() }, " Cooking" , " Cooked" , " mod assets" )
@@ -130,8 +147,10 @@ class BuildProject {
130147 $this._PerformStep ({ ($_ )._CopyMissingUncooked() }, " Copying" , " Copied" , " requested uncooked packages" )
131148
132149 $this._PerformStep ({ ($_ )._FinalCopy() }, " Copying" , " Copied" , " built mod to game directory" )
150+
133151 $fullStopwatch.Stop ()
134152 $this._ReportTimings ($fullStopwatch )
153+
135154 SuccessMessage " *** SUCCESS! ($ ( FormatElapsed $fullStopwatch.Elapsed ) ) ***" $this.modNameCanonical
136155 }
137156 catch {
@@ -217,7 +236,31 @@ class BuildProject {
217236
218237 # build package lists we'll need later and delete as appropriate
219238 # the mod's packages
220- $this.thismodpackages = Get-ChildItem " $ ( $this.modSrcRoot ) /Src" - Directory
239+ $modSrcPath = " $ ( $this.modSrcRoot ) /Src"
240+ if (Test-Path $modSrcPath ) {
241+ $this.modScriptPackages = @ (Get-ChildItem " $ ( $this.modSrcRoot ) /Src" - Directory)
242+ } else {
243+ # No scripts to compile
244+ $this.modScriptPackages = @ ()
245+ }
246+
247+ if (! $this._HasScriptPackages ()) {
248+ if ($this.clean.Length -gt 0 ) {
249+ ThrowFailure " AddToClean is not supported when no script packages to compile"
250+ }
251+
252+ if ($this.include.Length -gt 0 ) {
253+ ThrowFailure " IncludeSrc is not supported when no script packages to compile"
254+ }
255+
256+ if ($this.preMakeHooks.Length -gt 0 ) {
257+ ThrowFailure " AddPreMakeHook is not supported when no script packages to compile"
258+ }
259+
260+ if ($this.debug ) {
261+ ThrowFailure " Debug build enabled but no script packages to compile"
262+ }
263+ }
221264
222265 $this.isHl = $this._HasNativePackages ()
223266 $this.cookHL = $this.isHl -and -not $this.debug
@@ -308,7 +351,9 @@ class BuildProject {
308351 Robocopy.exe " $ ( $this.modSrcRoot ) " " $ ( $this.stagingPath ) " * .* $global :def_robocopy_args / XF @xf / XD " ContentForCook"
309352 Write-Host " Copied project to staging."
310353
311- New-Item " $ ( $this.stagingPath ) /Script" - ItemType Directory
354+ if ($this._HasScriptPackages ()) {
355+ New-Item " $ ( $this.stagingPath ) /Script" - ItemType Directory
356+ }
312357
313358 # read mod metadata from the x2proj file
314359 Write-Host " Reading mod metadata from $ ( $this.modX2ProjPath ) "
@@ -369,10 +414,12 @@ class BuildProject {
369414 }
370415 Write-Host " Copied dependency sources to Src."
371416
372- # copying the mod's scripts to the script staging location
373- Write-Host " Copying the mod's sources to Src..."
374- $this._CopySrcFolder (" $ ( $this.modSrcRoot ) \Src" )
375- Write-Host " Copied mod sources to Src."
417+ if ($this._HasScriptPackages ()) {
418+ # copying the mod's scripts to the script staging location
419+ Write-Host " Copying the mod's sources to Src..."
420+ $this._CopySrcFolder (" $ ( $this.modSrcRoot ) \Src" )
421+ Write-Host " Copied mod sources to Src."
422+ }
376423 }
377424
378425 [void ]_CopySrcFolder([string ] $includeDir ) {
@@ -523,7 +570,7 @@ class BuildProject {
523570 [bool ]_HasNativePackages() {
524571 # Check if this is a Highlander and we need to cook things
525572 $anynative = $false
526- foreach ($name in $this.thismodpackages )
573+ foreach ($name in $this.modScriptPackages )
527574 {
528575 if ($global :nativescriptpackages.Contains ($name )) {
529576 $anynative = $true
@@ -533,9 +580,26 @@ class BuildProject {
533580 return $anynative
534581 }
535582
583+ [bool ] _HasScriptPackages () {
584+ return $this.modScriptPackages.Length -gt 0
585+ }
586+
587+ [bool ] _ShouldCompileBase () {
588+ if ($this._HasScriptPackages ()) {
589+ return $true
590+ }
591+
592+ # We need to compile base game scripts if cooking assets, otherwise the cooker will just crash if the SDK was cleaned beforehand
593+ if ($this._AnyAssetsToCook ()) {
594+ return $true
595+ }
596+
597+ return $false
598+ }
599+
536600 [void ]_CopyScriptPackages() {
537601 # copy packages to staging
538- foreach ($name in $this.thismodpackages ) {
602+ foreach ($name in $this.modScriptPackages ) {
539603 if ($this.cookHL -and $global :nativescriptpackages.Contains ($name ))
540604 {
541605 # This is a native (cooked) script package -- copy important upks
@@ -787,6 +851,10 @@ class BuildProject {
787851 $exitCode = $process.ExitCode
788852 $receiver.Finish ($exitCode )
789853 }
854+
855+ [bool ] _AnyAssetsToCook () {
856+ return ($this.contentOptions.sfStandalone.Length -gt 0 ) -or ($this.contentOptions.sfMaps.Length -gt 0 ) -or ($this.contentOptions.sfCollectionMaps.Length -gt 0 )
857+ }
790858}
791859
792860class ModAssetsCookStep {
@@ -818,7 +886,7 @@ class ModAssetsCookStep {
818886 }
819887
820888 [void ] Execute() {
821- if (( $this.project.contentOptions.sfStandalone.Length -lt 1 ) -and ( $this .project.contentOptions.sfMaps.Length -lt 1 ) -and ( $this .project.contentOptions.sfCollectionMaps.Length -lt 1 )) {
889+ if (! $this.project._AnyAssetsToCook ( )) {
822890 Write-Host " No asset cooking is requested, skipping"
823891 return
824892
0 commit comments