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; 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); }); }