Files
Fishing/build.ps1
T
2026-11-03 09:40:50 +03:00

70 lines
4.7 KiB
PowerShell

# Builds Fishing.rbxlx (place file for Roblox Studio) and install/* from src/.
# Run: powershell -ExecutionPolicy Bypass -File build.ps1
# Fishing.rbxlx is created only if it does not exist yet: after the level is baked in Studio
# (World1Builder) the place file holds the hand-edited map, and scripts reach it via Rojo.
# Use -Force to recreate it from scratch (this DELETES the map built in Studio).
param([switch]$Force)
$root = $PSScriptRoot
$enc = New-Object System.Text.UTF8Encoding($false)
$scripts = @(
@{ Name = 'FishConfig'; Class = 'ModuleScript'; Service = 'ReplicatedStorage'; Path = 'src\ReplicatedStorage\FishConfig.lua'; Rbxmx = '1_FishConfig_ReplicatedStorage.rbxmx' },
@{ Name = 'GameModels'; Class = 'ModuleScript'; Service = 'ReplicatedStorage'; Path = 'src\ReplicatedStorage\GameModels.lua'; Rbxmx = '2_GameModels_ReplicatedStorage.rbxmx' },
@{ Name = 'MapBuilder'; Class = 'Script'; Service = 'ServerScriptService'; Path = 'src\ServerScriptService\MapBuilder.server.lua'; Rbxmx = '3_MapBuilder_ServerScriptService.rbxmx' },
@{ Name = 'GameServer'; Class = 'Script'; Service = 'ServerScriptService'; Path = 'src\ServerScriptService\GameServer.server.lua'; Rbxmx = '4_GameServer_ServerScriptService.rbxmx' },
@{ Name = 'World1Builder'; Class = 'ModuleScript'; Service = 'ServerScriptService'; Path = 'src\ServerScriptService\World1Builder.lua'; Rbxmx = '6_World1Builder_ServerScriptService.rbxmx' },
@{ Name = 'FishingClient'; Class = 'LocalScript'; Service = 'StarterPlayerScripts'; Path = 'src\StarterPlayer\StarterPlayerScripts\FishingClient.client.lua'; Rbxmx = '5_FishingClient_StarterPlayerScripts.rbxmx' }
)
$header = '<roblox xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.roblox.com/roblox.xsd" version="4">'
$script:ref = 0
function NextRef { $script:ref++; return "RBX$($script:ref)" }
function ScriptItem($s) {
$src = [System.IO.File]::ReadAllText((Join-Path $root $s.Path), $enc)
if ($src.Contains(']]>')) { throw "CDATA conflict in $($s.Path)" }
return "<Item class=`"$($s.Class)`" referent=`"$(NextRef)`"><Properties><string name=`"Name`">$($s.Name)</string><ProtectedString name=`"Source`"><![CDATA[$src]]></ProtectedString></Properties></Item>`n"
}
function ServiceItem($class, $children) {
return "<Item class=`"$class`" referent=`"$(NextRef)`"><Properties><string name=`"Name`">$class</string></Properties>`n$children</Item>`n"
}
# --- place file ---
$rs = ($scripts | Where-Object { $_.Service -eq 'ReplicatedStorage' } | ForEach-Object { ScriptItem $_ }) -join ''
$sss = ($scripts | Where-Object { $_.Service -eq 'ServerScriptService' } | ForEach-Object { ScriptItem $_ }) -join ''
$sps = ($scripts | Where-Object { $_.Service -eq 'StarterPlayerScripts' } | ForEach-Object { ScriptItem $_ }) -join ''
$place = $header + "`n" +
(ServiceItem 'ReplicatedStorage' $rs) +
(ServiceItem 'ServerScriptService' $sss) +
(ServiceItem 'StarterPlayer' (ServiceItem 'StarterPlayerScripts' $sps)) +
"</roblox>`n"
$placePath = Join-Path $root 'Fishing.rbxlx'
if ($Force -or -not (Test-Path $placePath)) {
[System.IO.File]::WriteAllText($placePath, $place, $enc)
Write-Host "Built Fishing.rbxlx"
} else {
Write-Host "Fishing.rbxlx already exists - left untouched (it holds the map built in Studio; scripts come via Rojo). Use -Force to recreate."
}
# --- install/*.rbxmx and install/INSTALL.lua ---
$installDir = Join-Path $root 'install'
New-Item -ItemType Directory -Force $installDir | Out-Null
$parents = @{ ReplicatedStorage = 'game.ReplicatedStorage'; ServerScriptService = 'game.ServerScriptService'; StarterPlayerScripts = 'game.StarterPlayer.StarterPlayerScripts' }
$sb = New-Object System.Text.StringBuilder
[void]$sb.Append("local function make(class, name, parent, src)`n local old = parent:FindFirstChild(name)`n if old then old:Destroy() end`n local s = Instance.new(class)`n s.Name = name`n s.Source = src`n s.Parent = parent`nend`nlocal oldMap = workspace:FindFirstChild('FishingMap')`nif oldMap then oldMap:Destroy() end`n")
foreach ($s in $scripts) {
$src = [System.IO.File]::ReadAllText((Join-Path $root $s.Path), $enc)
if ($src.Contains(']=====]')) { throw "Long-string conflict in $($s.Path)" }
[void]$sb.Append("make('$($s.Class)', '$($s.Name)', $($parents[$s.Service]), [=====[" + $src + "]=====])`n")
$script:ref = 0
$xml = $header + "`n" + (ScriptItem $s) + "</roblox>`n"
[System.IO.File]::WriteAllText((Join-Path $installDir $s.Rbxmx), $xml, $enc)
}
[void]$sb.Append("print('DONE! $($scripts.Count) scripts installed. Press Play (F5).')`n")
[System.IO.File]::WriteAllText((Join-Path $installDir 'INSTALL.lua'), $sb.ToString(), $enc)
Write-Host "Built install/"