-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew-preview.ps1
More file actions
105 lines (86 loc) · 3.76 KB
/
Copy pathnew-preview.ps1
File metadata and controls
105 lines (86 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<#
.SYNOPSIS
Generate a preview stub for a biscuit. activity
.USAGE
.\new-preview.ps1 MyNewActivity
Adds a render function to test_preview.cpp and rebuilds.
#>
param(
[Parameter(Mandatory=$true)]
[string]$ActivityName
)
$env:PYTHONUTF8 = "1"
$previewFile = "test\test_preview\test_preview.cpp"
$funcName = "render_$($ActivityName.ToLower())"
$bmpName = "preview_$($ActivityName.ToLower()).bmp"
if (-not (Test-Path $previewFile)) {
Write-Host "ERROR: $previewFile not found" -ForegroundColor Red
exit 1
}
$content = Get-Content $previewFile -Raw
# Check if already exists
if ($content -match $funcName) {
Write-Host "$funcName already exists in test_preview.cpp" -ForegroundColor Yellow
Write-Host "Just edit it and run: pio test -e native -f test_preview" -ForegroundColor Cyan
exit 0
}
# Find the source file for reference
$srcFile = "src\activities\apps\${ActivityName}Activity.cpp"
$hint = ""
if (Test-Path $srcFile) {
Write-Host "Found source: $srcFile" -ForegroundColor Green
$hint = " // Reference: $srcFile"
} else {
Write-Host "No source file found at $srcFile — creating blank template" -ForegroundColor Yellow
}
# Generate the stub
$stub = @"
void ${funcName}() {
${hint}
renderer.clearScreen();
drawHeader("${ActivityName}");
// === YOUR RENDER CODE HERE ===
// Copy drawing calls from your activity's render() method.
// Available functions:
// renderer.drawCenteredText(UI_12_FONT_ID, y, "text", true, 1); // bold
// renderer.drawCenteredText(UI_10_FONT_ID, y, "text"); // normal
// renderer.drawText(UI_10_FONT_ID, x, y, "text");
// renderer.drawText(SMALL_FONT_ID, x, y, "small text");
// renderer.fillRect(x, y, w, h, true); // black
// renderer.fillRect(x, y, w, h, false); // white
// renderer.drawRect(x, y, w, h); // border
// renderer.drawLine(x1, y1, x2, y2);
// drawListItem(y, "Item", selected); // list row
// drawDie(x, y, size, value); // d6 die face
// drawHeader("Title", "subtitle");
//
// Screen: 480 wide x 800 tall
// Header ends at y=42, button hints start at y=768
renderer.drawCenteredText(UI_12_FONT_ID, 380, "TODO: add render code", true, 1);
drawButtonHints("Back", "Select", "Up", "Down");
TEST_ASSERT_TRUE(renderer.saveBMP("test/${bmpName}"));
}
"@
# Insert stub before the template comment block
$insertPoint = "// ============================================================`n// YOUR NEW ACTIVITY"
if ($content -match [regex]::Escape("// YOUR NEW ACTIVITY")) {
$content = $content -replace [regex]::Escape("// ============================================================`n// YOUR NEW ACTIVITY"), "${stub}`n// ============================================================`n// YOUR NEW ACTIVITY"
} else {
# Fallback: insert before setUp
$content = $content -replace "// ============================================================\nvoid setUp", "${stub}`n// ============================================================`nvoid setUp"
}
# Add RUN_TEST line
$content = $content -replace "return UNITY_END\(\);", " RUN_TEST(${funcName});`n return UNITY_END();"
Set-Content $previewFile $content -NoNewline
Write-Host ""
Write-Host "Added $funcName to test_preview.cpp" -ForegroundColor Green
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host " 1. Edit test\test_preview\test_preview.cpp" -ForegroundColor White
Write-Host " Find $funcName() and add your drawing code" -ForegroundColor White
Write-Host ""
Write-Host " 2. Preview:" -ForegroundColor White
Write-Host " pio test -e native -f test_preview; start test\${bmpName}" -ForegroundColor Yellow
Write-Host ""
Write-Host " Or use watch mode:" -ForegroundColor White
Write-Host " .\preview.ps1" -ForegroundColor Yellow