Skip to content

Commit 716fb87

Browse files
committed
Add Simple Layer Analyzer for ASEPRITE with visibility detection
- Implemented a console-only tool to analyze layer visibility in ASEPRITE files. - Fixed the "black box" issue by dynamically detecting visible and hidden layers. - Added functionality to save individual visible layers as PNG files for inspection. - Improved error handling for loading ASEPRITE files. - Removed hardcoded loop in favor of dynamic layer counting.
1 parent 33e897a commit 716fb87

20 files changed

+3119
-101
lines changed

.github/copilot-instructions.md

Lines changed: 203 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,63 @@
1010
- **QB64-PE Modern**: Leverages QB64-PE V3.12+ features (not QB1.1/QuickBasic compatible)
1111
- **Developer-Friendly**: Extensive debugging, testing, and documentation support
1212

13+
## Critical Development Workflow
14+
15+
### Build System Integration
16+
- **Primary build task**: Use VS Code's "BUILD: Compile" task which auto-removes old executables and compiles with QB64-PE
17+
- **Cross-platform support**: Tasks configured for Windows (.exe), macOS/Linux (.run) with proper compiler paths
18+
- **Execution pattern**: "EXECUTE: Run" depends on successful compilation, handles platform differences automatically
19+
- **QB64-PE path**: Configure `qb64pe.compilerPath` setting to point to your QB64-PE installation
20+
1321
## Library Architecture
1422

1523
### Include Pattern (.BI/.BM System)
16-
QB64_GJ_LIB uses a consistent modular include pattern:
24+
QB64_GJ_LIB uses a consistent modular include pattern that separates interface from implementation:
1725

1826
```basic
1927
' Unified Usage (everything)
20-
'$INCLUDE:'path_to_GJ_LIB/_GJ_LIB.BI' ' Header/interface
28+
'$INCLUDE:'path_to_GJ_LIB/_GJ_LIB.BI' ' Header/interface at TOP
2129
' ...your code...
22-
'$INCLUDE:'path_to_GJ_LIB/_GJ_LIB.BM' ' Implementation
30+
'$INCLUDE:'path_to_GJ_LIB/_GJ_LIB.BM' ' Implementation at BOTTOM
2331
2432
' Individual Usage (example: ANSI + DUMP)
25-
'$INCLUDE:'path_to_GJ_LIB/ANSI/ANSI.BI'
33+
'$INCLUDE:'path_to_GJ_LIB/ANSI/ANSI.BI' ' Headers at TOP
2634
'$INCLUDE:'path_to_GJ_LIB/DUMP/DUMP.BI'
2735
' ...your code...
28-
'$INCLUDE:'path_to_GJ_LIB/ANSI/ANSI.BM'
36+
'$INCLUDE:'path_to_GJ_LIB/ANSI/ANSI.BM' ' Implementations at BOTTOM
2937
'$INCLUDE:'path_to_GJ_LIB/DUMP/DUMP.BM'
3038
```
3139

3240
**Critical Rules:**
33-
- `.BI` files contain type definitions, constants, and function declarations
34-
- `.BM` files contain the actual implementation code
35-
- Always include `.BI` at the top, `.BM` at the bottom
36-
- Use `$IF` preprocessor guards for safe unified/individual inclusion
41+
- `.BI` files: Type definitions, constants, function declarations (always at top)
42+
- `.BM` files: Actual implementation code (always at bottom)
43+
- ARR library is special: Uses `.BAS` files with type-specific implementations (ARR_STR.BAS, ARR_INT.BAS, etc.)
44+
- All files use `$INCLUDEONCE` and preprocessor guards for safe unified/individual inclusion
45+
46+
### Testing Architecture
47+
- **Test files**: Use `.BAS` extension (uppercase) in same directory as library
48+
- **Console testing**: Always use `$CONSOLE:ONLY` and end with `SYSTEM` for clean automation
49+
- **Unified vs Individual**: Toggle with `$LET GJ_LIB_UNIFIED_TESTING = 1` in `_GJ_LIB.BI`
50+
- **Pattern**: Tests typically use DUMP library to display array/object states for verification
3751

3852
### Available Libraries
3953

40-
| Library | Purpose | Key Features |
41-
|---------|---------|--------------|
42-
| **ANSI** | ANSI text mode | Full ANSI.SYS support, 256/RGB colors, QB64 native emulation |
43-
| **ARR** | Array operations | High-level array manipulation for all QB64 types |
44-
| **ASEPRITE** | Aseprite file support | Load/display .ase/.aseprite files with layer compositing |
45-
| **BBX** | Bounding box | Reusable bounding box with position, resize, keyboard/mouse control |
46-
| **CONSOLE** | Console management | Enhanced console debugging and output control |
47-
| **DICT** | Dictionary/hash | Key-value pairs using custom types with `.key` and `.val` |
48-
| **DUMP** | Debug printing | PHP `print_r` style variable dumping |
49-
| **INPUT** | Advanced input | Lightbar menus, text boxes, enhanced user input |
50-
| **MISC** | Utilities | Miscellaneous helper functions that don't fit elsewhere |
51-
| **PIPEPRINT** | ANSI string DSL | Mystic BBS-style pipe (\|) parsing for colored text |
52-
| **STRINGS** | String manipulation | Extensive string processing, arrays, parsing, searching |
53-
| **SYS** | System utilities | OS integration, file operations, system info |
54-
| **VECT2D** | 2D vectors | Mathematical 2D vector operations |
55-
| **VIDEO_MODES** | Display modes | Video mode detection and management |
54+
| Library | Purpose | Key Features | Function Pattern |
55+
|---------|---------|--------------|------------------|
56+
| **ANSI** | ANSI text mode | Full ANSI.SYS support, 256/RGB colors, QB64 native emulation | `ansi_color$()`, `ansi_rgb$()` |
57+
| **ARR** | Array operations | High-level array manipulation for all QB64 types | `ARR_[TYPE].push()`, `ARR_[TYPE].find()` |
58+
| **ASEPRITE** | Aseprite file support | Load/display .ase/.aseprite files with layer compositing | `load_aseprite_image()`, `create_composite_image_from_aseprite&()` |
59+
| **BBX** | Bounding box | Reusable bounding box with position, resize, keyboard/mouse control | Object-oriented style with BBX type |
60+
| **CONSOLE** | Console management | Enhanced console debugging and output control | Console object with methods |
61+
| **DICT** | Dictionary/hash | Key-value pairs using custom `DICTIONARY` type with `.key` and `.val` | `dict_set()`, `dict_get()` |
62+
| **DUMP** | Debug printing | PHP `print_r` style variable dumping | `dump_var()`, `DUMP.string_array$()` |
63+
| **INPUT** | Advanced input | Lightbar menus (LIGHTBAR/LIGHTBAR32), text boxes, enhanced user input | Menu-driven input systems |
64+
| **MISC** | Utilities | Miscellaneous helper functions that don't fit elsewhere | Various utility functions |
65+
| **PIPEPRINT** | ANSI string DSL | Mystic BBS-style pipe (\|) parsing for colored text | `pipeprint()` with pipe codes |
66+
| **STRINGS** | String manipulation | Extensive string processing, arrays, parsing, searching | `str_split()`, `str_join()`, etc. |
67+
| **SYS** | System utilities | OS integration, file operations, system info | Cross-platform system functions |
68+
| **VECT2D** | 2D vectors | Mathematical 2D vector operations | Vector math functions |
69+
| **VIDEO_MODES** | Display modes | Video mode detection and management | Video mode utilities |
5670

5771
## Coding Conventions
5872

@@ -208,6 +222,87 @@ Tasks are configured for Windows, macOS, and Linux:
208222

209223
## Common Patterns and Examples
210224

225+
### VS Code Integration
226+
The project includes comprehensive VS Code configuration:
227+
228+
**Build Tasks:**
229+
- `BUILD: Compile` - Compiles current file with QB64-PE
230+
- `BUILD: Remove` - Cleans compiled executables
231+
- `EXECUTE: Run` - Compiles and runs current file
232+
233+
**External Tool Integration:**
234+
- QB64-PE IDE integration
235+
- InForm-PE GUI designer
236+
- Image editors (GIMP, Krita, Aseprite, Inkscape)
237+
- Text mode editors (MoebiusXBIN, IcyDraw, PabloDraw)
238+
239+
### Cross-Platform Support
240+
Tasks are configured for Windows, macOS, and Linux:
241+
```jsonc
242+
"windows": {
243+
"command": "${config:qb64pe.compilerPath}",
244+
"args": ["-w", "-x", "${fileDirname}\\${fileBasename}"]
245+
},
246+
"linux": {
247+
"command": "${config:qb64pe.compilerPath}",
248+
"args": ["-w", "-x", "${fileDirname}/${fileBasename}"]
249+
}
250+
```
251+
252+
## Common Patterns and Examples
253+
254+
### Dictionary Usage (DICT)
255+
```basic
256+
' Create dictionary
257+
DIM dict(1 TO 100) AS DICT_KV
258+
dict_size = 0
259+
260+
' Add entries
261+
dict_size = dict_set(dict(), dict_size, "username", "grymmjack")
262+
dict_size = dict_set(dict(), dict_size, "age", "42")
263+
264+
' Retrieve values
265+
username$ = dict_get(dict(), dict_size, "username")
266+
```
267+
268+
### Array Operations (ARR)
269+
```basic
270+
' Dynamic string array example
271+
DIM my_strings(1 TO 1000) AS STRING
272+
arr_size = 0
273+
274+
' Add elements
275+
arr_size = arr_str_push(my_strings(), arr_size, "Hello")
276+
arr_size = arr_str_push(my_strings(), arr_size, "World")
277+
278+
' Search and manipulate
279+
index = arr_str_find(my_strings(), arr_size, "Hello")
280+
```
281+
282+
### ANSI Text Styling
283+
```basic
284+
' Using ANSI library for colored output
285+
PRINT ansi_color$(15, 4) + "White text on red background" + ansi_reset$
286+
PRINT ansi_rgb$(255, 128, 0) + "Orange text" + ansi_reset$
287+
```
288+
289+
### Debug Dumping (DUMP)
290+
```basic
291+
' PHP-style variable dumping
292+
TYPE person
293+
name AS STRING
294+
age AS INTEGER
295+
END TYPE
296+
297+
DIM p AS person
298+
p.name = "John"
299+
p.age = 30
300+
301+
dump_var p ' Outputs structured variable information
302+
```
303+
304+
## Error Handling and Debugging
305+
211306
### Dictionary Usage (DICT)
212307
```basic
213308
' Create dictionary
@@ -293,6 +388,37 @@ IF _FILEEXISTS(filename$) THEN
293388
END IF
294389
```
295390

391+
**Console vs Graphics Mode Conflicts:**
392+
```basic
393+
' Problem: Console output not visible in graphics mode
394+
' Solution: Use $CONSOLE:ONLY for debug builds
395+
396+
' Problem: "Press any key" prompts in automated testing
397+
' Solution: Always end with SYSTEM, not END
398+
```
399+
400+
**File Path Issues:**
401+
```basic
402+
' Problem: Relative paths causing include errors
403+
' Solution: Use absolute paths or proper working directory
404+
405+
' Correct:
406+
'$INCLUDE:'C:\path\to\QB64_GJ_LIB\_GJ_LIB.BI'
407+
408+
' Or ensure working directory is set properly
409+
```
410+
411+
**Memory Management:**
412+
```basic
413+
' Always free image resources
414+
IF img& <> -1 THEN _FREEIMAGE img&
415+
416+
' Check for valid handles before use
417+
IF _FILEEXISTS(filename$) THEN
418+
' Safe to proceed
419+
END IF
420+
```
421+
296422
## Integration Guidelines
297423

298424
### Adding New Libraries
@@ -338,68 +464,68 @@ This project includes access to specialized QB64PE MCP (Model Context Protocol)
338464

339465
#### Code Analysis and Enhancement
340466
```
341-
#mcp_qb64pe_analyze_qb64pe_execution_mode - Analyze QB64PE execution characteristics
342-
#mcp_qb64pe_enhance_qb64pe_code_for_debugging - Add debugging enhancements automatically
343-
#mcp_qb64pe_validate_qb64pe_syntax - Check syntax and suggest corrections
344-
#mcp_qb64pe_validate_qb64pe_compatibility - Check for compatibility issues
467+
#qb64pe_analyze_qb64pe_execution_mode - Analyze QB64PE execution characteristics
468+
#qb64pe_enhance_qb64pe_code_for_debugging - Add debugging enhancements automatically
469+
#qb64pe_validate_qb64pe_syntax - Check syntax and suggest corrections
470+
#qb64pe_validate_qb64pe_compatibility - Check for compatibility issues
345471
```
346472

347473
#### Debugging and Monitoring
348474
```
349-
#mcp_qb64pe_get_llm_debugging_guide - Get LLM-specific debugging guidance
350-
#mcp_qb64pe_generate_advanced_debugging_template - Create debugging templates
351-
#mcp_qb64pe_inject_native_qb64pe_logging - Add native logging capabilities
352-
#mcp_qb64pe_parse_qb64pe_structured_output - Parse program output
475+
#qb64pe_get_llm_debugging_guide - Get LLM-specific debugging guidance
476+
#qb64pe_generate_advanced_debugging_template - Create debugging templates
477+
#qb64pe_inject_native_qb64pe_logging - Add native logging capabilities
478+
#qb64pe_parse_qb64pe_structured_output - Parse program output
353479
```
354480

355481
#### Screenshot and Graphics Analysis
356482
```
357-
#mcp_qb64pe_capture_qb64pe_screenshot - Auto-capture program screenshots
358-
#mcp_qb64pe_analyze_qb64pe_graphics_screenshot - Analyze visual output
359-
#mcp_qb64pe_generate_qb64pe_screenshot_analysis_template - Create test templates
360-
#mcp_qb64pe_start_screenshot_monitoring - Monitor graphics programs
483+
#qb64pe_capture_qb64pe_screenshot - Auto-capture program screenshots
484+
#qb64pe_analyze_qb64pe_graphics_screenshot - Analyze visual output
485+
#qb64pe_generate_qb64pe_screenshot_analysis_template - Create test templates
486+
#qb64pe_start_screenshot_monitoring - Monitor graphics programs
361487
```
362488

363489
#### Knowledge and Documentation
364490
```
365-
#mcp_qb64pe_search_qb64pe_wiki - Search QB64PE documentation
366-
#mcp_qb64pe_lookup_qb64pe_keyword - Get keyword information
367-
#mcp_qb64pe_get_qb64pe_keywords_by_category - Browse keywords by category
368-
#mcp_qb64pe_autocomplete_qb64pe_keywords - Get keyword suggestions
491+
#qb64pe_search_qb64pe_wiki - Search QB64PE documentation
492+
#qb64pe_lookup_qb64pe_keyword - Get keyword information
493+
#qb64pe_get_qb64pe_keywords_by_category - Browse keywords by category
494+
#qb64pe_autocomplete_qb64pe_keywords - Get keyword suggestions
369495
```
370496

371497
#### Installation and Configuration
372498
```
373-
#mcp_qb64pe_detect_qb64pe_installation - Check QB64PE installation
374-
#mcp_qb64pe_get_qb64pe_installation_guidance - Get setup instructions
375-
#mcp_qb64pe_validate_qb64pe_path - Verify installation path
499+
#qb64pe_detect_qb64pe_installation - Check QB64PE installation
500+
#qb64pe_get_qb64pe_installation_guidance - Get setup instructions
501+
#qb64pe_validate_qb64pe_path - Verify installation path
376502
```
377503

378504
### AI Agent Best Practices with MCP Tools
379505

380506
#### 1. **Program Execution Safety**
381507
**CRITICAL**: Never wait indefinitely for QB64PE programs
382-
- Use `#mcp_qb64pe_analyze_qb64pe_execution_mode` to understand program behavior
383-
- Apply `#mcp_qb64pe_enhance_qb64pe_code_for_debugging` before execution
508+
- Use `#qb64pe_analyze_qb64pe_execution_mode` to understand program behavior
509+
- Apply `#qb64pe_enhance_qb64pe_code_for_debugging` before execution
384510
- Set timeouts: 30-60 seconds for graphics, 15-30 for console programs
385-
- Monitor with `#mcp_qb64pe_get_process_monitoring_commands`
511+
- Monitor with `#qb64pe_get_process_monitoring_commands`
386512

387513
#### 2. **Debugging Workflow**
388514
```
389-
1. Analyze code: #mcp_qb64pe_analyze_qb64pe_execution_mode
390-
2. Enhance for debugging: #mcp_qb64pe_enhance_qb64pe_code_for_debugging
391-
3. Validate syntax: #mcp_qb64pe_validate_qb64pe_syntax
515+
1. Analyze code: #qb64pe_analyze_qb64pe_execution_mode
516+
2. Enhance for debugging: #qb64pe_enhance_qb64pe_code_for_debugging
517+
3. Validate syntax: #qb64pe_validate_qb64pe_syntax
392518
4. Execute with monitoring
393-
5. Parse output: #mcp_qb64pe_parse_qb64pe_structured_output
394-
6. Capture screenshots: #mcp_qb64pe_capture_qb64pe_screenshot (if graphics)
395-
7. Analyze results: #mcp_qb64pe_analyze_qb64pe_graphics_screenshot
519+
5. Parse output: #qb64pe_parse_qb64pe_structured_output
520+
6. Capture screenshots: #qb64pe_capture_qb64pe_screenshot (if graphics)
521+
7. Analyze results: #qb64pe_analyze_qb64pe_graphics_screenshot
396522
```
397523

398524
#### 3. **Graphics Program Handling**
399-
- Use `#mcp_qb64pe_start_screenshot_monitoring` for automated capture
400-
- Apply `#mcp_qb64pe_generate_qb64pe_screenshot_analysis_template` for testing
401-
- Analyze with `#mcp_qb64pe_analyze_qb64pe_graphics_screenshot`
402-
- Generate feedback with `#mcp_qb64pe_generate_programming_feedback`
525+
- Use `#qb64pe_start_screenshot_monitoring` for automated capture
526+
- Apply `#qb64pe_generate_qb64pe_screenshot_analysis_template` for testing
527+
- Analyze with `#qb64pe_analyze_qb64pe_graphics_screenshot`
528+
- Generate feedback with `#qb64pe_generate_programming_feedback`
403529

404530
#### 4. **Code Enhancement Patterns**
405531
```basic
@@ -419,16 +545,32 @@ SYSTEM ' Added by debugging service
419545
```
420546

421547
#### 5. **Compatibility and Porting**
422-
- Use `#mcp_qb64pe_analyze_qbasic_compatibility` for legacy code
423-
- Apply `#mcp_qb64pe_port_qbasic_to_qb64pe` for conversions
424-
- Check with `#mcp_qb64pe_search_qb64pe_compatibility`
548+
- Use `#qb64pe_analyze_qbasic_compatibility` for legacy code
549+
- Apply `#qb64pe_port_qbasic_to_qb64pe` for conversions
550+
- Check with `#qb64pe_search_qb64pe_compatibility`
551+
552+
### MCP Setup
553+
In `.vscode/mcp.json`:
554+
```json
555+
{
556+
"servers": {
557+
"qb64pe": {
558+
"command": "node",
559+
"args": ["C:/Users/grymmjack/git/qb64pe-mcp-server/build/index.js"],
560+
"env": {}
561+
}
562+
},
563+
}
564+
```
565+
> Then save the file, open extensions, find the MCP server, choose settings
566+
> and grant it model access.
425567
426568
### MCP Tool Configuration
427569
The workspace includes MCP server configuration in `.vscode/settings.json`:
428570
```jsonc
429571
"chat.mcp.serverSampling": {
430572
"QB64_GJ_LIB/.vscode/mcp.json: qb64pe": {
431-
"allowedModels": ["copilot/claude-3.5-sonnet", ...]
573+
"allowedModels": ["copilot/claude-4.0-sonnet", "copilot/claude-3.5-sonnet", ...]
432574
}
433575
}
434576
```

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
"label": "IMAGE: Open in Aseprite",
284284
"type": "shell",
285285
"windows": {
286-
"command": "C:\\Program Files\\Aseprite\\aseprite.exe",
286+
"command": "F:\\SteamLibrary\\steamapps\\common\\Aseprite\\Aseprite.exe",
287287
"args": [
288288
"${file}"
289289
]

0 commit comments

Comments
 (0)