56 lines
1.8 KiB
Dart
56 lines
1.8 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:archive/archive.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:flutter_svga/src/proto/svga.pbserver.dart';
|
|
|
|
void main() {
|
|
test('dump svga catalog', () async {
|
|
const path =
|
|
'sc_images/room/anim/luck_gift/kojuyee_reback_banner.svga';
|
|
final rawBytes = File(path).readAsBytesSync();
|
|
final inflatedBytes = const ZLibDecoder().decodeBytes(rawBytes);
|
|
final movie = MovieEntity.fromBuffer(inflatedBytes);
|
|
final outputDir = Directory('/tmp/luck_gift_svga_catalog');
|
|
outputDir.createSync(recursive: true);
|
|
|
|
final metadata = <Map<String, Object?>>[];
|
|
for (final key in movie.images.keys) {
|
|
final bytes = movie.images[key]!;
|
|
File('${outputDir.path}/$key.png').writeAsBytesSync(bytes);
|
|
|
|
final sprites =
|
|
movie.sprites.where((sprite) => sprite.imageKey == key).toList();
|
|
final firstFrame = sprites.isNotEmpty && sprites.first.frames.isNotEmpty
|
|
? sprites.first.frames.first
|
|
: null;
|
|
metadata.add({
|
|
'key': key,
|
|
'bytes': bytes.length,
|
|
'spriteCount': sprites.length,
|
|
'layout': firstFrame == null
|
|
? null
|
|
: {
|
|
'x': firstFrame.layout.x,
|
|
'y': firstFrame.layout.y,
|
|
'width': firstFrame.layout.width,
|
|
'height': firstFrame.layout.height,
|
|
},
|
|
'transform': firstFrame == null
|
|
? null
|
|
: {
|
|
'a': firstFrame.transform.a,
|
|
'd': firstFrame.transform.d,
|
|
'tx': firstFrame.transform.tx,
|
|
'ty': firstFrame.transform.ty,
|
|
},
|
|
});
|
|
}
|
|
|
|
File('${outputDir.path}/metadata.json').writeAsStringSync(
|
|
const JsonEncoder.withIndent(' ').convert(metadata),
|
|
);
|
|
});
|
|
}
|