Skip to content

Commit

Permalink
Remove part-of directives and clean up analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
spydon committed Dec 28, 2024
1 parent 38101fb commit f0721be
Show file tree
Hide file tree
Showing 33 changed files with 110 additions and 90 deletions.
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/chunk.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../tiled.dart';
import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
17 changes: 12 additions & 5 deletions packages/tiled/lib/src/common/color.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of tiled;
import 'package:meta/meta.dart';

/// Basic data class holding a Color in ARGB format.
/// This can be converted to dart:ui's Color using the flame_tiled package
Expand All @@ -16,28 +16,35 @@ class ColorData {

int get blue => _sub(_hex, 0);

/// Parses the Color from an int using the lower 32-bits and tiled's format: 0xaarrggbb
/// Parses the Color from an int using the lower 32-bits and tiled's format:
/// 0xaarrggbb
const ColorData.hex(this._hex);

const ColorData.rgb(int red, int green, int blue, [int alpha = 255])
: assert(red >= 0 && red <= 255),
assert(green >= 0 && green <= 255),
assert(blue >= 0 && blue <= 255),
assert(alpha >= 0 && alpha <= 255),
_hex = (alpha << 3 * 8) + (red << 2 * 8) + (green << 1 * 8) +
_hex = (alpha << 3 * 8) +
(red << 2 * 8) +
(green << 1 * 8) +
(blue << 0 * 8);

const ColorData.argb(int alpha, int red, int green, int blue)
: assert(red >= 0 && red <= 255),
assert(green >= 0 && green <= 255),
assert(blue >= 0 && blue <= 255),
assert(alpha >= 0 && alpha <= 255),
_hex = (alpha << 3 * 8) + (red << 2 * 8) + (green << 1 * 8) +
_hex = (alpha << 3 * 8) +
(red << 2 * 8) +
(green << 1 * 8) +
(blue << 0 * 8);

@override
bool operator ==(Object other) {
if (other is! ColorData) return false;
if (other is! ColorData) {
return false;
}
return _hex == other._hex;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/common/enums.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/src/parser.dart';

enum MapOrientation { orthogonal, isometric, staggered, hexagonal }

Expand Down
2 changes: 0 additions & 2 deletions packages/tiled/lib/src/common/flips.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of '../../tiled.dart';

class Flips {
final bool horizontally;
final bool vertically;
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/common/frame.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/src/parser.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/common/gid.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/tiled.dart';

/// A [Gid], Global Tile ID is a Tiled concept to represent the tiles inside
/// int matrices. This wrapper is used by [Layer] and [Chunk] to provide
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/common/point.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/src/parser.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
9 changes: 7 additions & 2 deletions packages/tiled/lib/src/common/property.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of '../../tiled.dart';
import 'package:collection/collection.dart';
import 'package:tiled/tiled.dart';
import 'package:xml/xml.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down Expand Up @@ -37,7 +39,10 @@ class Property<T> {
case PropertyType.color:
return ColorProperty(
name: name,
value: parser.getColor('value', defaults: ColorData.hex(0x00000000)),
value: parser.getColor(
'value',
defaults: const ColorData.hex(0x00000000),
),
hexValue: parser.getString('value', defaults: '#00000000'),
);

Expand Down
3 changes: 2 additions & 1 deletion packages/tiled/lib/src/common/tiled_image.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
part of '../../tiled.dart';
import 'package:meta/meta.dart';
import 'package:tiled/src/parser.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/editor_setting/chunk_size.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/src/parser.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/editor_setting/editor_setting.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/editor_setting/export.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/src/parser.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
15 changes: 10 additions & 5 deletions packages/tiled/lib/src/layer.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
part of '../tiled.dart';
import 'dart:convert';
import 'dart:typed_data';

import 'package:archive/archive.dart';
import 'package:tiled/tiled.dart';
import 'package:xml/xml.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down Expand Up @@ -77,8 +82,8 @@ abstract class Layer {
/// any graphics drawn by this layer or any child layers (optional).
String? tintColorHex;

/// [ColorData] that is multiplied with any graphics drawn by this layer or any
/// child layers (optional).
/// [ColorData] that is multiplied with any graphics drawn by this layer or
/// any child layers (optional).
///
/// Parsed from [tintColorHex], will be null if parsing fails for any reason.
ColorData? tintColor;
Expand Down Expand Up @@ -328,7 +333,7 @@ abstract class Layer {
decompressed = const ZLibDecoder().decodeBytes(decodedString);
break;
case Compression.gzip:
decompressed = GZipDecoder().decodeBytes(decodedString);
decompressed = const GZipDecoder().decodeBytes(decodedString);
break;
case Compression.zstd:
throw UnsupportedError('zstd is an unsupported compression');
Expand Down Expand Up @@ -420,7 +425,7 @@ class TileLayer extends Layer {
}

class ObjectGroup extends Layer {
static const defaultColor = ColorData.rgb(160, 160, 164, 255);
static const defaultColor = ColorData.rgb(160, 160, 164);
static const defaultColorHex = '%a0a0a4';

/// topdown (default) or index (indexOrder).
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/objects/text.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/objects/tiled_object.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
3 changes: 2 additions & 1 deletion packages/tiled/lib/src/parser.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
part of '../tiled.dart';
import 'package:tiled/tiled.dart';
import 'package:xml/xml.dart';

class ParsingException implements Exception {
final String name;
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/template.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../tiled.dart';
import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
5 changes: 4 additions & 1 deletion packages/tiled/lib/src/tile_map_parser.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
part of '../tiled.dart';
import 'dart:convert';

import 'package:tiled/tiled.dart';
import 'package:xml/xml.dart';

class TileMapParser {
static TiledMap parseJson(String json) {
Expand Down
6 changes: 5 additions & 1 deletion packages/tiled/lib/src/tiled_map.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
part of '../tiled.dart';
import 'dart:collection';

import 'package:collection/collection.dart';
import 'package:tiled/tiled.dart';
import 'package:xml/xml.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/tileset/grid.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/tileset/terrain.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
4 changes: 3 additions & 1 deletion packages/tiled/lib/src/tileset/tile.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of '../../tiled.dart';
import 'dart:math';

import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/tileset/tile_offset.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../tiled.dart';
import 'package:tiled/src/parser.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
4 changes: 3 additions & 1 deletion packages/tiled/lib/src/tileset/tileset.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of '../../tiled.dart';
import 'dart:math';

import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/tileset/wang/wang_color.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../../tiled.dart';
import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/tileset/wang/wang_set.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../../../tiled.dart';
import 'package:tiled/tiled.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
4 changes: 3 additions & 1 deletion packages/tiled/lib/src/tileset/wang/wang_tile.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of '../../../tiled.dart';
import 'dart:typed_data';

import 'package:tiled/src/parser.dart';

/// Below is Tiled's documentation about how this structure is represented
/// on XML files:
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/tsx_provider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of '../tiled.dart';
import 'package:tiled/tiled.dart';

/// abstract class to be implemented for an external tileset data provider.
abstract class TsxProvider {
Expand Down
68 changes: 28 additions & 40 deletions packages/tiled/lib/tiled.dart
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
library tiled;

import 'dart:collection';
import 'dart:convert';
import 'dart:math' show Rectangle;
import 'dart:typed_data';

import 'package:archive/archive.dart';
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';
import 'package:xml/xml.dart';

part 'src/chunk.dart';
part 'src/common/enums.dart';
part 'src/common/flips.dart';
part 'src/common/frame.dart';
part 'src/common/gid.dart';
part 'src/common/point.dart';
part 'src/common/property.dart';
part 'src/common/tiled_image.dart';
part 'src/common/color.dart';
part 'src/editor_setting/chunk_size.dart';
part 'src/editor_setting/editor_setting.dart';
part 'src/editor_setting/export.dart';
part 'src/layer.dart';
part 'src/objects/text.dart';
part 'src/objects/tiled_object.dart';
part 'src/parser.dart';
part 'src/template.dart';
part 'src/tile_map_parser.dart';
part 'src/tiled_map.dart';
part 'src/tileset/grid.dart';
part 'src/tileset/terrain.dart';
part 'src/tileset/tile.dart';
part 'src/tileset/tile_offset.dart';
part 'src/tileset/tileset.dart';
part 'src/tileset/wang/wang_color.dart';
part 'src/tileset/wang/wang_set.dart';
part 'src/tileset/wang/wang_tile.dart';
part 'src/tsx_provider.dart';
export 'src/chunk.dart';
export 'src/common/color.dart';
export 'src/common/enums.dart';
export 'src/common/flips.dart';
export 'src/common/frame.dart';
export 'src/common/gid.dart';
export 'src/common/point.dart';
export 'src/common/property.dart';
export 'src/common/tiled_image.dart';
export 'src/editor_setting/chunk_size.dart';
export 'src/editor_setting/editor_setting.dart';
export 'src/editor_setting/export.dart';
export 'src/layer.dart';
export 'src/objects/text.dart';
export 'src/objects/tiled_object.dart';
export 'src/parser.dart';
export 'src/template.dart';
export 'src/tile_map_parser.dart';
export 'src/tiled_map.dart';
export 'src/tileset/grid.dart';
export 'src/tileset/terrain.dart';
export 'src/tileset/tile.dart';
export 'src/tileset/tile_offset.dart';
export 'src/tileset/tileset.dart';
export 'src/tileset/wang/wang_color.dart';
export 'src/tileset/wang/wang_set.dart';
export 'src/tileset/wang/wang_tile.dart';
export 'src/tsx_provider.dart';
4 changes: 2 additions & 2 deletions packages/tiled/test/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:test/scaffolding.dart';
import 'package:tiled/tiled.dart';

void main() {
group("ColorData.hex", () {
test("parse", () {
group('ColorData.hex', () {
test('parse', () {
final random = Random();
final red = random.nextInt(256);
final green = random.nextInt(256);
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/test/image_layer_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:io';

import 'package:tiled/tiled.dart';
import 'package:test/test.dart';
import 'package:tiled/tiled.dart';

void main() {
late TiledMap map;
Expand Down
8 changes: 5 additions & 3 deletions packages/tiled/test/parser_test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:io';
import 'dart:math' show Rectangle;

import 'package:test/test.dart';
import 'package:collection/collection.dart';
import 'package:test/test.dart';
import 'package:tiled/tiled.dart';
import 'package:xml/xml.dart';

Expand Down Expand Up @@ -89,7 +89,9 @@ void main() {
);
expect(
properties.getValue<String>('multiline string'),
equals('Hello,\r\nWorld'),
Platform.isWindows
? equals('Hello,\r\nWorld')
: equals('Hello,\nWorld'),
);
expect(
properties.getValue<int>('integer property'),
Expand All @@ -101,7 +103,7 @@ void main() {
);
expect(
properties.getValue<ColorData>('color property'),
equals(ColorData.hex(0x00112233)),
equals(const ColorData.hex(0x00112233)),
);
expect(
properties.getValue<double>('float property'),
Expand Down
Loading

0 comments on commit f0721be

Please sign in to comment.