Fix runtime color alpha composition

This commit is contained in:
gem
2026-06-09 11:26:51 +08:00
parent 45ab9d7861
commit 8d2c97269a
4 changed files with 62 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ import 'package:flame_lua_runtime/runtime/models/runtime_node.dart';
import 'package:flame_lua_runtime/runtime/protocol/runtime_protocol.dart';
import 'package:flame_lua_runtime/runtime/rendering/runtime_component.dart';
import 'package:flame_lua_runtime/runtime/resources/game_resource_manager.dart';
import 'package:flutter/material.dart' show Color;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -114,6 +115,29 @@ void main() {
expect(component.renderAlpha, 1);
});
test('multiplies color alpha with node and runtime alpha', () {
expect(
composeRuntimeColorAlpha(const Color(0xffffffff), 1).a,
closeTo(1, 0.001),
);
expect(
composeRuntimeColorAlpha(const Color(0x80ffffff), 1).a,
closeTo(0.5, 0.003),
);
expect(
composeRuntimeColorAlpha(const Color(0x80ffffff), 0.5).a,
closeTo(0.25, 0.003),
);
expect(
composeRuntimeColorAlpha(const Color(0x00ffffff), 1).a,
closeTo(0, 0.001),
);
expect(
composeRuntimeColorAlpha(const Color(0x80ffffff), 0.25).a,
closeTo(0.125, 0.003),
);
});
test('multi-line non-button text is top aligned', () {
final component = RuntimeComponent(
node: const RuntimeNode(