Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Fix: Some minor bug fixing (#63)
Browse files Browse the repository at this point in the history
- Re-selecting emulator
 - Workaround for non semantic versions in config files
 - Mod list author text
  • Loading branch information
89pleasure committed Jun 29, 2023
1 parent f2ab1f6 commit 871713e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 54 deletions.
4 changes: 3 additions & 1 deletion lib/main.dart
Expand Up @@ -25,7 +25,9 @@ void main() async {
// Set local storage
await SharedPreferencesStorage.instance.init();

if (kDebugMode && const bool.fromEnvironment('DEBUG_CLEAR_STORAGE_ON_STARTUP', defaultValue: false)) {
const bool clearStorageOnStartup = bool.fromEnvironment('DEBUG_CLEAR_STORAGE_ON_STARTUP', defaultValue: false);
if (kDebugMode && clearStorageOnStartup) {
debugPrint('Clearing storage on startup');
SharedPreferencesStorage.instance.clear();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/entity/mod.dart
Expand Up @@ -21,7 +21,7 @@ class Mod with _$Mod {
required final String id,
required final String title,
required final Category category,
required final String? version,
required final String version,
required final Map<dynamic, dynamic> game,
required final String origin,
final String? subtitle,
Expand All @@ -45,7 +45,7 @@ class Mod with _$Mod {
category: Category.values.singleWhere(
(category) => category.id == yaml['category'] as int,
),
version: yaml['version'] is int ? yaml['version'].toString() : yaml['version'] as String?,
version: yaml['version'] is int ? yaml['version'].toString() : yaml['version'] as String? ?? '0.0.0',
game: yaml['game'],
origin: origin,
author: yaml['author'],
Expand Down
24 changes: 12 additions & 12 deletions lib/src/entity/mod.freezed.dart
Expand Up @@ -19,7 +19,7 @@ mixin _$Mod {
String get id => throw _privateConstructorUsedError;
String get title => throw _privateConstructorUsedError;
Category get category => throw _privateConstructorUsedError;
String? get version => throw _privateConstructorUsedError;
String get version => throw _privateConstructorUsedError;
Map<dynamic, dynamic> get game => throw _privateConstructorUsedError;
String get origin => throw _privateConstructorUsedError;
String? get subtitle => throw _privateConstructorUsedError;
Expand All @@ -41,7 +41,7 @@ abstract class $ModCopyWith<$Res> {
{String id,
String title,
Category category,
String? version,
String version,
Map<dynamic, dynamic> game,
String origin,
String? subtitle,
Expand All @@ -66,7 +66,7 @@ class _$ModCopyWithImpl<$Res, $Val extends Mod> implements $ModCopyWith<$Res> {
Object? id = null,
Object? title = null,
Object? category = null,
Object? version = freezed,
Object? version = null,
Object? game = null,
Object? origin = null,
Object? subtitle = freezed,
Expand All @@ -88,10 +88,10 @@ class _$ModCopyWithImpl<$Res, $Val extends Mod> implements $ModCopyWith<$Res> {
? _value.category
: category // ignore: cast_nullable_to_non_nullable
as Category,
version: freezed == version
version: null == version
? _value.version
: version // ignore: cast_nullable_to_non_nullable
as String?,
as String,
game: null == game
? _value.game
: game // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -134,7 +134,7 @@ abstract class _$$_ModCopyWith<$Res> implements $ModCopyWith<$Res> {
{String id,
String title,
Category category,
String? version,
String version,
Map<dynamic, dynamic> game,
String origin,
String? subtitle,
Expand All @@ -156,7 +156,7 @@ class __$$_ModCopyWithImpl<$Res> extends _$ModCopyWithImpl<$Res, _$_Mod>
Object? id = null,
Object? title = null,
Object? category = null,
Object? version = freezed,
Object? version = null,
Object? game = null,
Object? origin = null,
Object? subtitle = freezed,
Expand All @@ -178,10 +178,10 @@ class __$$_ModCopyWithImpl<$Res> extends _$ModCopyWithImpl<$Res, _$_Mod>
? _value.category
: category // ignore: cast_nullable_to_non_nullable
as Category,
version: freezed == version
version: null == version
? _value.version
: version // ignore: cast_nullable_to_non_nullable
as String?,
as String,
game: null == game
? _value._game
: game // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -240,7 +240,7 @@ class _$_Mod extends _Mod {
@override
final Category category;
@override
final String? version;
final String version;
final Map<dynamic, dynamic> _game;
@override
Map<dynamic, dynamic> get game {
Expand Down Expand Up @@ -327,7 +327,7 @@ abstract class _Mod extends Mod {
{required final String id,
required final String title,
required final Category category,
required final String? version,
required final String version,
required final Map<dynamic, dynamic> game,
required final String origin,
final String? subtitle,
Expand All @@ -344,7 +344,7 @@ abstract class _Mod extends Mod {
@override
Category get category;
@override
String? get version;
String get version;
@override
Map<dynamic, dynamic> get game;
@override
Expand Down
18 changes: 15 additions & 3 deletions lib/src/repository/mods.dart
Expand Up @@ -26,7 +26,7 @@ class ModsRepository {

Future<bool> hasModUpdate(Emulator emulator, String gameTitleId, String identfier, String modOrigin) async {
final installedModDirectory =
await emulator.filesystem.getModDirectory(emulator, gameTitleId.toUpperCase(), identfier.toLowerCase());
await emulator.filesystem.getModDirectory(emulator, gameTitleId.toUpperCase(), identfier);
final int installedModVersion = getExtendedVersionNumber(await getModVersion(installedModDirectory.path));
final int sourceModVersion = getExtendedVersionNumber(await getModVersion(modOrigin));

Expand Down Expand Up @@ -75,7 +75,7 @@ class ModsRepository {
}

/// Gets a version of a mod by its path
Future<String> getModVersion(String path, {String configFileBasename = 'config.yaml'}) async {
Future<dynamic> getModVersion(String path, {String configFileBasename = 'config.yaml'}) async {
final directory = Directory(path);
final File configYaml = File('${directory.path}${Platform.pathSeparator}$configFileBasename');
final sourceModConfig = await loadYaml(await configYaml.readAsString());
Expand All @@ -89,7 +89,19 @@ class ModsRepository {
return sourceModConfig['version'];
}

int getExtendedVersionNumber(String version) {
int getExtendedVersionNumber(dynamic version) {
if (version == null) {
return 0;
}

if (version is int) {
version = '$version.0.0';
}

if (version is double) {
version = '$version.0';
}

List versionCells = version.split('.');
versionCells = versionCells.map((i) => int.parse(i)).toList();
return versionCells[0] * 100000 + versionCells[1] * 1000 + versionCells[2];
Expand Down
7 changes: 6 additions & 1 deletion lib/src/screen/games/game_list_empty_view.dart
@@ -1,7 +1,9 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:modmopet/src/entity/emulator.dart';
import 'package:modmopet/src/provider/game_list_provider.dart';
import 'package:modmopet/src/service/emulator.dart';
import 'package:modmopet/src/themes/color_schemes.g.dart';
import 'package:modmopet/src/widgets/mm_evelated_button.dart';

Expand Down Expand Up @@ -48,7 +50,10 @@ class GameListEmptyView extends ConsumerWidget {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: MMElevatedButton.secondary(
onPressed: () => ref.invalidate(gameListProvider),
onPressed: () {
ref.read(selectedEmulatorProvider.notifier).clear();
ref.invalidate(gameListProvider);
},
child: Text('no_games_found_button_update'.tr()),
),
),
Expand Down
74 changes: 39 additions & 35 deletions lib/src/screen/mods/mod_list_item.dart
@@ -1,3 +1,4 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
Expand Down Expand Up @@ -26,30 +27,39 @@ class ModListItem extends HookConsumerWidget {
}
}

List<Widget> createAuthorsTextLinks(List<dynamic>? authors) {
List<Widget> authorsLinks = [];
if (authors != null && authors.isNotEmpty) {
for (Map author in authors) {
authorsLinks.add(
TextButton(
onPressed: author['link'] != null ? () => _launchAuthorLink(author['link']) : null,
child: author['name'] != null
? Text(
author['name'],
softWrap: true,
style: TextStyle(
fontSize: 11.0,
color: author['link'] != null ? MMColors.instance.secondary : MMColors.instance.lightWhite,
),
overflow: TextOverflow.ellipsis,
)
: const Text('unknown'),
Widget createAuthorsTextLinks(List<dynamic> authors, TextStyle textStyle) {
List<TextSpan> authorsLinks = [];
for (Map author in authors) {
String? authorName = author['name'];
String? authorLink = author['link'];

authorsLinks.add(
TextSpan(
recognizer: TapGestureRecognizer()..onTap = authorLink != null ? () => _launchAuthorLink(authorLink) : null,
mouseCursor: authorLink != null ? SystemMouseCursors.click : SystemMouseCursors.basic,
text: (authorName != null && authorName.isNotEmpty)
? author == authors.last
? authorName
: '$authorName, '
: 'unknown',
style: textStyle.copyWith(
fontWeight: (authorLink != null && authorLink.isNotEmpty) ? FontWeight.bold : FontWeight.normal,
color: (authorLink != null && authorLink.isNotEmpty)
? MMColors.instance.secondary
: MMColors.instance.lightWhite,
),
);
}
),
);
}

return authorsLinks;
return RichText(
overflow: TextOverflow.ellipsis,
maxLines: 2,
textAlign: TextAlign.right,
text: TextSpan(
children: authorsLinks,
),
);
}

@override
Expand Down Expand Up @@ -97,28 +107,22 @@ class ModListItem extends HookConsumerWidget {
buildGameVersionCompatibility(mod, textTheme),
],
),
minVerticalPadding: 20.0,
minVerticalPadding: 18.0,
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
width: 300.0,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
...createAuthorsTextLinks(mod.author),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12.0,
),
child: mod.version == null
? const Text('No version')
: Text(
'v${mod.version!}',
),
),
mod.author != null
? createAuthorsTextLinks(mod.author!, textTheme.bodySmall!)
: const Text('unknown'),
mod.version == null
? Text('No version', style: textTheme.bodySmall!)
: Text('v${mod.version!}', style: textTheme.bodySmall!),
],
),
),
Expand Down

0 comments on commit 871713e

Please sign in to comment.