Initial commit
This commit is contained in:
38
tools/generate_audio.py
Normal file
38
tools/generate_audio.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Generate original mono PCM effects using only the Python standard library.
|
||||
Python is a development convenience; it is never needed to play the game.
|
||||
"""
|
||||
from pathlib import Path
|
||||
import math
|
||||
import struct
|
||||
import wave
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1] / "assets" / "audio"
|
||||
CUES = {
|
||||
"pellet": ([880, 1320], 0.035),
|
||||
"power": ([330, 440, 660, 880], 0.09),
|
||||
"frightened": ([165, 220, 165], 0.10),
|
||||
"defeated": ([660, 880, 1320], 0.07),
|
||||
"death": ([660, 550, 440, 330, 165], 0.12),
|
||||
"victory": ([440, 554.37, 659.25, 880, 659.25, 880], 0.16),
|
||||
"game_over": ([330, 293.66, 261.63, 164.81], 0.22),
|
||||
}
|
||||
|
||||
def main():
|
||||
ROOT.mkdir(parents=True, exist_ok=True)
|
||||
rate = 22050
|
||||
for name, (notes, duration) in CUES.items():
|
||||
samples = bytearray()
|
||||
for frequency in notes:
|
||||
count = int(rate * duration)
|
||||
for i in range(count):
|
||||
envelope = min(i / (rate * 0.005), 1) * (1 - i / count) ** 1.5
|
||||
tone = math.sin(2 * math.pi * frequency * i / rate)
|
||||
samples.extend(struct.pack("<h", int(tone * envelope * 6500)))
|
||||
with wave.open(str(ROOT / f"{name}.wav"), "wb") as output:
|
||||
output.setnchannels(1)
|
||||
output.setsampwidth(2)
|
||||
output.setframerate(rate)
|
||||
output.writeframes(samples)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
38
tools/package.ps1
Normal file
38
tools/package.ps1
Normal file
@@ -0,0 +1,38 @@
|
||||
param(
|
||||
[ValidatePattern('^[A-Za-z0-9_]+(-[A-Za-z0-9_]+)+$')]
|
||||
[string]$Target = "x86_64-pc-windows-msvc"
|
||||
)
|
||||
$ErrorActionPreference = "Stop"
|
||||
$project = Split-Path $PSScriptRoot -Parent
|
||||
Push-Location $project
|
||||
try {
|
||||
$rustInfo = rustc -vV
|
||||
if ($LASTEXITCODE -ne 0) { throw "Could not determine Rust host target" }
|
||||
$hostTarget = (($rustInfo | Select-String '^host: ').ToString() -replace '^host: ', '')
|
||||
$targetDir = if ($env:CARGO_TARGET_DIR) { $env:CARGO_TARGET_DIR } else { "target" }
|
||||
$executable = if ($Target -match '-windows-') { "first_person_maze.exe" } else { "first_person_maze" }
|
||||
if ($Target -eq $hostTarget) {
|
||||
cargo build --release --locked
|
||||
$binary = Join-Path $targetDir "release/$executable"
|
||||
} else {
|
||||
cargo build --release --locked --target $Target
|
||||
$binary = Join-Path $targetDir "$Target/release/$executable"
|
||||
}
|
||||
if ($LASTEXITCODE -ne 0) { throw "Cargo build failed" }
|
||||
if (-not (Test-Path -LiteralPath $binary -PathType Leaf)) { throw "Missing binary: $binary" }
|
||||
$releaseRoot = [System.IO.Path]::GetFullPath((Join-Path $project "release"))
|
||||
$destination = [System.IO.Path]::GetFullPath((Join-Path $releaseRoot "$Target/first_person_maze"))
|
||||
if (-not $destination.StartsWith($releaseRoot + [System.IO.Path]::DirectorySeparatorChar, [System.StringComparison]::OrdinalIgnoreCase)) {
|
||||
throw "Package destination is outside the release directory"
|
||||
}
|
||||
if (Test-Path -LiteralPath $destination) {
|
||||
Remove-Item -LiteralPath $destination -Recurse -Force
|
||||
}
|
||||
New-Item -ItemType Directory -Force -Path $destination | Out-Null
|
||||
Copy-Item -LiteralPath $binary -Destination $destination
|
||||
$audioDestination = Join-Path $destination "assets/audio"
|
||||
New-Item -ItemType Directory -Force -Path $audioDestination | Out-Null
|
||||
Get-ChildItem -LiteralPath "assets/audio" -Filter "*.wav" -File | Copy-Item -Destination $audioDestination
|
||||
Copy-Item -LiteralPath "README.md" -Destination $destination
|
||||
Write-Host "Package: $destination"
|
||||
} finally { Pop-Location }
|
||||
28
tools/package.sh
Normal file
28
tools/package.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
host_target="$(rustc -vV | sed -n 's/^host: //p')"
|
||||
target="${1:-$host_target}"
|
||||
case "$target" in
|
||||
''|*[!a-zA-Z0-9_-]*) printf 'Invalid target: %s\n' "$target" >&2; exit 1 ;;
|
||||
esac
|
||||
target_dir="${CARGO_TARGET_DIR:-target}"
|
||||
case "$target" in
|
||||
*-windows-*) executable=first_person_maze.exe ;;
|
||||
*) executable=first_person_maze ;;
|
||||
esac
|
||||
if [ "$target" = "$host_target" ]; then
|
||||
cargo build --release --locked
|
||||
binary="$target_dir/release/$executable"
|
||||
else
|
||||
cargo build --release --locked --target "$target"
|
||||
binary="$target_dir/$target/release/$executable"
|
||||
fi
|
||||
destination="release/$target/first_person_maze"
|
||||
test -f "$binary"
|
||||
rm -rf "$destination"
|
||||
mkdir -p "$destination/assets/audio"
|
||||
cp "$binary" "$destination/"
|
||||
cp assets/audio/*.wav "$destination/assets/audio/"
|
||||
cp README.md "$destination/"
|
||||
printf 'Package: %s\n' "$destination"
|
||||
Reference in New Issue
Block a user