Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flame_jenny): Allow removal of characters (#2715)
Allow characters to be removed from character storage, or character storage to be cleared. This is useful in large games where each scene may have different sets of characters. They can be cleared between scenes, and new characters loaded.
- Loading branch information
1 parent
9918c05
commit 3421f4f
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/flame_jenny/jenny/test/character_storage_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'package:jenny/src/character.dart'; | ||
import 'package:jenny/src/character_storage.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('CharacterStorage', () { | ||
test('Should store character', () { | ||
final storage = CharacterStorage(); | ||
|
||
expect(storage.isEmpty, true); | ||
|
||
final character = Character('Jenny'); | ||
storage.add(character); | ||
|
||
expect(storage.isEmpty, false); | ||
expect(storage.isNotEmpty, true); | ||
|
||
expect(storage.contains(character.name), true); | ||
}); | ||
|
||
test('Should store character aliases', () { | ||
final storage = CharacterStorage(); | ||
final character = Character('Jenny', aliases: ['Jen', 'Jennifer']); | ||
storage.add(character); | ||
|
||
expect(storage.contains(character.name), true); | ||
expect(storage.contains(character.aliases[0]), true); | ||
expect(storage.contains(character.aliases[1]), true); | ||
}); | ||
|
||
test('Should remove character and aliases by name', () { | ||
final storage = CharacterStorage(); | ||
final character = Character('Jenny', aliases: ['Jen', 'Jennifer']); | ||
storage.add(character); | ||
|
||
expect(storage.contains(character.name), true); | ||
expect(storage.contains(character.aliases[0]), true); | ||
expect(storage.contains(character.aliases[1]), true); | ||
|
||
storage.remove(character.name); | ||
|
||
expect(storage.contains(character.name), false); | ||
expect(storage.contains(character.aliases[0]), false); | ||
expect(storage.contains(character.aliases[1]), false); | ||
}); | ||
|
||
test('Should remove character and aliases by alias', () { | ||
final storage = CharacterStorage(); | ||
final character = Character('Jenny', aliases: ['Jen', 'Jennifer']); | ||
storage.add(character); | ||
|
||
expect(storage.contains(character.name), true); | ||
expect(storage.contains(character.aliases[0]), true); | ||
expect(storage.contains(character.aliases[1]), true); | ||
|
||
storage.remove(character.aliases[1]); | ||
|
||
expect(storage.contains(character.name), false); | ||
expect(storage.contains(character.aliases[0]), false); | ||
expect(storage.contains(character.aliases[1]), false); | ||
}); | ||
|
||
test('Should clear all characters', () { | ||
final storage = CharacterStorage(); | ||
storage.add(Character('Jenny', aliases: ['Jen', 'Jennifer'])); | ||
storage.add(Character('Thomas')); | ||
storage.add(Character('Leon')); | ||
|
||
storage.clear(); | ||
|
||
expect(storage.isEmpty, true); | ||
}); | ||
}); | ||
} |