Add a data generator for the completed.md checklist.
This commit is contained in:
parent
18641d5606
commit
cef613c265
11 changed files with 1047 additions and 446 deletions
184
lib/updateTool.dart
Normal file
184
lib/updateTool.dart
Normal file
|
@ -0,0 +1,184 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:libac_dart/nbt/Stream.dart';
|
||||
import 'package:libacflutter/Constants.dart';
|
||||
import 'package:pokedex/Session.dart';
|
||||
import 'package:pokedex/pokemon.dart';
|
||||
|
||||
Future<int> main(List<String> args) async {
|
||||
runApp(CompletedGenerator());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
class CompletedGenerator extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _completedGen();
|
||||
}
|
||||
}
|
||||
|
||||
class _completedGen extends State<CompletedGenerator> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(theme: ThemeData.dark(), home: MainGen());
|
||||
}
|
||||
}
|
||||
|
||||
class MainGen extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _main();
|
||||
}
|
||||
}
|
||||
|
||||
class _main extends State<MainGen> {
|
||||
bool firstLaunch = true;
|
||||
double progress = 0;
|
||||
String statusMessage = "";
|
||||
Generation gen = Generation.One;
|
||||
StringBuilder sb = StringBuilder();
|
||||
int index = 0;
|
||||
Generation? currentGen = null;
|
||||
int maxTasks = 5;
|
||||
|
||||
int state = 0;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
if (firstLaunch) {
|
||||
firstLaunch = false;
|
||||
setState(() {
|
||||
statusMessage = "Warming up...";
|
||||
progress = 0.0;
|
||||
});
|
||||
|
||||
Timer.periodic(Duration(milliseconds: 100), (x) async {
|
||||
if (state == 0) {
|
||||
sleep(Duration(seconds: 5));
|
||||
statusMessage = "Acquiring game generation";
|
||||
progress = 0.25;
|
||||
setState(() {});
|
||||
|
||||
state++;
|
||||
} else if (state == 1) {
|
||||
SessionData.resetHighestGenCache();
|
||||
int highest = SessionData.highestGenID();
|
||||
// Get actual generation
|
||||
gen = Generation.One;
|
||||
for (var _gen in Generation.values) {
|
||||
if (_gen.idStart < highest) {
|
||||
gen = _gen;
|
||||
}
|
||||
}
|
||||
|
||||
statusMessage = "Generation acquired";
|
||||
progress = 1.0;
|
||||
state++;
|
||||
|
||||
setState(() {});
|
||||
} else if (state == 2) {
|
||||
statusMessage = "Generation ${gen.name}";
|
||||
|
||||
progress = 0.0;
|
||||
state++;
|
||||
|
||||
setState(() {});
|
||||
} else if (state == 3) {
|
||||
statusMessage = "Analyzing Pokemon...";
|
||||
index = 0;
|
||||
currentGen = null;
|
||||
state++;
|
||||
|
||||
setState(() {});
|
||||
} else if (state == 4) {
|
||||
maxTasks += Pokemon.values.length;
|
||||
state++;
|
||||
setState(() {});
|
||||
} else if ((state - index) == 5) {
|
||||
// Pokemon iteration task
|
||||
int iterNumber = state - 5;
|
||||
|
||||
if (iterNumber >= Pokemon.values.length) {
|
||||
state++;
|
||||
setState(() {});
|
||||
return;
|
||||
}
|
||||
|
||||
var pokemon = Pokemon.values[iterNumber];
|
||||
|
||||
if (currentGen != pokemon.generation) {
|
||||
sb.append("\n# Generation ${pokemon.generation.name}\n\n");
|
||||
currentGen = pokemon.generation;
|
||||
}
|
||||
|
||||
progress = index * 100 / Pokemon.values.length;
|
||||
statusMessage =
|
||||
("- Analysis of pokemon ${pokemon.pokemonName} has begun");
|
||||
|
||||
// TODO : This needs to check locations and dex entries to see if they are up to date with the latest generation.
|
||||
// The future task should take into account the generation the pokemon was introduced in. (EX. If introduced in gen 2, it won't have data entries for gen 1).
|
||||
|
||||
if (pokemon.locations.isEmpty && pokemon.dexEntries.isEmpty) {
|
||||
sb.append("- [ ] ${pokemon.pokemonName}\n");
|
||||
} else {
|
||||
if (pokemon.locations.isNotEmpty && pokemon.dexEntries.isNotEmpty) {
|
||||
sb.append("- [x] ${pokemon.pokemonName}\n");
|
||||
} else if (pokemon.locations.isNotEmpty) {
|
||||
sb.append("- [ ] ${pokemon.pokemonName} (MISSING DEX ENTRIES)\n");
|
||||
} else if (pokemon.dexEntries.isNotEmpty) {
|
||||
sb.append(
|
||||
"- [ ] ${pokemon.pokemonName} (MISSING LOCATION ENTRIES)\n",
|
||||
);
|
||||
}
|
||||
}
|
||||
index++;
|
||||
progress = progress / 100; // push it into a 0-1 range.
|
||||
state++;
|
||||
|
||||
setState(() {});
|
||||
} else if (state - index == 6) {
|
||||
// Task - write file
|
||||
maxTasks += 3;
|
||||
statusMessage = "Saving to COMPLETED.md";
|
||||
File complete = File("COMPLETED.md");
|
||||
progress = 99.75;
|
||||
state++;
|
||||
setState(() {});
|
||||
await complete.writeAsString(sb.toString());
|
||||
} else if (state - index == 7) {
|
||||
statusMessage = "Data generation completed";
|
||||
progress = 1.0;
|
||||
state++;
|
||||
setState(() {});
|
||||
} else if (state - index == 8) {
|
||||
x.cancel();
|
||||
sleep(Duration(seconds: 10));
|
||||
exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
super.didChangeDependencies();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Data Generator"),
|
||||
backgroundColor: LibACFlutterConstants.TITLEBAR_COLOR,
|
||||
),
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Status: ${statusMessage}", style: TextStyle(fontSize: 24)),
|
||||
Text("Progress: ${progress * 100}%", style: TextStyle(fontSize: 24)),
|
||||
Text("Task ${state}/${maxTasks}", style: TextStyle(fontSize: 24)),
|
||||
LinearProgressIndicator(value: progress, minHeight: 30),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue