feat: imported input-box pets, with dsh-Go's sprite packs
Nothing is built in: Settings → 宠物 shows "尚未导入宠物" until a zip is picked. The zip holds a dsh-Go pack.json and PNG sheets; it is validated (pack.json, every named sheet) and unpacked under the app's private files directory, with enable, size (40/52/64) and remove kept on the device. A pack's canvas, anchor, per-animation box and frame list drive rendering: PetSlot reserves the area above the baseline and stands the sprite on the composer's top edge (or on the activity cap while a turn runs). Idle, thinking, working and error follow the chat's state, and a tap plays the pack's react-left/react-right. Only one sheet is decoded at a time. path_provider's JNI binding does not load on this engine, so MainActivity exposes the files directory over a tiny method channel instead. dist/deepy-whale-pet.zip is the Deepy whale for testing. Tests cover the real pack manifest, frame/state mapping and zip import. 0.4.0 (400).
This commit is contained in:
1 parent
ff0dbf1b37
commit
d72af036a1
16 files changed
+1410
-12
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:openchamber/pets/pet_pack.dart';
|
||||
|
||||
void main() {
|
||||
test('the deepy pack parses into canvas, states and animations', () {
|
||||
final json = jsonDecode(File('test/fixtures/deepy-pack.json').readAsStringSync())
|
||||
as Map<String, dynamic>;
|
||||
final pack = PetPack.fromJson(json);
|
||||
|
||||
expect(pack.isValid, isTrue);
|
||||
expect(pack.id, 'deepy-whale');
|
||||
expect(pack.name, 'Deepy 小鲸鱼');
|
||||
expect(pack.canvas.width, closeTo(52, 0.001));
|
||||
expect(pack.canvas.height, closeTo(52, 0.001));
|
||||
expect(pack.anchor.dy, closeTo(48, 0.001));
|
||||
|
||||
expect(pack.animationForState('idle'), 'idle');
|
||||
expect(pack.animationForState('thinking'), 'thinking');
|
||||
expect(pack.animationForState('working'), 'typing');
|
||||
expect(pack.animationForState('attention'), 'happy');
|
||||
expect(pack.animationForState('missing'), 'idle');
|
||||
|
||||
final idle = pack.animation('idle')!;
|
||||
expect(idle.frames, isNotEmpty);
|
||||
expect(idle.frames.first.index, 0);
|
||||
expect(idle.loop, isTrue);
|
||||
// The frame is the box at the pack's 5x export.
|
||||
expect(idle.frameW, (idle.box.width * 5).round());
|
||||
expect(idle.frameH, (idle.box.height * 5).round());
|
||||
// 52 frames in a 21-column sheet, so the sheet has several rows.
|
||||
expect(idle.frames.map((f) => f.index).reduce((a, b) => a > b ? a : b),
|
||||
greaterThan(idle.cols));
|
||||
|
||||
expect(pack.reactions['tapLeft'], 'react-left');
|
||||
expect(pack.reactions['tapRight'], 'react-right');
|
||||
});
|
||||
|
||||
test('frames default to one column when the pack omits the list', () {
|
||||
final pack = PetPack.fromJson({
|
||||
'id': 'p',
|
||||
'canvas': {'w': 8, 'h': 8},
|
||||
'animations': {
|
||||
'idle': {
|
||||
'sheet': 'idle.png',
|
||||
'frameW': 40,
|
||||
'frameH': 40,
|
||||
'cols': 4,
|
||||
'ms': 400,
|
||||
'box': {'x': 0, 'y': 0, 'w': 8, 'h': 8},
|
||||
},
|
||||
},
|
||||
'states': {
|
||||
'idle': ['idle'],
|
||||
},
|
||||
});
|
||||
expect(pack.isValid, isTrue);
|
||||
final idle = pack.animation('idle')!;
|
||||
expect(idle.frames.length, 4);
|
||||
expect(idle.frames.first.ms, 100);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user