Skip to content

Commit

Permalink
Large refactor
Browse files Browse the repository at this point in the history
Most of the core has been rewritten or refactored.
Also includes a few UI improvements.
  • Loading branch information
petlyh committed Jun 19, 2024
1 parent 4a9b35a commit f5aae1a
Show file tree
Hide file tree
Showing 31 changed files with 909 additions and 651 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build_web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- "linux/**"
- "windows/**"
- ".github/**"
- "test/**"

permissions:
contents: write
Expand All @@ -21,7 +22,7 @@ jobs:
steps:
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.13.7"
flutter-version: "3.22.2"
channel: "stable"

- name: Checkout source code
Expand Down
22 changes: 11 additions & 11 deletions .metadata
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.
# This file should be version controlled and should not be manually edited.

version:
revision: 796c8ef79279f9c774545b3771238c3098dbefab
channel: stable
revision: "761747bfc538b5af34aa0d3fac380f1bc331ec49"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: linux
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: web
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: windows
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49

# User provided section

Expand Down
5 changes: 4 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:flutter_lints/flutter.yaml
include: package:lint/strict.yaml

linter:
rules:
Expand All @@ -8,5 +8,8 @@ analyzer:
language:
strict-casts: true
strict-raw-types: true
strong-mode:
implicit-casts: false
implicit-dynamic: false
plugins:
- custom_lint
41 changes: 25 additions & 16 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:mk8se/models/models.dart";
import "package:mk8se/providers/empty_savefile.dart";
import "package:mk8se/widgets/main_panel.dart";
import "package:mk8se/widgets/top_bar.dart";
import "package:package_info_plus/package_info_plus.dart";
import "package:url_launcher/url_launcher_string.dart";

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FileData.initEmpty();
runApp(const ProviderScope(child: App()));

final emptySavefile = await readEmptySavefile();

runApp(
ProviderScope(
overrides: [emptySavefileProvider.overrideWithValue(emptySavefile)],
child: const App(),
),
);
}

class App extends StatelessWidget {
const App({super.key});

// disable splash animations on web
static const splashFactory = kIsWeb ? NoSplash.splashFactory : null;
static const splashFactory = NoSplash.splashFactory;

@override
Widget build(BuildContext context) {
Expand All @@ -33,7 +38,9 @@ class App extends StatelessWidget {
splashFactory: splashFactory,
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.blue, brightness: Brightness.dark),
seedColor: Colors.blue,
brightness: Brightness.dark,
),
useMaterial3: true,
visualDensity: VisualDensity.compact,
),
Expand All @@ -50,27 +57,29 @@ class MainPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
scrolledUnderElevation: 0,
forceMaterialTransparency: true,
toolbarHeight: 48,
titleSpacing: 4,
title: const TopRow(),
actions: [
IconButton(
tooltip: "Source Code",
onPressed: () => launchUrlString(repoUrl),
icon: const Icon(Icons.code)),
tooltip: "Source Code",
onPressed: () => launchUrlString(repoUrl),
icon: const Icon(Icons.code),
),
IconButton(
tooltip: "Info",
onPressed: () => showInfo(context),
icon: const Icon(Icons.info_outline)),
tooltip: "Info",
onPressed: () => showInfo(context),
icon: const Icon(Icons.info_outline),
),
const SizedBox(width: 4),
],
),
body: const MainPanel(),
);
}

void showInfo(BuildContext context) async {
Future<void> showInfo(BuildContext context) async {
final packageInfo = await PackageInfo.fromPlatform();

if (!context.mounted) {
Expand All @@ -83,4 +92,4 @@ class MainPage extends StatelessWidget {
applicationLegalese: "Licensed under AGPLv3.",
);
}
}
}
68 changes: 68 additions & 0 deletions lib/models/byte_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import "dart:math";
import "dart:typed_data";

import "package:built_collection/built_collection.dart";
import "package:collection/collection.dart";
import "package:meta/meta.dart";

@immutable
extension type const ByteList._(BuiltList<int> _list) implements Iterable<int> {
ByteList.fromUint8List(Uint8List uint8List) : _list = uint8List.build();

ByteList.fromByteData(ByteData byteData)
: _list = byteData.buffer.asUint8List().build();

@redeclare
List<int> toList() => _list.toList();

Uint8List toUint8List() => Uint8List.fromList(toList());

List<int> toSublist(int start, [int? end]) =>
_list.sublist(start, end).toList();

int readInt8(int offset) => _list[offset];

int readInt32(int offset) => _decodeBase(toSublist(offset, offset + 4), 256);

ByteList withInt8At(int number, int offset) => ByteList._(
_list.rebuild(
(b) => b.replaceRange(
offset,
offset + 1,
[number.clamp(0, 255)],
),
),
);

ByteList withInt32At(int number, int offset) => ByteList._(
_list.rebuild(
(b) => b.replaceRange(
offset,
offset + 4,
_encodeBase(number, 4, 256),
),
),
);
}

/// Encodes [number] to base [radix] with [digitCount] digits.
///
/// Result is [Endian.big].
Iterable<int> _encodeBase(int number, int digitCount, int radix) {
final digitValue = pow(radix, digitCount - 1).toInt();
final digit = (number / digitValue).truncate();

return [
digit,
if (digitCount > 1)
..._encodeBase(number - (digit * digitValue), digitCount - 1, radix),
];
}

/// Interprets a list of digits of base [radix] as a an integer.
///
/// [input] is interpreted as [Endian.big].
int _decodeBase(List<int> input, int radix) => input.reversed.reduceIndexed(
(index, previous, element) =>
(previous + element.clamp(0, radix - 1) * pow(radix, index)).toInt(),
);
109 changes: 0 additions & 109 deletions lib/models/file_data.dart

This file was deleted.

10 changes: 0 additions & 10 deletions lib/models/models.dart

This file was deleted.

33 changes: 0 additions & 33 deletions lib/models/offset.dart

This file was deleted.

Loading

0 comments on commit f5aae1a

Please sign in to comment.