reloadTexture method
Reads path's texture again (it changed on disk). What it was is
drawn until the new one arrives; then the materials made with it are
made again.
Implementation
void reloadTexture(String path) {
final known = _textures[path];
if (known == null) return;
final shown = known.texture;
if (shown == null) {
// Still being read the first time: read afresh.
_textures.remove(path);
_forgetMaterials((m) => m.texture == path);
_revision++;
return;
}
final entry = _textures[path] = _Texture()..texture = shown;
unawaited(
read(path)
.then((bytes) => uploader.uploadImage(bytes))
.then(
(texture) {
if (!identical(_textures[path], entry) || texture == null) {
return;
}
entry.texture = texture;
_forgetMaterials((m) => m.texture == path);
_revision++;
},
onError: (Object error) {
if (identical(_textures[path], entry)) {
debugPrint('just_game_engine: no texture $path: $error');
}
},
),
);
}