-
Notifications
You must be signed in to change notification settings - Fork 2
New levels 51 #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New levels 51 #23
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| package com.khlebobul.pegma | ||
|
|
||
| import android.os.Bundle | ||
| import io.flutter.embedding.android.FlutterActivity | ||
|
|
||
| class MainActivity : FlutterActivity() | ||
| class MainActivity : FlutterActivity() { | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| // Force hardware acceleration for better rendering performance | ||
| window.setFlags( | ||
| android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, | ||
| android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED | ||
| ) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,15 @@ import 'package:path/path.dart'; | |
| class DatabaseHelper { | ||
| static final DatabaseHelper instance = DatabaseHelper._init(); | ||
| static Database? _database; | ||
| static Future<Database>? _initFuture; | ||
|
|
||
| DatabaseHelper._init(); | ||
|
|
||
| Future<Database> get database async { | ||
| if (_database != null) return _database!; | ||
| _database = await _initDB('pegma.db'); | ||
| // Prevent race conditions by reusing the same initialization future | ||
| _initFuture ??= _initDB('pegma.db'); | ||
| _database = await _initFuture; | ||
| return _database!; | ||
| } | ||
|
Comment on lines
12
to
18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Race condition guard is incomplete for close/reopen scenarios. The Consider resetting both fields in Future<void> close() async {
final db = await database;
await db.close();
+ _database = null;
+ _initFuture = null;
}
🤖 Prompt for AI Agents |
||
|
|
||
|
|
@@ -20,7 +23,7 @@ class DatabaseHelper { | |
|
|
||
| return await openDatabase( | ||
| path, | ||
| version: 4, | ||
| version: 5, | ||
| onCreate: _createDB, | ||
| onUpgrade: _upgradeDB, | ||
| ); | ||
|
|
@@ -49,6 +52,16 @@ class DatabaseHelper { | |
| ) | ||
| '''); | ||
| } | ||
|
|
||
| if (oldVersion < 5) { | ||
| // Delete saved games for levels that were modified (10, 45, 48) | ||
| // This fixes incompatibility issues while preserving completed level progress | ||
| await db.delete( | ||
| 'saved_games', | ||
| where: 'level_id IN (?, ?, ?)', | ||
| whereArgs: [10, 45, 48], | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Future<void> _createDB(Database db, int version) async { | ||
|
|
@@ -126,11 +139,26 @@ class DatabaseHelper { | |
|
|
||
| if (result.isEmpty) return null; | ||
|
|
||
| final row = result.first; | ||
| return { | ||
| 'board': jsonDecode(row['board_state'] as String) as List<dynamic>, | ||
| 'moves_count': row['moves_count'] as int, | ||
| }; | ||
| try { | ||
| final row = result.first; | ||
| final boardData = jsonDecode(row['board_state'] as String) as List<dynamic>; | ||
|
|
||
| // Validate board structure | ||
| if (boardData.isEmpty || boardData.first is! List) { | ||
| // Invalid board structure, delete corrupted save | ||
| await deleteSavedGameState(levelId); | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| 'board': boardData, | ||
| 'moves_count': row['moves_count'] as int, | ||
| }; | ||
| } catch (e) { | ||
| // If decoding fails, delete corrupted save and return null | ||
| await deleteSavedGameState(levelId); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| Future<void> deleteSavedGameState(int levelId) async { | ||
|
|
@@ -143,6 +171,18 @@ class DatabaseHelper { | |
| await db.delete('saved_games'); | ||
| } | ||
|
|
||
| /// Clear saved games for specific levels (useful after level modifications) | ||
| Future<void> clearSavedGamesForLevels(List<int> levelIds) async { | ||
| if (levelIds.isEmpty) return; | ||
| final db = await database; | ||
| final placeholders = List.filled(levelIds.length, '?').join(','); | ||
| await db.delete( | ||
| 'saved_games', | ||
| where: 'level_id IN ($placeholders)', | ||
| whereArgs: levelIds, | ||
| ); | ||
| } | ||
|
|
||
| Future<void> close() async { | ||
| final db = await database; | ||
| await db.close(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "board": [ | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"], | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"], | ||
| ["0", "0", "1", "1", "1", "0", "0"], | ||
| ["0", "1", "0", "1", "0", "1", "0"], | ||
| ["0", "0", "1", "0", "1", "0", "0"], | ||
| ["-1", "-1", "1", "1", "1", "-1", "-1"], | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"] | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "board": [ | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"], | ||
| ["0", "0", "0", "1", "0", "0", "0"], | ||
| ["0", "0", "1", "1", "1", "0", "0"], | ||
| ["1", "1", "0", "0", "0", "1", "1"], | ||
| ["-1", "-1", "1", "0", "1", "-1", "-1"], | ||
| ["-1", "-1", "1", "0", "1", "-1", "-1"] | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "board": [ | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["-1", "-1", "1", "1", "1", "-1", "-1"], | ||
| ["0", "0", "1", "1", "1", "0", "0"], | ||
| ["0", "1", "1", "0", "1", "1", "0"], | ||
| ["0", "0", "1", "0", "1", "0", "0"], | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"], | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"] | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "board": [ | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"], | ||
| ["0", "0", "1", "1", "1", "0", "0"], | ||
| ["0", "1", "0", "1", "0", "1", "0"], | ||
| ["0", "1", "1", "0", "1", "1", "0"], | ||
| ["-1", "-1", "1", "0", "1", "-1", "-1"], | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"] | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "board": [ | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"], | ||
| ["-1", "-1", "1", "1", "1", "-1", "-1"], | ||
| ["0", "0", "1", "0", "1", "0", "0"], | ||
| ["0", "0", "1", "1", "1", "0", "0"], | ||
| ["0", "0", "1", "0", "1", "0", "0"], | ||
| ["-1", "-1", "1", "1", "1", "-1", "-1"], | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"] | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "board": [ | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["0", "0", "0", "0", "1", "1", "1"], | ||
| ["1", "1", "1", "1", "1", "1", "1"], | ||
| ["0", "0", "0", "1", "1", "0", "0"], | ||
| ["-1", "-1", "0", "1", "1", "-1", "-1"], | ||
| ["-1", "-1", "0", "1", "1", "-1", "-1"] | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "board": [ | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"], | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"], | ||
| ["0", "0", "0", "0", "0", "0", "0"], | ||
| ["0", "1", "1", "1", "1", "1", "0"], | ||
| ["0", "1", "0", "0", "0", "1", "0"], | ||
| ["-1", "-1", "1", "1", "1", "-1", "-1"], | ||
| ["-1", "-1", "1", "0", "1", "-1", "-1"] | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "board": [ | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["0", "1", "1", "0", "1", "1", "0"], | ||
| ["1", "1", "1", "1", "1", "1", "1"], | ||
| ["0", "1", "1", "0", "1", "1", "0"], | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"] | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "board": [ | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"], | ||
| ["0", "1", "1", "0", "1", "1", "0"], | ||
| ["0", "0", "1", "1", "1", "1", "0"], | ||
| ["0", "0", "1", "0", "1", "0", "0"], | ||
| ["-1", "-1", "1", "1", "1", "-1", "-1"], | ||
| ["-1", "-1", "0", "1", "0", "-1", "-1"] | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "board": [ | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["-1", "-1", "0", "0", "0", "-1", "-1"], | ||
| ["0", "1", "0", "1", "0", "1", "1"], | ||
| ["0", "1", "1", "1", "1", "1", "0"], | ||
| ["0", "0", "0", "1", "0", "0", "0"], | ||
| ["-1", "-1", "1", "1", "1", "-1", "-1"], | ||
| ["-1", "-1", "1", "0", "1", "-1", "-1"] | ||
| ] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: khlebobul/pegma
Length of output: 108
🏁 Script executed:
Repository: khlebobul/pegma
Length of output: 2253
🏁 Script executed:
Repository: khlebobul/pegma
Length of output: 270
Remove the redundant programmatic hardware acceleration setting.
Hardware acceleration is already enabled in the manifest (
android:hardwareAccelerated="true"on line 13 of AndroidManifest.xml), which is the proper and authoritative way to configure it. SettingFLAG_HARDWARE_ACCELERATEDprogrammatically inonCreate()is ineffective—the window is already created and the rendering pipeline established before this callback executes. Remove this code to avoid confusion.🤖 Prompt for AI Agents