kuhy_credit: Flutter example, CI fixes
Some checks are pending
file length / file-length (push) Waiting to run
kuhy_credit drift / drift (push) Waiting to run
kuhy_credit tests / python (push) Waiting to run
kuhy_credit tests / web (push) Waiting to run
kuhy_credit tests / flutter (push) Waiting to run
kuhy_credit tests / godot (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run

- Flutter example gets its android and web platform dirs (label
  "Credit" for the launcher contract); logo painter moves to a part
  file to stay under 250 lines.
- Godot click tests size the headless window to 640x360 (the official
  build opens 64x64 and drops clicks outside it) and hide GUT's GUI.
- godot/test.sh writes godot output to files, not $(...), and fails
  when fewer tests ran than tests/ declares.
- README Python snippet passes ruff format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-20 16:49:46 +01:00
parent 826f9946e8
commit d696189a2e
40 changed files with 511 additions and 47 deletions

View File

@ -121,6 +121,7 @@ bash kuhy_credit/terminal/kuhy-credit.sh # no Python needed
```python
from kuhy_credit import credit_line
print(credit_line()) # Created by kuhy https://kuhy.duckdns.org
```

48
kuhy_credit/flutter/example/.gitignore vendored Normal file
View File

@ -0,0 +1,48 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/
/coverage/
# Symbolication related
app.*.symbols
# Obfuscation related
app.*.map.json
# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
# Widget Preview related
.widget_preview/

View File

@ -0,0 +1,33 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: "ab2912035e160d9cad6306df307576da6128ebdb"
channel: "stable"
project_type: app
# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: ab2912035e160d9cad6306df307576da6128ebdb
base_revision: ab2912035e160d9cad6306df307576da6128ebdb
- platform: android
create_revision: ab2912035e160d9cad6306df307576da6128ebdb
base_revision: ab2912035e160d9cad6306df307576da6128ebdb
- platform: web
create_revision: ab2912035e160d9cad6306df307576da6128ebdb
base_revision: ab2912035e160d9cad6306df307576da6128ebdb
# User provided section
# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'

View File

@ -1,4 +1,6 @@
analyzer:
exclude:
- build/**
- android/**
- web/**
include: package:very_good_analysis/analysis_options.yaml

View File

@ -0,0 +1,14 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
.cxx/
# Remember to never publicly share your keystore.
# See https://flutter.dev/to/reference-keystore
key.properties
**/*.keystore
**/*.jks

View File

@ -0,0 +1,49 @@
plugins {
id("com.android.application")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}
android {
namespace = "com.kuhy.kuhy_credit_example"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.kuhy.kuhy_credit_example"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
// Uses the version code from pubspec.yaml. When using split APKs, 1000 * ABI_VERSION
// is added automatically by Flutter. (https://developer.android.com/studio/build/configure-apk-splits#configure-APK-versions)
// You can force using the value of versionCode by specifying the `-P force-version-code-ignoring-abi=true`
// flag during build.
versionCode = flutter.versionCode
versionName = flutter.versionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
}
}
}
kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}
flutter {
source = "../.."
}

View File

@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@ -0,0 +1,45 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="Credit"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>

View File

@ -0,0 +1,5 @@
package com.kuhy.kuhy_credit_example
import io.flutter.embedding.android.FlutterActivity
class MainActivity : FlutterActivity()

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>

View File

@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@ -0,0 +1,24 @@
allprojects {
repositories {
google()
mavenCentral()
}
}
val newBuildDir: Directory =
rootProject.layout.buildDirectory
.dir("../../build")
.get()
rootProject.layout.buildDirectory.value(newBuildDir)
subprojects {
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
project.layout.buildDirectory.value(newSubprojectBuildDir)
}
subprojects {
project.evaluationDependsOn(":app")
}
tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}

View File

@ -0,0 +1,6 @@
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
# This newDsl flag was added by the Flutter template
android.newDsl=false
# This builtInKotlin flag was added by the Flutter template
android.builtInKotlin=false

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-all.zip

View File

@ -0,0 +1,26 @@
pluginManagement {
val flutterSdkPath =
run {
val properties = java.util.Properties()
file("local.properties").inputStream().use { properties.load(it) }
val flutterSdkPath = properties.getProperty("flutter.sdk")
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
flutterSdkPath
}
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "9.3.1" apply false
id("org.jetbrains.kotlin.android") version "2.4.20" apply false
}
include(":app")

View File

@ -264,10 +264,10 @@ packages:
dependency: transitive
description:
name: vector_math
sha256: fa49e1674cb84acb900141714e6c6e1f9ae099827c24d141430ff6819db4e1bc
sha256: "92b9910f66ed1057fd4da7b040ae7c74cafacf885bdc81be496928d5049b032d"
url: "https://pub.dev"
source: hosted
version: "2.4.4"
version: "2.4.3"
very_good_analysis:
dependency: "direct dev"
description:

Binary file not shown.

After

Width:  |  Height:  |  Size: 917 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="$FLUTTER_BASE_HREF">
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<!--
Uncomment the tag below to lay the app out underneath the parts of the
screen that the device obstructs, such as a display cutout, the rounded
corners of the screen, or a home indicator.
Without it, the browser keeps the app clear of them, and `SafeArea` and
`MediaQuery.paddingOf` report no padding. With it, the app covers the whole
screen, and it is up to the app to keep its own content out of the way,
which is what `SafeArea` is for.
-->
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover"> -->
<!-- iOS meta tags & icons -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="kuhy_credit_example">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<title>kuhy_credit_example</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<!--
You can customize the "flutter_bootstrap.js" script.
This is useful to provide a custom configuration to the Flutter loader
or to give the user feedback during the initialization process.
For more details:
* https://docs.flutter.dev/platform-integration/web/initialization
-->
<script src="flutter_bootstrap.js" async></script>
</body>
</html>

View File

@ -0,0 +1,35 @@
{
"name": "kuhy_credit_example",
"short_name": "kuhy_credit_example",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
{
"src": "icons/Icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "icons/Icon-maskable-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icons/Icon-maskable-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
]
}

View File

@ -5,6 +5,8 @@ import 'package:flutter/widgets.dart';
import 'package:kuhy_credit/src/credit_data.g.dart';
import 'package:url_launcher/url_launcher.dart';
part 'kuhy_credit_logo.dart';
/// Opens [uri] in the system browser: a new tab on web, the browser app on
/// Android.
Future<void> openInBrowser(Uri uri) async {
@ -230,38 +232,3 @@ class _Panel extends StatelessWidget {
);
}
}
class _Logo extends StatelessWidget {
const _Logo({required this.size});
final double size;
@override
Widget build(BuildContext context) {
return CustomPaint(size: Size.square(size), painter: const _LogoPainter());
}
}
class _LogoPainter extends CustomPainter {
const _LogoPainter();
@override
void paint(Canvas canvas, Size size) {
canvas
..scale(size.width / kLogoSize)
..drawRect(
const Rect.fromLTWH(0, 0, kLogoSize, kLogoSize),
Paint()..color = const Color(kLogoField),
);
for (final (fill, points) in kLogoShapes) {
final path = Path()..moveTo(points[0], points[1]);
for (var i = 2; i < points.length; i += 2) {
path.lineTo(points[i], points[i + 1]);
}
canvas.drawPath(path..close(), Paint()..color = Color(fill));
}
}
@override
bool shouldRepaint(_LogoPainter oldDelegate) => false;
}

View File

@ -0,0 +1,36 @@
part of 'kuhy_credit.dart';
class _Logo extends StatelessWidget {
const _Logo({required this.size});
final double size;
@override
Widget build(BuildContext context) {
return CustomPaint(size: Size.square(size), painter: const _LogoPainter());
}
}
class _LogoPainter extends CustomPainter {
const _LogoPainter();
@override
void paint(Canvas canvas, Size size) {
canvas
..scale(size.width / kLogoSize)
..drawRect(
const Rect.fromLTWH(0, 0, kLogoSize, kLogoSize),
Paint()..color = const Color(kLogoField),
);
for (final (fill, points) in kLogoShapes) {
final path = Path()..moveTo(points[0], points[1]);
for (var i = 2; i < points.length; i += 2) {
path.lineTo(points[i], points[i + 1]);
}
canvas.drawPath(path..close(), Paint()..color = Color(fill));
}
}
@override
bool shouldRepaint(_LogoPainter oldDelegate) => false;
}

View File

@ -75,12 +75,18 @@ main() {
trap cleanup EXIT
export XDG_DATA_HOME="$TMP/xdg"
# GUT's own class_names need a class cache before a script run.
local imported
imported="$(godot_run --headless --path "$HERE" --import 2>&1)" || true
local out code=0 start="$SECONDS"
out="$(godot_run --headless --audio-driver Dummy \
--path "$HERE" -s addons/gut/gut_cmdln.gd -gexit "$@" 2>&1)" || code=$?
local tests passing failing pending why=""
# Output goes to files, not $(...): the godot build-lock shim may hold a
# child that keeps a command-substitution pipe open (a deadlock).
godot_run --headless --path "$HERE" --import >"$TMP/import.log" 2>&1 || true
local imported out code=0 start="$SECONDS"
imported="$(<"$TMP/import.log")"
godot_run --headless --audio-driver Dummy \
--path "$HERE" -s addons/gut/gut_cmdln.gd -gexit "$@" >"$TMP/gut.log" 2>&1 || code=$?
out="$(<"$TMP/gut.log")"
local tests passing failing pending why="" declared
# Every test_* function must run: a script that fails to parse is dropped
# by GUT without a failure, so count what the files declare.
declared="$(cat "$HERE"/tests/test_*.gd | grep -c '^func test_')"
tests="$(total_of Tests "$out")"
passing="$(total_of "Passing Tests" "$out")"
failing="$(total_of "Failing Tests" "$out")"
@ -93,6 +99,8 @@ main() {
why="exit code $code"
elif ((tests == 0)); then
why="no tests ran"
elif (($# == 0 && tests != declared)); then
why="ran $tests tests but tests/ declares $declared (a script failed to load?)"
elif ((tests != passing + pending)); then
why="tests $tests != passing $passing + pending $pending"
fi

View File

@ -0,0 +1,25 @@
extends GutTest
## Base for tests that click. GUT's own full-window GUI sits on a CanvasLayer
## above the scene and swallows pushed mouse events, so it is hidden while
## these tests run. The headless window of the official Godot build is 64x64,
## and a click outside the window is dropped, so the window takes the
## project's 640x360 size for these tests.
const TEST_WINDOW := Vector2i(640, 360)
var _gut_layers: Array[Node] = []
var _old_size: Vector2i
func before_all() -> void:
_old_size = get_window().size
get_window().size = TEST_WINDOW
_gut_layers = get_tree().root.find_children("GutLayer", "CanvasLayer", true, false)
for layer in _gut_layers:
layer.visible = false
func after_all() -> void:
for layer in _gut_layers:
layer.visible = true
get_window().size = _old_size

View File

@ -0,0 +1 @@
uid://dj5wof521mjvp

View File

@ -0,0 +1 @@
uid://c1xqry5othtbb

View File

@ -1,4 +1,4 @@
extends GutTest
extends "res://tests/click_test.gd"
## E2E: the demo scene, two clicks through the viewport, the URL that would open.
const CreditData = preload("res://addons/kuhy_credit/credit_data.gd")
@ -12,7 +12,7 @@ func _click(at: Vector2) -> void:
ev.pressed = pressed
ev.position = at
ev.global_position = at
get_viewport().push_input(ev)
get_viewport().push_input(ev, true)
await wait_process_frames(2)

View File

@ -1,4 +1,4 @@
extends GutTest
extends "res://tests/click_test.gd"
## The credit control: logo -> panel -> URL, every close path, theme tokens.
## Input goes through the viewport (push_input), as a real click would.
@ -25,7 +25,7 @@ func _click_at(pos: Vector2) -> void:
ev.pressed = pressed
ev.position = pos
ev.global_position = pos
get_viewport().push_input(ev)
get_viewport().push_input(ev, true)
await wait_process_frames(2)

View File

@ -137,6 +137,7 @@ HAND_WRITTEN = [
"web/src/kuhy-credit.js",
"web/demo/index.html",
"flutter/lib/src/kuhy_credit.dart",
"flutter/lib/src/kuhy_credit_logo.dart",
"flutter/example/lib/main.dart",
"godot/addons/kuhy_credit/kuhy_credit.gd",
"godot/demo/demo.gd",