Created
March 19, 2017 21:40
-
-
Save y-ack/11b7d6c01b08c8edf10b2dcaae9ee290 to your computer and use it in GitHub Desktop.
Now I can edit map data in a text editor
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
#Use examples: | |
#Get-Content route1.blk | MapBytesToText -Width 10 | |
#(Invoke-WebRequest https://raw.githubusercontent.com/pret/pokeyellow/master/maps/route1.blk).Content | MapBytesToText -Width 10 | |
#Takes .blk files and outputs a table of tile block indexes I can actually work with | |
#The resulting format can be eaten by MapBytesToText to convert back into .blk | |
function MapBytesToText { | |
param([Parameter(Mandatory=$True,Position=1,ValueFromPipeline=$True)][String]$File, | |
[Parameter(Mandatory=$False)][Int]$Width) | |
$Width = $Width*4 | |
$formattedbytes = ([System.Text.Encoding]::UTF8.GetBytes($File)) | Foreach-Object {$_.toString().PadLeft(3," ")} | |
$formattedbytes = $formattedbytes -join ',' | |
if($Width) {$formattedbytes = $formattedbytes -replace "(.{$Width})","`$1`n"} | |
$formattedbytes | |
} | |
#Takes a formatted string of tile block indexes e.g. | |
# 10,78,86,86,86,77, | |
# 10,78,13,13,13,77 | |
# as produced by MapBytesToText and converts for output to e.g. a .blk file | |
function MapStringToBytes { | |
param([Parameter(Mandatory=$True,Position=1,ValueFromPipeline=$True)][String]$In) | |
[System.Text.Encoding]::UTF8.GetString(($In -replace "[ `n]", "") -split ',') | |
} | |
#If there are no bugs, this flow should produce identical files. | |
#$mapdata = (Invoke-WebRequest https://raw.githubusercontent.com/pret/pokeyellow/master/maps/route1.blk).Content | |
#$mapdata | MapBytesToText -Width 10 | MapStringToBytes | Out-File route1.blk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment