Skip to content

Commit 8515420

Browse files
committed
feat: update shader asset management by copying shaders to assets/shaders_text and adjusting paths
1 parent dd60417 commit 8515420

File tree

7 files changed

+24
-23
lines changed

7 files changed

+24
-23
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- name: Get dependencies
3535
run: flutter pub get
3636

37+
- name: Copy shaders to assets
38+
run: dart scripts/copy_shaders.dart
39+
3740
- name: Build web
3841
run: flutter build web --release --base-href /shaders_gallery/
3942

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ app.*.map.json
4343
/android/app/debug
4444
/android/app/profile
4545
/android/app/release
46-
assets/shaders/
46+
assets/shaders_text/

lib/noise_shader_builder.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter_shaders/flutter_shaders.dart';
32
import 'dart:ui';
43
import 'shader_builder.dart';
54

lib/shader_source_viewer.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ class _ShaderSourceViewerState extends State<ShaderSourceViewer> {
2929
Future<void> _loadShaderSource() async {
3030
try {
3131
// Convert shader path to asset path
32-
// e.g., 'shaders/crt_shader.frag' -> 'assets/shaders/crt_shader.frag'
32+
// e.g., 'shaders/crt_shader.frag' -> 'assets/shaders_text/crt_shader.frag'
3333
String assetPath = widget.assetKey;
3434
if (assetPath.startsWith('shaders/')) {
35-
assetPath = 'assets/$assetPath';
35+
final basename = assetPath.split('/').last;
36+
assetPath = 'assets/shaders_text/$basename';
3637
}
3738

3839
final source = await rootBundle.loadString(assetPath);
@@ -116,6 +117,7 @@ class _ShaderSourceViewerState extends State<ShaderSourceViewer> {
116117
_sourceCode!,
117118
style: const TextStyle(
118119
fontFamily: 'Roboto Mono',
120+
fontFamilyFallback: <String>["Courier"],
119121
fontSize: 12,
120122
color: Colors.green,
121123
),

lib/widgets/shader_control_panel.dart

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ import 'package:shaders/shader_source_viewer.dart';
33
import '../main.dart';
44

55
/// A tabbed panel that displays shader controls and source code.
6-
///
6+
///
77
/// This widget provides two tabs:
88
/// - Controls: Custom shader-specific controls built by the shader builder
99
/// - Source: The shader source code with syntax highlighting and copy functionality
1010
class ShaderControlPanel extends StatelessWidget {
1111
final ShaderInfo shaderInfo;
1212

13-
const ShaderControlPanel({
14-
super.key,
15-
required this.shaderInfo,
16-
});
13+
const ShaderControlPanel({super.key, required this.shaderInfo});
1714

1815
@override
1916
Widget build(BuildContext context) {
@@ -34,14 +31,14 @@ class ShaderControlPanel extends StatelessWidget {
3431
padding: const EdgeInsets.all(16),
3532
child: shaderInfo.builder.buildControls(context),
3633
),
37-
SizedBox()
38-
// Padding(
39-
// padding: const EdgeInsets.all(16),
40-
// child: ShaderSourceViewer(
41-
// assetKey: shaderInfo.assetKey,
42-
// shaderName: shaderInfo.name,
43-
// ),
44-
// ),
34+
35+
Padding(
36+
padding: const EdgeInsets.all(16),
37+
child: ShaderSourceViewer(
38+
assetKey: shaderInfo.assetKey,
39+
shaderName: shaderInfo.name,
40+
),
41+
),
4542
],
4643
),
4744
),

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ flutter:
3232
uses-material-design: true
3333

3434
assets:
35-
- assets/shaders/
35+
- assets/shaders_text/
3636

3737
shaders:
3838
- shaders/crt_shader.frag

scripts/copy_shaders.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import 'dart:io';
44
import 'dart:async';
55

6-
/// Script to copy shader files from shaders/ directory to assets/shaders/
6+
/// Script to copy shader files from shaders/ directory to assets/shaders_text/
77
/// This allows the shader source code to be viewed in the app
88
Future<void> main() async {
99
print('🔧 Copying shader files to assets directory...');
1010

1111
final shaderDir = Directory('shaders');
12-
final assetsShaderDir = Directory('assets/shaders');
12+
final assetsShaderDir = Directory('assets/shaders_text');
1313

1414
// Ensure assets/shaders directory exists
1515
if (!await assetsShaderDir.exists()) {
@@ -32,10 +32,10 @@ Future<void> main() async {
3232
// Copy each shader file to assets/shaders
3333
for (final shaderFile in shaderFiles) {
3434
final fileName = shaderFile.path.split('/').last;
35-
final targetFile = File('assets/shaders/$fileName');
36-
35+
final targetFile = File('assets/shaders_text/$fileName');
36+
3737
await shaderFile.copy(targetFile.path);
38-
print('✅ Copied $fileName to assets/shaders/');
38+
print('✅ Copied $fileName to assets/shaders_text/');
3939
}
4040

4141
print('🎉 Successfully copied ${shaderFiles.length} shader files!');

0 commit comments

Comments
 (0)