Skip to content
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

Add hair effects #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
.pub-cache/
.pub/
/build/
.flutter-plugins-dependencies

# Android related
**/android/**/gradle-wrapper.jar
Expand Down
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.jvmargs=-Xmx1536M

android.enableR8=true
Binary file modified assets/galaxy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/rainbow1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\Users\User\Documents\flutter\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Users\User\Documents\FlutterApps\studypoints\studypoints"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "FLUTTER_FRAMEWORK_DIR=C:\Users\User\Documents\flutter\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
7 changes: 7 additions & 0 deletions lib/avatar/data/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Avatar {
String hair;
String skin;
String feet = 'assets/feet1.png';
String hairEffect;
Color hairColor = Colors.red;
List<String> accessoires = [];

Expand All @@ -16,6 +17,7 @@ class Avatar {
this.face,
this.hair,
this.skin,
this.hairEffect,
});

operator [](String type) {
Expand All @@ -32,6 +34,8 @@ class Avatar {
return skin;
case 'extra':
return accessoires;
case 'hairEffect':
return hairEffect;
}
}

Expand All @@ -52,6 +56,9 @@ class Avatar {
case 'skin':
skin = value;
break;
case 'hairEffect':
hairEffect = value;
break;
}
}
}
45 changes: 45 additions & 0 deletions lib/avatar/data/image_merger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:flutter/painting.dart';
import 'package:flutter/material.dart';
import 'dart:ui' as ui;
import 'dart:async';

class ImageMerger extends StatelessWidget {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A class comment would be helpful. You should also rename this class to make it more obvious that it is a widget.

final BlendMode blendMode;
final String image;
final Widget blendedWidget;

ImageMerger({
this.image,
this.blendedWidget,
this.blendMode = BlendMode.modulate,
});

Future<ui.Image> _getImage() {
Completer<ui.Image> completer = Completer<ui.Image>();
AssetImage(image).resolve(ImageConfiguration()).addListener(
ImageStreamListener(
(ImageInfo info, bool _) => completer.complete(info.image)));
return completer.future;
}

@override
Widget build(BuildContext context) {
return FutureBuilder<ui.Image>(
future: _getImage(),
builder: (BuildContext context, AsyncSnapshot<ui.Image> snapshot) {
if (snapshot.hasData) {
return ShaderMask(
blendMode: blendMode,
child: Container(child: blendedWidget),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Container can probably be removed

shaderCallback: (Rect bounds) {
return ImageShader(snapshot.data, TileMode.clamp, TileMode.clamp,
Matrix4.identity().storage);
},
Comment on lines +34 to +37
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use arrow notation here

);
} else {
return blendedWidget;
}
},
);
}
}
24 changes: 24 additions & 0 deletions lib/avatar/data/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,30 @@ class ShopItemRepository extends Repository<ShopItem> {
thumbnail: 'assets/extra2.png',
cost: 100,
),
ShopItem(
id: 'hairEffect1',
type: 'hairEffect',
name: 'Normal',
resource: 'assets/white.png',
thumbnail: 'assets/white.png',
cost: 50,
),
ShopItem(
id: 'hairEffect2',
type: 'hairEffect',
name: 'Galaxy',
resource: 'assets/galaxy.png',
thumbnail: 'assets/galaxy.png',
cost: 50,
),
ShopItem(
id: 'hairEffect3',
type: 'hairEffect',
name: 'Rainbow',
resource: 'assets/rainbow1.png',
thumbnail: 'assets/rainbow1.png',
cost: 50,
),
];

ShopItem fetch(String id) =>
Expand Down
4 changes: 4 additions & 0 deletions lib/avatar/widgets/avatar_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ class _AvatarScreenState extends State<AvatarScreen> {
return 'Skin';
case 'extra':
return 'Accessoires';
case 'hairEffect':
return 'Hair Effects';
default:
return 'Other';
}
}
}
Expand Down
18 changes: 14 additions & 4 deletions lib/avatar/widgets/avatar_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:studypoints/avatar/data/image_merger.dart';
import 'package:studypoints/services/user.dart';
import 'package:studypoints/avatar/data/avatar.dart';
import 'package:flutter/painting.dart';
Expand Down Expand Up @@ -42,10 +43,19 @@ class AvatarViewState extends State<AvatarView> {
Image.asset(getRessource(avatar.skin)),
Image.asset(getRessource(avatar.face)),
Image.asset("assets/head1.png"),
Image.asset(
getRessource(avatar.hair),
color: Provider.of<UserService>(context).avatar.hairColor,
colorBlendMode: BlendMode.modulate,
ImageMerger(
image: getRessource(avatar.hairEffect),
blendMode: BlendMode.modulate,
blendedWidget: Container(
width: widget.width,
height: widget.height,
child: Image.asset(
getRessource(avatar.hair),
color: avatar.hairEffect != 'hairEffect3'
? Provider.of<UserService>(context).avatar.hairColor
: Colors.white,
colorBlendMode: BlendMode.modulate,
)),
),
Image.asset("assets/ears1.png"),
Image.asset(getRessource(avatar.body)),
Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class StudyPointsApp extends StatelessWidget {
face: items.firstOfType('face').id,
hair: items.firstOfType('hair').id,
skin: items.firstOfType('skin').id,
hairEffect: items.firstOfType('hairEffect').id,
)),
),
],
Expand Down
1 change: 1 addition & 0 deletions lib/services/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class UserService {
ShopItemRepository().firstOfType('face').id,
ShopItemRepository().firstOfType('hair').id,
ShopItemRepository().firstOfType('body').id,
ShopItemRepository().firstOfType('hairEffect').id,
...ShopItemRepository().fetchType('skin').map((item) => item.id),
];

Expand Down
14 changes: 7 additions & 7 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "2.3.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -73,14 +73,14 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.1.7"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
version: "1.6.4"
path_provider:
dependency: transitive
description:
Expand All @@ -94,7 +94,7 @@ packages:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0+1"
provider:
dependency: "direct main"
description:
Expand All @@ -108,7 +108,7 @@ packages:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.5"
screenshot:
dependency: "direct main"
description:
Expand Down Expand Up @@ -155,7 +155,7 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
term_glyph:
dependency: transitive
description:
Expand Down