Skip to content

Commit

Permalink
Add image to dialog, closes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Oct 31, 2024
1 parent 406a1fa commit 7f9a26a
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

> WIP: 🃏 Powerful, customizable, cross-platform, opensource table sandbox game 🃏
[![Latest release)](https://img.shields.io/github/v/release/LinwoodDev/Setonix?color=A28DDB&style=for-the-badge&logo=github&logoColor=A28DDB)](https://github.com/LinwoodDev/Setonix/releases)
[![Latest release)](https://img.shields.io/github/v/release/LinwoodDev/Setonix?include_prereleases&color=A28DDB&style=for-the-badge&logo=github&logoColor=A28DDB)](https://github.com/LinwoodDev/Setonix/releases)
[![GitHub License badge](https://img.shields.io/github/license/LinwoodDev/Setonix?color=A28DDB&style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOTIiIGhlaWdodD0iMTkyIiBmaWxsPSIjZWJiNzMzIiB2aWV3Qm94PSIwIDAgMjU2IDI1NiI%2BPHJlY3Qgd2lkdGg9IjI1NiIgaGVpZ2h0PSIyNTYiIGZpbGw9Im5vbmUiPjwvcmVjdD48cmVjdCB4PSIzMiIgeT0iNDgiIHdpZHRoPSIxOTIiIGhlaWdodD0iMTYwIiByeD0iOCIgc3Ryb2tlLXdpZHRoPSIxNiIgc3Ryb2tlPSIjZWJiNzMzIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGZpbGw9Im5vbmUiPjwvcmVjdD48bGluZSB4MT0iNzYiIHkxPSI5NiIgeDI9IjE4MCIgeTI9Ijk2IiBmaWxsPSJub25lIiBzdHJva2U9IiNlYmI3MzMiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIxNiI%2BPC9saW5lPjxsaW5lIHgxPSI3NiIgeTE9IjEyOCIgeDI9IjE4MCIgeTI9IjEyOCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjZWJiNzMzIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS13aWR0aD0iMTYiPjwvbGluZT48bGluZSB4MT0iNzYiIHkxPSIxNjAiIHgyPSIxODAiIHkyPSIxNjAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2ViYjczMyIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2Utd2lkdGg9IjE2Ij48L2xpbmU%2BPC9zdmc%2B)](https://github.com/LinwoodDev/Setonix/blob/main/LICENSE)
[![GitHub Repo stars](https://img.shields.io/github/stars/LinwoodDev/Setonix?color=A28DDB&logo=github&logoColor=A28DDB&style=for-the-badge)](https://github.com/LinwoodDev/Setonix)
[![Matrix badge](https://img.shields.io/matrix/linwood:matrix.org?style=for-the-badge&color=A28DDB&logo=matrix&logoColor=A28DDB&label=Matrix)](https://linwood.dev/matrix)
Expand Down
7 changes: 7 additions & 0 deletions api/lib/src/event/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,10 @@ final class DialogCloseRequest extends ClientWorldEvent

DialogCloseRequest(this.id, this.value);
}

@MappableClass()
final class ImagesRequest extends ClientWorldEvent with ImagesRequestMappable {
final List<String> ids;

ImagesRequest(this.ids);
}
4 changes: 4 additions & 0 deletions api/lib/src/event/event.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'dart:convert';

import 'package:dart_mappable/dart_mappable.dart';
import 'package:networker/networker.dart';
import 'package:setonix_api/event.dart';

import 'dart:typed_data';

part 'event.mapper.dart';

part 'server.dart';
Expand Down
243 changes: 243 additions & 0 deletions api/lib/src/event/event.mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class ServerWorldEventMapper extends SubClassMapperBase<ServerWorldEvent> {
BoardTilesChangedMapper.ensureInitialized();
DialogOpenedMapper.ensureInitialized();
DialogsClosedMapper.ensureInitialized();
ImagesUpdatedMapper.ensureInitialized();
HybridWorldEventMapper.ensureInitialized();
}
return _instance!;
Expand Down Expand Up @@ -1507,6 +1508,128 @@ class _DialogsClosedCopyWithImpl<$R, $Out>
_DialogsClosedCopyWithImpl($value, $cast, t);
}

class ImagesUpdatedMapper extends SubClassMapperBase<ImagesUpdated> {
ImagesUpdatedMapper._();

static ImagesUpdatedMapper? _instance;
static ImagesUpdatedMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = ImagesUpdatedMapper._());
ServerWorldEventMapper.ensureInitialized().addSubMapper(_instance!);
MapperContainer.globals.useAll([Base64IdMapHook()]);
}
return _instance!;
}

@override
final String id = 'ImagesUpdated';

static Map<String, Uint8List> _$images(ImagesUpdated v) => v.images;
static const Field<ImagesUpdated, Map<String, Uint8List>> _f$images =
Field('images', _$images);

@override
final MappableFields<ImagesUpdated> fields = const {
#images: _f$images,
};

@override
final String discriminatorKey = 'type';
@override
final dynamic discriminatorValue = 'ImagesUpdated';
@override
late final ClassMapperBase superMapper =
ServerWorldEventMapper.ensureInitialized();

static ImagesUpdated _instantiate(DecodingData data) {
return ImagesUpdated(data.dec(_f$images));
}

@override
final Function instantiate = _instantiate;

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

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

mixin ImagesUpdatedMappable {
String toJson() {
return ImagesUpdatedMapper.ensureInitialized()
.encodeJson<ImagesUpdated>(this as ImagesUpdated);
}

Map<String, dynamic> toMap() {
return ImagesUpdatedMapper.ensureInitialized()
.encodeMap<ImagesUpdated>(this as ImagesUpdated);
}

ImagesUpdatedCopyWith<ImagesUpdated, ImagesUpdated, ImagesUpdated>
get copyWith => _ImagesUpdatedCopyWithImpl(
this as ImagesUpdated, $identity, $identity);
@override
String toString() {
return ImagesUpdatedMapper.ensureInitialized()
.stringifyValue(this as ImagesUpdated);
}

@override
bool operator ==(Object other) {
return ImagesUpdatedMapper.ensureInitialized()
.equalsValue(this as ImagesUpdated, other);
}

@override
int get hashCode {
return ImagesUpdatedMapper.ensureInitialized()
.hashValue(this as ImagesUpdated);
}
}

extension ImagesUpdatedValueCopy<$R, $Out>
on ObjectCopyWith<$R, ImagesUpdated, $Out> {
ImagesUpdatedCopyWith<$R, ImagesUpdated, $Out> get $asImagesUpdated =>
$base.as((v, t, t2) => _ImagesUpdatedCopyWithImpl(v, t, t2));
}

abstract class ImagesUpdatedCopyWith<$R, $In extends ImagesUpdated, $Out>
implements ServerWorldEventCopyWith<$R, $In, $Out> {
MapCopyWith<$R, String, Uint8List, ObjectCopyWith<$R, Uint8List, Uint8List>>
get images;
@override
$R call({Map<String, Uint8List>? images});
ImagesUpdatedCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
}

class _ImagesUpdatedCopyWithImpl<$R, $Out>
extends ClassCopyWithBase<$R, ImagesUpdated, $Out>
implements ImagesUpdatedCopyWith<$R, ImagesUpdated, $Out> {
_ImagesUpdatedCopyWithImpl(super.value, super.then, super.then2);

@override
late final ClassMapperBase<ImagesUpdated> $mapper =
ImagesUpdatedMapper.ensureInitialized();
@override
MapCopyWith<$R, String, Uint8List, ObjectCopyWith<$R, Uint8List, Uint8List>>
get images => MapCopyWith($value.images,
(v, t) => ObjectCopyWith(v, $identity, t), (v) => call(images: v));
@override
$R call({Map<String, Uint8List>? images}) =>
$apply(FieldCopyWithData({if (images != null) #images: images}));
@override
ImagesUpdated $make(CopyWithData data) =>
ImagesUpdated(data.get(#images, or: $value.images));

@override
ImagesUpdatedCopyWith<$R2, ImagesUpdated, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t) =>
_ImagesUpdatedCopyWithImpl($value, $cast, t);
}

class ClientWorldEventMapper extends SubClassMapperBase<ClientWorldEvent> {
ClientWorldEventMapper._();

Expand All @@ -1525,6 +1648,7 @@ class ClientWorldEventMapper extends SubClassMapperBase<ClientWorldEvent> {
BoardRemoveRequestMapper.ensureInitialized();
BoardMoveRequestMapper.ensureInitialized();
DialogCloseRequestMapper.ensureInitialized();
ImagesRequestMapper.ensureInitialized();
HybridWorldEventMapper.ensureInitialized();
}
return _instance!;
Expand Down Expand Up @@ -2851,6 +2975,125 @@ class _DialogCloseRequestCopyWithImpl<$R, $Out>
_DialogCloseRequestCopyWithImpl($value, $cast, t);
}

class ImagesRequestMapper extends SubClassMapperBase<ImagesRequest> {
ImagesRequestMapper._();

static ImagesRequestMapper? _instance;
static ImagesRequestMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = ImagesRequestMapper._());
ClientWorldEventMapper.ensureInitialized().addSubMapper(_instance!);
}
return _instance!;
}

@override
final String id = 'ImagesRequest';

static List<String> _$ids(ImagesRequest v) => v.ids;
static const Field<ImagesRequest, List<String>> _f$ids = Field('ids', _$ids);

@override
final MappableFields<ImagesRequest> fields = const {
#ids: _f$ids,
};

@override
final String discriminatorKey = 'type';
@override
final dynamic discriminatorValue = 'ImagesRequest';
@override
late final ClassMapperBase superMapper =
ClientWorldEventMapper.ensureInitialized();

static ImagesRequest _instantiate(DecodingData data) {
return ImagesRequest(data.dec(_f$ids));
}

@override
final Function instantiate = _instantiate;

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

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

mixin ImagesRequestMappable {
String toJson() {
return ImagesRequestMapper.ensureInitialized()
.encodeJson<ImagesRequest>(this as ImagesRequest);
}

Map<String, dynamic> toMap() {
return ImagesRequestMapper.ensureInitialized()
.encodeMap<ImagesRequest>(this as ImagesRequest);
}

ImagesRequestCopyWith<ImagesRequest, ImagesRequest, ImagesRequest>
get copyWith => _ImagesRequestCopyWithImpl(
this as ImagesRequest, $identity, $identity);
@override
String toString() {
return ImagesRequestMapper.ensureInitialized()
.stringifyValue(this as ImagesRequest);
}

@override
bool operator ==(Object other) {
return ImagesRequestMapper.ensureInitialized()
.equalsValue(this as ImagesRequest, other);
}

@override
int get hashCode {
return ImagesRequestMapper.ensureInitialized()
.hashValue(this as ImagesRequest);
}
}

extension ImagesRequestValueCopy<$R, $Out>
on ObjectCopyWith<$R, ImagesRequest, $Out> {
ImagesRequestCopyWith<$R, ImagesRequest, $Out> get $asImagesRequest =>
$base.as((v, t, t2) => _ImagesRequestCopyWithImpl(v, t, t2));
}

abstract class ImagesRequestCopyWith<$R, $In extends ImagesRequest, $Out>
implements ClientWorldEventCopyWith<$R, $In, $Out> {
ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get ids;
@override
$R call({List<String>? ids});
ImagesRequestCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
}

class _ImagesRequestCopyWithImpl<$R, $Out>
extends ClassCopyWithBase<$R, ImagesRequest, $Out>
implements ImagesRequestCopyWith<$R, ImagesRequest, $Out> {
_ImagesRequestCopyWithImpl(super.value, super.then, super.then2);

@override
late final ClassMapperBase<ImagesRequest> $mapper =
ImagesRequestMapper.ensureInitialized();
@override
ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get ids =>
ListCopyWith($value.ids, (v, t) => ObjectCopyWith(v, $identity, t),
(v) => call(ids: v));
@override
$R call({List<String>? ids}) =>
$apply(FieldCopyWithData({if (ids != null) #ids: ids}));
@override
ImagesRequest $make(CopyWithData data) =>
ImagesRequest(data.get(#ids, or: $value.ids));

@override
ImagesRequestCopyWith<$R2, ImagesRequest, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t) =>
_ImagesRequestCopyWithImpl($value, $cast, t);
}

class HybridWorldEventMapper extends SubClassMapperBase<HybridWorldEvent> {
HybridWorldEventMapper._();

Expand Down
8 changes: 8 additions & 0 deletions api/lib/src/event/process/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,13 @@ ServerResponse? processClientEvent(
BoardTilesChanged(event.table, newTiles), kAnyChannel);
case DialogCloseRequest():
return ServerResponse.builder(DialogsClosed.single(event.id), channel);
case ImagesRequest():
return ServerResponse.builder(
ImagesUpdated(Map.fromEntries(event.ids.map((e) {
final image = state.images[e];
if (image == null) return null;
return MapEntry(e, image);
}).nonNulls)),
channel);
}
}
Loading

0 comments on commit 7f9a26a

Please sign in to comment.