Skip to content

Commit

Permalink
Add more figure editing fields in dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Jan 3, 2025
1 parent cd2ff9d commit c0368f1
Show file tree
Hide file tree
Showing 24 changed files with 644 additions and 249 deletions.
15 changes: 5 additions & 10 deletions api/lib/src/models/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ import 'visual.dart';
part 'background.mapper.dart';

@MappableClass()
class BackgroundDefinition with BackgroundDefinitionMappable, VisualDefinition {
@override
final VectorDefinition offset;
@override
final VectorDefinition? size;
@override
final String texture;
class BackgroundDefinition extends VisualDefinition
with BackgroundDefinitionMappable {
final int priority;

BackgroundDefinition({
this.offset = VectorDefinition.zero,
this.size,
required this.texture,
super.offset,
super.size,
required super.texture,
this.priority = 0,
});
}
6 changes: 5 additions & 1 deletion api/lib/src/models/background.mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BackgroundDefinitionMapper extends ClassMapperBase<BackgroundDefinition> {
static BackgroundDefinitionMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = BackgroundDefinitionMapper._());
VisualDefinitionMapper.ensureInitialized();
VectorDefinitionMapper.ensureInitialized();
}
return _instance!;
Expand Down Expand Up @@ -106,9 +107,12 @@ extension BackgroundDefinitionValueCopy<$R, $Out>
abstract class BackgroundDefinitionCopyWith<
$R,
$In extends BackgroundDefinition,
$Out> implements ClassCopyWith<$R, $In, $Out> {
$Out> implements VisualDefinitionCopyWith<$R, $In, $Out> {
@override
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition> get offset;
@override
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition>? get size;
@override
$R call(
{VectorDefinition? offset,
VectorDefinition? size,
Expand Down
14 changes: 12 additions & 2 deletions api/lib/src/models/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,16 @@ class SetonixData extends ArchiveData<SetonixData> {
return MapEntry(e, translation);
}).nonNulls;

PackTranslation? getTranslation(String id) {
PackTranslation? getTranslation([String id = kFallbackLocale]) {
final data = getAsset('$kPackTranslationsPath/$id.json');
if (data == null) return null;
final content = utf8.decode(data);
return PackTranslationMapper.fromJson(content);
}

PackTranslation getTranslationOrDefault([String id = kFallbackLocale]) =>
getTranslation(id) ?? PackTranslation();

SetonixData setMetadata(FileMetadata metadata) => setAsset(
kPackMetadataPath,
utf8.encode(metadata.toJson()),
Expand All @@ -209,7 +212,7 @@ class SetonixData extends ArchiveData<SetonixData> {
SetonixData(archive, state: state);

TranslationsStore getTranslationsStore(
{required String Function() getLocale}) =>
{String? Function() getLocale = getDefaultLocale}) =>
TranslationsStore(
translations: getAllTranslations(),
getLocale: getLocale,
Expand All @@ -233,6 +236,13 @@ class SetonixData extends ArchiveData<SetonixData> {
String background, BackgroundDefinition definition) =>
setAsset('$kPackBackgroundsPath/$background.json',
utf8.encode(definition.toJson()));

SetonixData setTranslation(PackTranslation translation,
[String locale = kFallbackLocale]) =>
setAsset(
'$kPackTranslationsPath/$locale.json',
utf8.encode(translation.toJson()),
);
}

class SetonixFile {
Expand Down
45 changes: 14 additions & 31 deletions api/lib/src/models/definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,36 @@ class FigureDefinition extends GameObjectDefinition
}

@MappableClass()
class BoardDefinition with BoardDefinitionMappable, VisualDefinition {
@override
final VectorDefinition offset;
@override
final VectorDefinition? size;
@override
final String texture;
class BoardDefinition extends VisualDefinition with BoardDefinitionMappable {
final VectorDefinition tiles;

BoardDefinition({
this.offset = VectorDefinition.zero,
this.size,
required this.texture,
super.offset,
super.size,
required super.texture,
this.tiles = VectorDefinition.one,
});
}

@MappableClass()
class VariationDefinition with VariationDefinitionMappable, VisualDefinition {
class VariationDefinition extends VisualDefinition
with VariationDefinitionMappable {
final String? category;
@override
final String texture;
@override
final VectorDefinition offset;
@override
final VectorDefinition? size;

VariationDefinition({
this.category,
required this.texture,
this.offset = VectorDefinition.zero,
this.size,
required super.texture,
super.offset,
super.size,
});
}

@MappableClass()
class FigureBackDefinition with FigureBackDefinitionMappable, VisualDefinition {
@override
final String texture;
@override
final VectorDefinition offset;
@override
final VectorDefinition? size;

class FigureBackDefinition extends VisualDefinition
with FigureBackDefinitionMappable {
FigureBackDefinition({
required this.texture,
this.offset = VectorDefinition.zero,
this.size,
required super.texture,
super.offset,
super.size,
});
}
18 changes: 15 additions & 3 deletions api/lib/src/models/definition.mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class VariationDefinitionMapper extends ClassMapperBase<VariationDefinition> {
static VariationDefinitionMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = VariationDefinitionMapper._());
VisualDefinitionMapper.ensureInitialized();
VectorDefinitionMapper.ensureInitialized();
}
return _instance!;
Expand Down Expand Up @@ -257,9 +258,12 @@ extension VariationDefinitionValueCopy<$R, $Out>
}

abstract class VariationDefinitionCopyWith<$R, $In extends VariationDefinition,
$Out> implements ClassCopyWith<$R, $In, $Out> {
$Out> implements VisualDefinitionCopyWith<$R, $In, $Out> {
@override
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition> get offset;
@override
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition>? get size;
@override
$R call(
{String? category,
String? texture,
Expand Down Expand Up @@ -315,6 +319,7 @@ class FigureBackDefinitionMapper extends ClassMapperBase<FigureBackDefinition> {
static FigureBackDefinitionMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = FigureBackDefinitionMapper._());
VisualDefinitionMapper.ensureInitialized();
VectorDefinitionMapper.ensureInitialized();
}
return _instance!;
Expand Down Expand Up @@ -403,9 +408,12 @@ extension FigureBackDefinitionValueCopy<$R, $Out>
abstract class FigureBackDefinitionCopyWith<
$R,
$In extends FigureBackDefinition,
$Out> implements ClassCopyWith<$R, $In, $Out> {
$Out> implements VisualDefinitionCopyWith<$R, $In, $Out> {
@override
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition> get offset;
@override
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition>? get size;
@override
$R call({String? texture, VectorDefinition? offset, VectorDefinition? size});
FigureBackDefinitionCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t);
Expand Down Expand Up @@ -451,6 +459,7 @@ class BoardDefinitionMapper extends ClassMapperBase<BoardDefinition> {
static BoardDefinitionMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = BoardDefinitionMapper._());
VisualDefinitionMapper.ensureInitialized();
VectorDefinitionMapper.ensureInitialized();
}
return _instance!;
Expand Down Expand Up @@ -540,10 +549,13 @@ extension BoardDefinitionValueCopy<$R, $Out>
}

abstract class BoardDefinitionCopyWith<$R, $In extends BoardDefinition, $Out>
implements ClassCopyWith<$R, $In, $Out> {
implements VisualDefinitionCopyWith<$R, $In, $Out> {
@override
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition> get offset;
@override
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition>? get size;
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition> get tiles;
@override
$R call(
{VectorDefinition? offset,
VectorDefinition? size,
Expand Down
10 changes: 7 additions & 3 deletions api/lib/src/models/translation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import 'package:dart_mappable/dart_mappable.dart';

part 'translation.mapper.dart';

const kFallbackLocale = 'en';

String? getDefaultLocale() => null;

class TranslationsStore {
final String Function() getLocale;
final String? Function() getLocale;
final Map<String, PackTranslation> translations;

TranslationsStore({
Iterable<MapEntry<String, PackTranslation>> translations = const [],
required this.getLocale,
this.getLocale = getDefaultLocale,
}) : translations = Map.fromEntries(translations);

PackTranslation getTranslation([String? locale]) =>
(locale == null ? null : translations[locale]) ??
(locale == null ? translations[kFallbackLocale] : translations[locale]) ??
translations[getLocale()] ??
PackTranslation();

Expand Down
18 changes: 14 additions & 4 deletions api/lib/src/models/visual.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import 'package:dart_mappable/dart_mappable.dart';

import 'vector.dart';

mixin VisualDefinition {
String get texture;
VectorDefinition get offset;
VectorDefinition? get size;
part 'visual.mapper.dart';

@MappableClass()
abstract class VisualDefinition with VisualDefinitionMappable {
final String texture;
final VectorDefinition offset;
final VectorDefinition? size;

VisualDefinition(
{required this.texture,
this.offset = VectorDefinition.zero,
required this.size});
}
71 changes: 71 additions & 0 deletions api/lib/src/models/visual.mapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member
// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter

part of 'visual.dart';

class VisualDefinitionMapper extends ClassMapperBase<VisualDefinition> {
VisualDefinitionMapper._();

static VisualDefinitionMapper? _instance;
static VisualDefinitionMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = VisualDefinitionMapper._());
VectorDefinitionMapper.ensureInitialized();
}
return _instance!;
}

@override
final String id = 'VisualDefinition';

static String _$texture(VisualDefinition v) => v.texture;
static const Field<VisualDefinition, String> _f$texture =
Field('texture', _$texture);
static VectorDefinition _$offset(VisualDefinition v) => v.offset;
static const Field<VisualDefinition, VectorDefinition> _f$offset =
Field('offset', _$offset, opt: true, def: VectorDefinition.zero);
static VectorDefinition? _$size(VisualDefinition v) => v.size;
static const Field<VisualDefinition, VectorDefinition> _f$size =
Field('size', _$size);

@override
final MappableFields<VisualDefinition> fields = const {
#texture: _f$texture,
#offset: _f$offset,
#size: _f$size,
};

static VisualDefinition _instantiate(DecodingData data) {
throw MapperException.missingConstructor('VisualDefinition');
}

@override
final Function instantiate = _instantiate;

static VisualDefinition fromMap(Map<String, dynamic> map) {
return ensureInitialized().decodeMap<VisualDefinition>(map);
}

static VisualDefinition fromJson(String json) {
return ensureInitialized().decodeJson<VisualDefinition>(json);
}
}

mixin VisualDefinitionMappable {
String toJson();
Map<String, dynamic> toMap();
VisualDefinitionCopyWith<VisualDefinition, VisualDefinition, VisualDefinition>
get copyWith;
}

abstract class VisualDefinitionCopyWith<$R, $In extends VisualDefinition, $Out>
implements ClassCopyWith<$R, $In, $Out> {
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition> get offset;
VectorDefinitionCopyWith<$R, VectorDefinition, VectorDefinition>? get size;
$R call({String? texture, VectorDefinition? offset, VectorDefinition? size});
VisualDefinitionCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t);
}
12 changes: 6 additions & 6 deletions api/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ packages:
dependency: "direct main"
description:
path: "packages/dart_leap"
ref: dfda6c2e3cef2e29511f97e9470fd4deb8e0c573
resolved-ref: dfda6c2e3cef2e29511f97e9470fd4deb8e0c573
ref: db69a03082e6811c58dc2d0e5c23d04305e1623f
resolved-ref: db69a03082e6811c58dc2d0e5c23d04305e1623f
url: "https://github.com/LinwoodDev/dart_pkgs"
source: git
version: "1.0.0"
Expand Down Expand Up @@ -259,10 +259,10 @@ packages:
dependency: transitive
description:
name: http_parser
sha256: "76d306a1c3afb33fe82e2bbacad62a61f409b5634c915fceb0d799de1a913360"
sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571"
url: "https://pub.dev"
source: hosted
version: "4.1.1"
version: "4.1.2"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -307,8 +307,8 @@ packages:
dependency: "direct main"
description:
path: "packages/lw_file_system_api"
ref: "2036c923bb93afcefaadd8108c7e789513ae7082"
resolved-ref: "2036c923bb93afcefaadd8108c7e789513ae7082"
ref: "5ab1b96bea6ef0e0c07629ff4e7152b4437cf8ee"
resolved-ref: "5ab1b96bea6ef0e0c07629ff4e7152b4437cf8ee"
url: "https://github.com/LinwoodDev/dart_pkgs"
source: git
version: "1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
lw_file_system_api:
git:
url: https://github.com/LinwoodDev/dart_pkgs
ref: 2036c923bb93afcefaadd8108c7e789513ae7082
ref: 5ab1b96bea6ef0e0c07629ff4e7152b4437cf8ee
path: packages/lw_file_system_api
networker:
git:
Expand All @@ -25,7 +25,7 @@ dependencies:
git:
url: https://github.com/LinwoodDev/dart_pkgs
path: packages/dart_leap
ref: dfda6c2e3cef2e29511f97e9470fd4deb8e0c573
ref: db69a03082e6811c58dc2d0e5c23d04305e1623f
crypto: ^3.0.5
collection: ^1.18.0
# path: ^1.8.0
Expand Down
Loading

0 comments on commit c0368f1

Please sign in to comment.