News

[modding][tool]Lookup and Compare technologies

Posted on Saturday, April 4, 2015

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
  1. function Get-Technology
  2. {
  3. <#
  4. .SYNOPSIS
  5. Fetches Technologies from all Technology Definition files.
  6. .DESCRIPTION
  7. Fetches Technologies from all Technology Definition files.
  8. .PARAMETER GenericName
  9. The generic name of the technology to find.
  10. .PARAMETER GamePath
  11. The path where the game-xml lies in (not the gameroot, but rather "[Gameroot]/data/Game").
  12. To set a default path, set it in the global $DefaultGamePath variable.
  13. .PARAMETER Property
  14. A specific property to withdraw. Use dots to indicate sub-items.
  15. Example: Stats.Value
  16. .EXAMPLE
  17. PS C:\> Get-Technology "ShieldOptimization2" -Property "Stats.Value"
  18. Retrieves the ShieldOptimization2 Technology from all files, specifically noting the Stats/Value property.
  19. #>
  20. [CmdletBinding()]
  21. Param (
  22. [Parameter(Mandatory = $true, Position = 0)]
  23. [string]
  24. $GenericName,
  25. [string]
  26. $GamePath = $DefaultGamePath,
  27. [string]
  28. $Property
  29. )
  30. $files = Get-ChildItem -Filter "*TechDefs.xml" -Path $GamePath
  31. $Results = @()
  32. $PropertySplit = @()
  33. $Property.Split(".") | ForEach-Object { $PropertySplit += $_ }
  34. $TagName = "" + ($PropertySplit | Select-Object -Last 1)
  35. foreach ($file in $files)
  36. {
  37. [xml]$xml = Get-Content $file
  38. $entry = $xml.Techlist.Tech | Where-Object { $_.GenericName -eq $GenericName }
  39. $value = $entry
  40. $PropertySplit | ForEach-Object { $value = $value.$_ }
  41. $count = 0
  42. $foundEntry = $false
  43. $foundValue = $false
  44. $LineEntry = 0
  45. $LineValue = 0
  46. Get-Content $file | ForEach-Object {
  47. if (!$foundValue)
  48. {
  49. $count++
  50. if ($_ -like "*<GenericName>$GenericName</GenericName>*") { $foundEntry = $true; $LineEntry = $count - 2 }
  51. if (($_ -like "*<$TagName>*") -and ($foundEntry) -and ($LineValue -eq 0)) { $foundValue = $true; $LineValue = $count }
  52. }
  53. }
  54. $Props = @{
  55. Entry = $Entry
  56. Value = $value
  57. LineEntry = $LineEntry
  58. LineValue = $LineValue
  59. File = $file
  60. }
  61. $Results += New-Object PSObject -Property $props
  62. }
  63. $global:ResultCache = $Results
  64. return $Results
  65. }
  66. $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.