Last active
September 24, 2021 05:46
-
-
Save quonic/ebadf3537500d174e8d4c1b4ee76e112 to your computer and use it in GitHub Desktop.
Nolol/Yolol code expander for thing like battery addition, for the Starbase game.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Version 5.1 | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory)] | |
[string[]] | |
$Path | |
) | |
function Expand-Addition { | |
[OutputType("String")] | |
param ( | |
[Parameter(Mandatory)] | |
[string] | |
$Path | |
) | |
# Get the content of the file $Path | |
$Nolol = Get-Content -Path $Path | |
# Loop through each line | |
$Nolol | ForEach-Object { | |
# Temp string for our output | |
$NololResult = "" | |
# Get the current line $_ and save it to $Line | |
$Line = $_ | |
# Check if the current line matches for a string starting with "// %" | |
if ($Line -like "// %*") { | |
# Replace the % with # to stop future duplication of work and add a new line | |
$NololResult = $NololResult + ($Line -replace '%', '#') + "`r`n" | |
# Split the line by , | |
$SplitLine = $Line -split ',' | |
# Remove // % and use the result for our temp variable | |
$Var = $SplitLine[0] -replace '// %','' | |
# Get our starting number | |
[int]$Start = $SplitLine[1] | |
# Get our ending number | |
[int]$End = $SplitLine[2] | |
# Get our "Device" base name | |
$Property = $SplitLine[3] | |
# Get our delimiter "+" | |
$Symbol = $SplitLine[4] | |
# Create the beginning part of our code | |
$Result = "$($Var)=" | |
# Loop from $Start to $End | |
for ($i = $Start; $i -lt $End; $i++) { | |
# Check if this is the first itteration | |
if ($i -eq $Start) { | |
$StringToAppend = "$($Property)$($i)" | |
} | |
# This isn't or first itteration, add the $Symbol to the begining | |
else { | |
$StringToAppend = "$($Symbol)$($Property)$($i)" | |
} | |
# If the line length is going to be longer than 70 character, then start a new line | |
if ($Result.Length + $StringToAppend.Length -ge 70) { | |
$NololResult = $NololResult + $Result + "`r`n" | |
$Result = "$($Var)=$($Var)+$($Property)$($i)" | |
} | |
# Line length is less than 70, append the current itteration | |
else { | |
$Result = $Result + $StringToAppend | |
} | |
} | |
# Save the results for this "// %" line | |
$NololResult = $NololResult + $Result | |
} | |
else { | |
# Save what ever we don't act on | |
$NololResult = $NololResult + $Line | |
} | |
# Output the results to the pipe line | |
$NololResult | |
} | |
} | |
# Get each file passed to us, test that each file is an existing file, and loop through each one | |
$Path | Where-Object { $(Test-Path -Path $_) } | ForEach-Object { | |
# Call Expand-Addition, pass the current($_) file, store the text to $Result | |
$Result = Expand-Addition -Path $_ | |
# Save over the current file with our changes | |
Set-Content -Path $_ -Value $Result | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert-Code.ps1 -Path .\example.nolol | |
// PowerShell script look for the bellow pattern and adds the expanded nolol/yolol code. | |
// It also changes the % to # so as later itterations don't duplicate the same code. | |
// %Bat,1,20,:Bat,+ | |
:Disp=Bat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment