TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Powershell conversion zMUD to tintin++

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Finished Scripts
View previous topic :: View next topic  
Author Message
azreal4066



Joined: 03 Sep 2009
Posts: 3

PostPosted: Fri Sep 04, 2009 11:13 am    Post subject: Powershell conversion zMUD to tintin++ Reply with quote

For those of you who, like me, are moving off of a Windows platform MUD client onto tintin++ - more specifically from zMUD onto tt++ - here is a Powershell script that will convert a text file export of your paths from zMUD into the format that tt++ uses. Powershell can be obtained through Windows Update or from Microsoft directly - or you can very easily rewrite this in Perl, Python, LUA, etc. The syntax for this little guy is fairly simple. Save the code below into a .ps1 file, open powershell, CD to the directory where you saved the script (I used my Desktop) and run it like so:
Code:
PS$>CD "$env:userprofile\Desktop"
PS$...\Desktop>.\Script.ps1 -Path 'Paths.txt'
PS$...\Desktop>

There is no exception handling or anything to prevent you from screwing it up, I figured it was unnecessary. The trick to getting it to work really is knowing how to export your paths out of zMUD correctly: Open zMUD, load your profile offline, open your Paths. From there you need to select all of your paths that you want to export then go to File > Export Text. Then remember where you put it and what you named it. There is one flaw with the script because it involves Powershell and how that code base works with file objects. tt++ won't take the text file that this script outputs directly i.e. you can't #READ zMUD_Paths.txt into tt++. Powershell does something funny with the file header and doesn't reset the line pointer either. I just paste the contents into a vim session and save it that way.

The Script:
Code:
Param( [string]$Path = $Args )

Function Get-Paths
{
   Param( [string]$Path = $Args )
   $Paths = @()
   $oFile = Get-Content -Path $Path
   Foreach( $Line in $oFile ) {
      $Paths += $Line
   }
   Remove-Variable oFile
   return $Paths
}

Function Convert-Path
{
   Param( [string]$zMUDPath = $Args )
   $zMUDPath = $zMUDPath -Replace '[{};\.]',''
   $ttPath = ''
   For ($i = 0; $i -lt $zMUDPath.Length; $i++) {
      If ($zMUDPath[$i] -match '^\d$') {
         $qty = ''
         $loop = 0      
         While ($zMUDPath[$i] -match '^\d$') {
            $qty += $zMUDPath[$i].ToString()
            $i++
         }
         [int]$loop = $qty
         For ( $j = 0; $j -lt $loop; $j++ ) {
            $direction = Get-Direction $zMUDPath[$i]
            $ttPath += "`t$direction;`r`n"
         }
      } Else {
         $direction = Get-Direction $zMUDPath[$i]
         $ttPath += "`t$direction;`r`n"
      }
   }
   return $ttPath
}

Function Get-Direction
{
   Param( [string]$Dir = $Args )
   $fDir = ''
   Switch ( $Dir )
   {
      'h' { $fDir = 'nw' }
      'n' { $fDir = 'n' }
      'l' { $fDir = 'se' }
      'e' { $fDir = 'e' }
      'k' { $fDir = 'sw' }
      's' { $fDir = 's' }
      'j' { $fDir = 'ne' }
      'w' { $fDir = 'w' }
      'u' { $fDir = 'u' }
      'd' { $fDir = 'd' }
   }
   return $fDir
}

Function Append-File
{
   Param( [string[]]$Paths = $Args )
   Foreach ( $Line in $Paths ) {
      $Syntax = $Line.Split(' ')
      $Alias = $Syntax[1]
      $ttPath = Convert-Path -zMUDPath $Syntax[2]
      $Entry = "#ALIAS {$Alias}`r`n{`r`n$ttPath}"
      $Entry | Out-File -filePath 'zMUD_Paths.txt' -Append
   }   
}

$Paths = Get-Paths -Path $Path
Append-File -Paths $Paths
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Finished Scripts All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group