Skip to content

Commit

Permalink
character hash
Browse files Browse the repository at this point in the history
  • Loading branch information
danemadsen committed Jul 15, 2024
1 parent c540e3e commit 87705f9
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions lib/classes/providers/character.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';
import 'dart:async';
import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,7 +16,6 @@ import 'package:shared_preferences/shared_preferences.dart';
class Character extends ChangeNotifier {
File? _profile;

Key _key = UniqueKey();
bool _useSystem = true;
String _name = "Maid";
String _description = "";
Expand Down Expand Up @@ -69,7 +69,6 @@ class Character extends ChangeNotifier {
}

void from(Character character) async {
_key = character.key;
_profile = await character.profile;
_useSystem = character.useSystem;
_name = character.name;
Expand All @@ -86,7 +85,6 @@ class Character extends ChangeNotifier {
}

Future<void> fromMap(Map<String, dynamic> inputJson) async {
_key = UniqueKey();
if (inputJson["profile"] != null) {
_profile = File(inputJson["profile"]);
}
Expand Down Expand Up @@ -308,7 +306,31 @@ class Character extends ChangeNotifier {
return _profile ??= await Utilities.fileFromAssetImage("defaultCharacter.png");
}

Key get key => _key;
String get hash {
Uint8List bytes;

if(_profile != null) {
bytes = _profile!.readAsBytesSync();
} else {
List<String> hashList = [
_name,
_description,
_personality,
_scenario,
_system,
_useGreeting.toString(),
_greetings.join(),
_useExamples.toString(),
_examples.join(),
];

bytes = utf8.encode(hashList.join());
}

return sha256.convert(bytes).toString();
}

Key get key => ValueKey(hash);

String get name => _name;

Expand Down

0 comments on commit 87705f9

Please sign in to comment.