TextureAtom.fromJson constructor

TextureAtom.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory TextureAtom.fromJson(Map<String, dynamic> json) {
  final ix1 = int.parse(json['ix1']);
  final iy1 = int.parse(json['iy1']);
  final ix2 = int.parse(json['ix2']);
  final iy2 = int.parse(json['iy2']);
  final textureName = json['texname'] as String;
  final frames = int.parse(json['frames']);
  final fps = int.parse(json['fps']).clamp(1, 10000);
  final ln = Engine.texture.getTextureByName(textureName)?.len ?? 1;
  final hg = Engine.texture.getTextureByName(textureName)?.hgt ?? 1;
  final tx1 = ix1 / ln;
  final ty1 = iy1 / hg;
  final tx2 = ix2 / ln;
  final ty2 = iy2 / hg;
  final len = (ix1 - ix2).abs();
  final hgt = (iy1 - iy2).abs();
  final tl = ln;
  final th = hg;
  return TextureAtom(tx1, ty1, tx2, ty2, textureName, fps, frames, tl, th)
    ..hgt = hgt
    ..len = len
    ..iy1 = iy1
    ..iy2 = iy2
    ..ix1 = ix1
    ..ix2 = ix2;
}