Skip to content

Commit

Permalink
Update for latest flutter support
Browse files Browse the repository at this point in the history
  • Loading branch information
nizwar committed Jul 26, 2024
1 parent c9513ed commit f4049e2
Show file tree
Hide file tree
Showing 49 changed files with 541 additions and 297 deletions.
34 changes: 17 additions & 17 deletions .metadata
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# 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: f1875d570e39de09040c8f79aa13cc56baab8db1
channel: stable
revision: "761747bfc538b5af34aa0d3fac380f1bc331ec49"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: android
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: ios
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: linux
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: macos
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: web
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: windows
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49

# User provided section

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.nizwar.ludo_flutter

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity()
12 changes: 12 additions & 0 deletions ios/RunnerTests/RunnerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Flutter
import UIKit
import XCTest

class RunnerTests: XCTestCase {

func testExample() {
// If you add code to the Runner application, consider adding tests here.
// See https://developer.apple.com/documentation/xctest for more information about using XCTest.
}

}
103 changes: 56 additions & 47 deletions lib/ludo_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:math';

import 'package:flutter/material.dart';
import 'package:ludo_flutter/ludo_player.dart';
import 'package:provider/provider.dart';

import 'audio.dart';
import 'constants.dart';
Expand Down Expand Up @@ -41,18 +42,54 @@ class LudoProvider extends ChangeNotifier {
LudoPlayer get currentPlayer => players.firstWhere((element) => element.type == _currentTurn);

///Fill all players
final List<LudoPlayer> players = [
LudoPlayer(LudoPlayerType.green),
LudoPlayer(LudoPlayerType.yellow),
LudoPlayer(LudoPlayerType.blue),
LudoPlayer(LudoPlayerType.red),
];
final List<LudoPlayer> players = [];

///Player win, we use `LudoPlayerType` to make it easier to check
final List<LudoPlayerType> winners = [];

LudoPlayer player(LudoPlayerType type) => players.firstWhere((element) => element.type == type);

///This method will check if the pawn can kill another pawn or not by checking the step of the pawn
bool checkToKill(LudoPlayerType type, int index, int step, List<List<double>> path) {
bool killSomeone = false;
for (int i = 0; i < 4; i++) {
var greenElement = player(LudoPlayerType.green).pawns[i];
var blueElement = player(LudoPlayerType.blue).pawns[i];
var redElement = player(LudoPlayerType.red).pawns[i];
var yellowElement = player(LudoPlayerType.yellow).pawns[i];

if ((greenElement.step > -1 && !LudoPath.safeArea.map((e) => e.toString()).contains(player(LudoPlayerType.green).path[greenElement.step].toString())) && type != LudoPlayerType.green) {
if (player(LudoPlayerType.green).path[greenElement.step].toString() == path[step - 1].toString()) {
killSomeone = true;
player(LudoPlayerType.green).movePawn(i, -1);
notifyListeners();
}
}
if ((yellowElement.step > -1 && !LudoPath.safeArea.map((e) => e.toString()).contains(player(LudoPlayerType.yellow).path[yellowElement.step].toString())) && type != LudoPlayerType.yellow) {
if (player(LudoPlayerType.yellow).path[yellowElement.step].toString() == path[step - 1].toString()) {
killSomeone = true;
player(LudoPlayerType.yellow).movePawn(i, -1);
notifyListeners();
}
}
if ((blueElement.step > -1 && !LudoPath.safeArea.map((e) => e.toString()).contains(player(LudoPlayerType.blue).path[blueElement.step].toString())) && type != LudoPlayerType.blue) {
if (player(LudoPlayerType.blue).path[blueElement.step].toString() == path[step - 1].toString()) {
killSomeone = true;
player(LudoPlayerType.blue).movePawn(i, -1);
notifyListeners();
}
}
if ((redElement.step > -1 && !LudoPath.safeArea.map((e) => e.toString()).contains(player(LudoPlayerType.red).path[redElement.step].toString())) && type != LudoPlayerType.red) {
if (player(LudoPlayerType.red).path[redElement.step].toString() == path[step - 1].toString()) {
killSomeone = true;
player(LudoPlayerType.red).movePawn(i, -1);
notifyListeners();
}
}
}
return killSomeone;
}

///This is the function that will be called to throw the dice
void throwDice() async {
if (_gameState != LudoGameState.throwDice) return;
Expand Down Expand Up @@ -194,47 +231,6 @@ class LudoProvider extends ChangeNotifier {
notifyListeners();
}

///This method will check if the pawn can kill another pawn or not by checking the step of the pawn
bool checkToKill(LudoPlayerType type, int index, int step, List<List<double>> path) {
bool killSomeone = false;
for (int i = 0; i < 4; i++) {
var greenElement = player(LudoPlayerType.green).pawns[i];
var blueElement = player(LudoPlayerType.blue).pawns[i];
var redElement = player(LudoPlayerType.red).pawns[i];
var yellowElement = player(LudoPlayerType.yellow).pawns[i];

if ((greenElement.step > -1 && !LudoPath.safeArea.map((e) => e.toString()).contains(player(LudoPlayerType.green).path[greenElement.step].toString())) && type != LudoPlayerType.green) {
if (player(LudoPlayerType.green).path[greenElement.step].toString() == path[step - 1].toString()) {
killSomeone = true;
player(LudoPlayerType.green).movePawn(i, -1);
notifyListeners();
}
}
if ((yellowElement.step > -1 && !LudoPath.safeArea.map((e) => e.toString()).contains(player(LudoPlayerType.yellow).path[yellowElement.step].toString())) && type != LudoPlayerType.yellow) {
if (player(LudoPlayerType.yellow).path[yellowElement.step].toString() == path[step - 1].toString()) {
killSomeone = true;
player(LudoPlayerType.yellow).movePawn(i, -1);
notifyListeners();
}
}
if ((blueElement.step > -1 && !LudoPath.safeArea.map((e) => e.toString()).contains(player(LudoPlayerType.blue).path[blueElement.step].toString())) && type != LudoPlayerType.blue) {
if (player(LudoPlayerType.blue).path[blueElement.step].toString() == path[step - 1].toString()) {
killSomeone = true;
player(LudoPlayerType.blue).movePawn(i, -1);
notifyListeners();
}
}
if ((redElement.step > -1 && !LudoPath.safeArea.map((e) => e.toString()).contains(player(LudoPlayerType.red).path[redElement.step].toString())) && type != LudoPlayerType.red) {
if (player(LudoPlayerType.red).path[redElement.step].toString() == path[step - 1].toString()) {
killSomeone = true;
player(LudoPlayerType.red).movePawn(i, -1);
notifyListeners();
}
}
}
return killSomeone;
}

///This function will check if the pawn finish the game or not
void validateWin(LudoPlayerType color) {
if (winners.map((e) => e.name).contains(color.name)) return;
Expand All @@ -248,9 +244,22 @@ class LudoProvider extends ChangeNotifier {
}
}

void startGame() {
winners.clear();
players.clear();
players.addAll([
LudoPlayer(LudoPlayerType.green),
LudoPlayer(LudoPlayerType.yellow),
LudoPlayer(LudoPlayerType.blue),
LudoPlayer(LudoPlayerType.red),
]);
}

@override
void dispose() {
_stopMoving = true;
super.dispose();
}

static LudoProvider read(BuildContext context) => context.read();
}
31 changes: 18 additions & 13 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:ludo_flutter/main_screen.dart';
import 'package:provider/provider.dart';

Expand All @@ -7,7 +8,7 @@ import 'ludo_provider.dart';
main() {
WidgetsFlutterBinding.ensureInitialized();
return runApp(ChangeNotifierProvider(
create: (_) => LudoProvider(),
create: (_) => LudoProvider()..startGame(),
child: const Root(),
));
}
Expand All @@ -23,18 +24,22 @@ class _RootState extends State<Root> {
@override
void initState() {
///Initialize images and precache it
precacheImage(const AssetImage("assets/images/thankyou.gif"), context);
precacheImage(const AssetImage("assets/images/board.png"), context);
precacheImage(const AssetImage("assets/images/dice/1.png"), context);
precacheImage(const AssetImage("assets/images/dice/2.png"), context);
precacheImage(const AssetImage("assets/images/dice/3.png"), context);
precacheImage(const AssetImage("assets/images/dice/4.png"), context);
precacheImage(const AssetImage("assets/images/dice/5.png"), context);
precacheImage(const AssetImage("assets/images/dice/6.png"), context);
precacheImage(const AssetImage("assets/images/dice/draw.gif"), context);
precacheImage(const AssetImage("assets/images/crown/1st.png"), context);
precacheImage(const AssetImage("assets/images/crown/2nd.png"), context);
precacheImage(const AssetImage("assets/images/crown/3rd.png"), context);
SchedulerBinding.instance.addPostFrameCallback((_) {
Future.wait([
precacheImage(const AssetImage("assets/images/thankyou.gif"), context),
precacheImage(const AssetImage("assets/images/board.png"), context),
precacheImage(const AssetImage("assets/images/dice/1.png"), context),
precacheImage(const AssetImage("assets/images/dice/2.png"), context),
precacheImage(const AssetImage("assets/images/dice/3.png"), context),
precacheImage(const AssetImage("assets/images/dice/4.png"), context),
precacheImage(const AssetImage("assets/images/dice/5.png"), context),
precacheImage(const AssetImage("assets/images/dice/6.png"), context),
precacheImage(const AssetImage("assets/images/dice/draw.gif"), context),
precacheImage(const AssetImage("assets/images/crown/1st.png"), context),
precacheImage(const AssetImage("assets/images/crown/2nd.png"), context),
precacheImage(const AssetImage("assets/images/crown/3rd.png"), context),
]);
});
super.initState();
}

Expand Down
21 changes: 13 additions & 8 deletions lib/main_screen.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:ludo_flutter/ludo_provider.dart';
import 'package:ludo_flutter/widgets/board_widget.dart';
import 'package:ludo_flutter/widgets/dice_widget.dart';
import 'package:provider/provider.dart';

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

@override
State<MainScreen> createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {
@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -18,12 +28,7 @@ class MainScreen extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
BoardWidget(),
Center(
child: SizedBox(
width: 50,
height: 50,
child: DiceWidget(),
)),
Center(child: SizedBox(width: 50, height: 50, child: DiceWidget())),
],
),
Consumer<LudoProvider>(
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/pawn_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PawnWidget extends StatelessWidget {
final int step;
final bool highlight;

const PawnWidget(this.index, this.type, {Key? key, this.highlight = false, this.step = -1}) : super(key: key);
const PawnWidget(this.index, this.type, {super.key, this.highlight = false, this.step = -1});

@override
Widget build(BuildContext context) {
Expand Down
9 changes: 8 additions & 1 deletion linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project(runner LANGUAGES CXX)
set(BINARY_NAME "ludo_flutter")
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
set(APPLICATION_ID "com.example.ludo_flutter")
set(APPLICATION_ID "dev.nizwar.ludo_flutter")

# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.
Expand Down Expand Up @@ -86,6 +86,7 @@ set_target_properties(${BINARY_NAME}
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
)


# Generated plugin build rules, which manage building the plugins and adding
# them to the application.
include(flutter/generated_plugins.cmake)
Expand Down Expand Up @@ -122,6 +123,12 @@ foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
COMPONENT Runtime)
endforeach(bundled_library)

# Copy the native assets provided by the build.dart from all packages.
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)

# Fully re-copy the assets directory on each build to avoid having stale files
# from a previous install.
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
Expand Down
20 changes: 20 additions & 0 deletions linux/my_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ static gboolean my_application_local_command_line(GApplication* application, gch
return TRUE;
}

// Implements GApplication::startup.
static void my_application_startup(GApplication* application) {
//MyApplication* self = MY_APPLICATION(object);

// Perform any actions required at application startup.

G_APPLICATION_CLASS(my_application_parent_class)->startup(application);
}

// Implements GApplication::shutdown.
static void my_application_shutdown(GApplication* application) {
//MyApplication* self = MY_APPLICATION(object);

// Perform any actions required at application shutdown.

G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application);
}

// Implements GObject::dispose.
static void my_application_dispose(GObject* object) {
MyApplication* self = MY_APPLICATION(object);
Expand All @@ -91,6 +109,8 @@ static void my_application_dispose(GObject* object) {
static void my_application_class_init(MyApplicationClass* klass) {
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
G_APPLICATION_CLASS(klass)->startup = my_application_startup;
G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown;
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
}

Expand Down
5 changes: 4 additions & 1 deletion macos/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :osx, '10.11'
platform :osx, '10.14'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down Expand Up @@ -31,6 +31,9 @@ target 'Runner' do
use_modular_headers!

flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
Expand Down
Loading

0 comments on commit f4049e2

Please sign in to comment.