Hi Guys,
in the course of trying to create a custom faction (as a major mod, not with the faction generator), I've found myself looking up and comparing technologies quite a bit. Lazy fellow that I am, I wrote myself a little tool to do this with. Friendly fellow that I am, I'm quite willing to share, just in case someone else finds a use for it:
Code: php
- function Get-Technology
- {
- <#
- .SYNOPSIS
- Fetches Technologies from all Technology Definition files.
-
- .DESCRIPTION
- Fetches Technologies from all Technology Definition files.
-
- .PARAMETER GenericName
- The generic name of the technology to find.
-
- .PARAMETER GamePath
- The path where the game-xml lies in (not the gameroot, but rather "[Gameroot]/data/Game").
- To set a default path, set it in the global $DefaultGamePath variable.
-
- .PARAMETER Property
- A specific property to withdraw. Use dots to indicate sub-items.
-
- Example: Stats.Value
-
- .EXAMPLE
- PS C:\> Get-Technology "ShieldOptimization2" -Property "Stats.Value"
-
- Retrieves the ShieldOptimization2 Technology from all files, specifically noting the Stats/Value property.
- #>
- [CmdletBinding()]
- Param (
- [Parameter(Mandatory = $true, Position = 0)]
- [string]
- $GenericName,
-
- [string]
- $GamePath = $DefaultGamePath,
-
- [string]
- $Property
- )
-
- $files = Get-ChildItem -Filter "*TechDefs.xml" -Path $GamePath
- $Results = @()
- $PropertySplit = @()
- $Property.Split(".") | ForEach-Object { $PropertySplit += $_ }
- $TagName = "" + ($PropertySplit | Select-Object -Last 1)
-
- foreach ($file in $files)
- {
- [xml]$xml = Get-Content $file
- $entry = $xml.Techlist.Tech | Where-Object { $_.GenericName -eq $GenericName }
- $value = $entry
- $PropertySplit | ForEach-Object { $value = $value.$_ }
-
- $count = 0
- $foundEntry = $false
- $foundValue = $false
- $LineEntry = 0
- $LineValue = 0
-
- Get-Content $file | ForEach-Object {
- if (!$foundValue)
- {
- $count++
- if ($_ -like "*<GenericName>$GenericName</GenericName>*") { $foundEntry = $true; $LineEntry = $count - 2 }
- if (($_ -like "*<$TagName>*") -and ($foundEntry) -and ($LineValue -eq 0)) { $foundValue = $true; $LineValue = $count }
- }
- }
- $Props = @{
- Entry = $Entry
- Value = $value
- LineEntry = $LineEntry
- LineValue = $LineValue
- File = $file
- }
- $Results += New-Object PSObject -Property $props
- }
-
- $global:ResultCache = $Results
- return $Results
- }
- $global:DefaultGamePath = "C:\Program Files\Steam\steamapps\common\Galactic Civilizations III\data\Game"
Powershell Skills recommended for use
(Not to worry, it can't break a thing - doesn't write information anywhere)
Cheers,
Bosparan
Note: This displays mightily ... unusual for me on Chrome. If you don't see a thing, try marking it.