Skip to content

Commit

Permalink
Restructure code
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Apr 13, 2024
1 parent bbc005f commit 1f3a4fd
Show file tree
Hide file tree
Showing 20 changed files with 1,041 additions and 254 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
*.iws
.idea/
.vscode/

*.mapper.dart
3 changes: 3 additions & 0 deletions app/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ analyzer:
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "build/**/*.dart"
- "lib/src/rust/*.dart"
- "lib/src/rust/**/*.dart"
errors:
invalid_annotation_target: ignore
linter:
Expand Down
3 changes: 3 additions & 0 deletions app/lib/game/board/game.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:flame/game.dart';

class BoardGame extends FlameGame {}
3 changes: 3 additions & 0 deletions app/lib/game/board/grid.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:flame/components.dart';

class BoardGrid extends Component {}
16 changes: 10 additions & 6 deletions app/lib/game/board.dart → app/lib/game/world/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import 'package:flame/game.dart';
import 'package:flame_tiled/flame_tiled.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:qeck/game/inventory.dart';
import 'package:qeck/game/player.dart';
import 'package:qeck/game/wall.dart';
import 'package:qeck/game/world/inventory.dart';
import 'package:qeck/game/world/player.dart';
import 'package:qeck/game/world/wall.dart';
import 'package:qeck/services/network.dart';

class SpacedSpriteSheet {
Expand All @@ -34,7 +34,7 @@ class SpacedSpriteSheet {
}
}

class BoardGame extends FlameGame with KeyboardEvents, HasCollisionDetection {
class GameWorld extends FlameGame with KeyboardEvents, HasCollisionDetection {
final NetworkingService networkingService;
final BoardPlayer _player = BoardPlayer(true);
final Map<int, BoardPlayer> _players = <int, BoardPlayer>{};
Expand All @@ -43,7 +43,7 @@ class BoardGame extends FlameGame with KeyboardEvents, HasCollisionDetection {
Vector2 get tileSize => _tileSize;
final VoidCallback onEscape;

BoardGame({
GameWorld({
required this.networkingService,
required this.onEscape,
});
Expand All @@ -52,7 +52,11 @@ class BoardGame extends FlameGame with KeyboardEvents, HasCollisionDetection {

@override
Future<void> onLoad() async {
final component = await TiledComponent.load('map.tmx', _tileSize);
final component = await TiledComponent.load(
'map.tmx',
_tileSize,
useAtlas: false,
);

final objects = component.tileMap.getLayer<ObjectGroup>('Objects')?.objects;
final spawn = objects?.firstWhere(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dart:ui';
import 'package:flame/components.dart';
import 'package:flame/events.dart';
import 'package:flame/flame.dart';
import 'package:qeck/game/board.dart';
import 'package:qeck/game/world/game.dart';

class HudSpriteSheet {
final SpacedSpriteSheet _spriteSheet;
Expand Down
6 changes: 3 additions & 3 deletions app/lib/game/player.dart → app/lib/game/world/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:flame/effects.dart';
import 'package:flame/extensions.dart';
import 'package:flame/flame.dart';
import 'package:flame/text.dart';
import 'package:qeck/game/board.dart';
import 'package:qeck/game/wall.dart';
import 'package:qeck/game/world/game.dart';
import 'package:qeck/game/world/wall.dart';
import 'package:qeck/models/message.dart';
import 'package:qeck/models/state.dart';

Expand Down Expand Up @@ -50,7 +50,7 @@ extension RendererExtension on PlayerState {

class BoardPlayer
extends SpriteAnimationGroupComponent<(PlayerState, PlayerDirection)>
with HasGameRef<BoardGame>, CollisionCallbacks {
with HasGameRef<GameWorld>, CollisionCallbacks {
final bool isSelf;
NetworkingUser _user;

Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ String? dataPath;

Future<void> main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();

usePathUrlStrategy();

final argParser = ArgParser();
argParser.addOption('path', abbr: 'p');
final result = argParser.parse(args);
Expand All @@ -44,7 +44,7 @@ Future<void> main(List<String> args) async {
value: settingsCubit,
child: RepositoryProvider(
create: (context) => NetworkingService(settingsCubit),
child: FlowApp(),
child: QeckApp(),
),
),
);
Expand Down Expand Up @@ -74,8 +74,8 @@ List<Locale> getLocales() =>
.where((l) => !kUnsupportedLanguages.contains(l.toString()))
.toList();

class FlowApp extends StatelessWidget {
FlowApp({super.key});
class QeckApp extends StatelessWidget {
QeckApp({super.key});

@override
Widget build(BuildContext context) {
Expand Down
53 changes: 53 additions & 0 deletions app/lib/models/table.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:dart_mappable/dart_mappable.dart';

part 'table.mapper.dart';

@MappableClass()
class GridLocation with GridLocationMappable {
final int x, y;

GridLocation(this.x, this.y);
}

@MappableClass()
class GameTable with GameTableMappable {
final Map<GridLocation, TableCell> cells;
final Map<GridLocation, GameBoard> boards;

GameTable({
this.cells = const {},
this.boards = const {},
});
}

@MappableClass()
class TableCell with TableCellMappable {
final List<GameObject> objects;

TableCell(this.objects);
}

@MappableClass()
class GameBoard with GameBoardMappable {
final AssetLocation asset;

GameBoard(this.asset);
}

@MappableClass()
class GameObject with GameObjectMappable {
final AssetLocation asset;
final String? variation;

GameObject({
required this.asset,
this.variation,
});
}

@MappableClass()
class AssetLocation with AssetLocationMappable {
final String namespace, id;

AssetLocation(this.namespace, this.id);
}
Loading

0 comments on commit 1f3a4fd

Please sign in to comment.