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).
77 lines
2.0 KiB
Dart
77 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'appearance_prefs.dart';
|
|
import 'pets/pet_library.dart';
|
|
import 'screens/home_screen.dart';
|
|
import 'screens/servers_screen.dart';
|
|
import 'state.dart';
|
|
|
|
void main() {
|
|
runApp(const OpenChamberApp());
|
|
}
|
|
|
|
class OpenChamberApp extends StatefulWidget {
|
|
const OpenChamberApp({super.key});
|
|
@override
|
|
State<OpenChamberApp> createState() => _OpenChamberAppState();
|
|
}
|
|
|
|
class _OpenChamberAppState extends State<OpenChamberApp>
|
|
with WidgetsBindingObserver {
|
|
final AppState app = AppState();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addObserver(this);
|
|
app.init();
|
|
AppearancePrefs.instance.ensureLoaded();
|
|
PetLibrary.instance.ensureLoaded();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
// The socket often dies while the app sits in the background; nothing
|
|
// reports it, so reopen the stream and refresh the open chat on return.
|
|
if (state == AppLifecycleState.resumed) app.onResumed();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final look = AppearancePrefs.instance;
|
|
return ListenableBuilder(
|
|
listenable: Listenable.merge([app, look]),
|
|
builder: (context, _) {
|
|
final home = app.client == null
|
|
? ServersScreen(app: app)
|
|
: HomeScreen(app: app);
|
|
return MaterialApp(
|
|
title: 'OpenChamber',
|
|
themeMode: look.themeMode,
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: look.seedColor,
|
|
brightness: Brightness.light,
|
|
),
|
|
useMaterial3: true,
|
|
),
|
|
darkTheme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: look.seedColor,
|
|
brightness: Brightness.dark,
|
|
),
|
|
useMaterial3: true,
|
|
),
|
|
home: home,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|