characterbook_file_formats 1.0.0
characterbook_file_formats: ^1.0.0 copied to clipboard
A pure Dart library for reading and writing CharacterBook file formats (.character, .race, .chax) and JSON.
characterbook_file_formats #
A pure Dart library for reading and writing file formats used by the CharacterBook application:
.characterβ character sheets.raceβ race descriptions.chaxβ character templates- plus standard JSON exports
No Flutter, Hive, or UI dependencies. Use it in any Dart project: CLI tools, servers, or other Flutter packages.
π Installation #
Add to your pubspec.yaml:
dependencies:
characterbook_file_formats: ^1.0.0
Then run:
dart pub get
π Usage #
Reading a file #
import 'dart:io';
import 'package:characterbook_file_formats/characterbook_file_formats.dart';
void main() async {
final file = File('aragorn.character');
final character = await CharacterBookFileParser.readFile(file) as Character;
print('Name: ${character.name}');
print('Race: ${character.race?.name}');
}
Writing an object to a file #
import 'dart:io';
import 'package:characterbook_file_formats/characterbook_file_formats.dart';
void main() async {
final elfRace = Race(
id: 'elves_high',
name: 'High Elves',
description: 'An ancient and wise race.',
lastEdited: DateTime.now(),
);
final file = File('high_elves.race');
await CharacterBookFileParser.writeFile(file, elfRace);
}
Manual JSON handling #
import 'dart:convert';
import 'package:characterbook_file_formats/characterbook_file_formats.dart';
void main() {
const jsonString = '{"id":"123","name":"Gandalf",...}';
final jsonMap = jsonDecode(jsonString) as Map<String, dynamic>;
final character = Character.fromJson(jsonMap);
// Back to JSON
final backToJson = jsonEncode(character.toJson());
}
π§© Supported Models #
| Model | File Extension | Purpose |
|---|---|---|
Character |
.character |
Complete RPG character sheet |
Race |
.race |
Race description, biology, and lore |
QuestionnaireTemplate |
.chax |
Template for quick character creation |
Relationship |
β | Connections between characters (JSON export) |
Note |
β | Notes linked to characters |
Folder |
β | Folder structure (type, color, contents) |
CustomField |
β | Additional keyβvalue fields for sheets |
All models support:
toJson()/fromJson()copyWith()- overridden
==andhashCode - immutability (
@immutable)
π Automatic File Type Detection #
The CharacterBookFileParser utility detects the data type from JSON content:
final json = jsonDecode(await file.readAsString());
final type = CharacterBookFileParser.detectType(json);
// CharacterBookFileType.character, .race, .template, .unknown
π§ͺ Testing #
The library includes a comprehensive unit test suite. Run it locally with:
dart pub get
dart test
π€ Contributing #
Pull requests and bug reports are welcome!
Main application repository: CharacterBook.
π License #
MIT License. See the LICENSE file.
π Related Projects #
- CharacterBook β original Flutter application.
- Pub.dev β package page.