Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
67c481b2
Commit
67c481b2
authored
Aug 17, 2015
by
Eric Seidel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Teach Asteroids Sounds how to load from AssetBundle
@abarth
parent
4cae568f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
17 deletions
+24
-17
main.dart
examples/game/lib/main.dart
+2
-2
sound.dart
examples/game/lib/sound.dart
+4
-5
sound_manager.dart
examples/game/lib/sound_manager.dart
+0
-2
sprites.dart
examples/game/lib/sprites.dart
+1
-0
asset_bundle.dart
packages/flutter/lib/mojo/asset_bundle.dart
+15
-8
fetch.dart
packages/flutter/lib/mojo/net/fetch.dart
+2
-0
No files found.
examples/game/lib/main.dart
View file @
67c481b2
...
...
@@ -48,8 +48,8 @@ main() async {
_app
=
new
GameDemoApp
();
_sounds
[
"explosion"
]
=
new
SoundEffect
(
'https://github.com/slembcke/GalacticGuardian.spritebuilder/raw/GDC/Packages/SpriteBuilder%20Resources.sbpack/TempSounds/Explosion.wav'
);
_sounds
[
"laser"
]
=
new
SoundEffect
(
'https://github.com/slembcke/GalacticGuardian.spritebuilder/raw/GDC/Packages/SpriteBuilder%20Resources.sbpack/TempSounds/Laser.wav'
);
_sounds
[
"explosion"
]
=
new
SoundEffect
(
_bundle
.
load
(
'assets/explosion.wav'
)
);
_sounds
[
"laser"
]
=
new
SoundEffect
(
_bundle
.
load
(
'assets/laser.wav'
)
);
await
_sounds
[
"explosion"
].
load
();
await
_sounds
[
"laser"
].
load
();
...
...
examples/game/lib/sound.dart
View file @
67c481b2
...
...
@@ -6,16 +6,15 @@ part of sprites;
typedef
void
SoundEffectStreamCallback
(
SoundEffectStream
);
class
SoundEffect
{
SoundEffect
(
this
.
_
url
);
SoundEffect
(
this
.
_
pipeFuture
);
// TODO: Remove load method from SoundEffect
Future
load
()
async
{
UrlResponse
response
=
await
fetchUrl
(
_url
);
_data
=
response
.
body
;
_data
=
await
_pipeFuture
;
}
String
_url
;
Object
_data
;
Future
<
MojoDataPipeConsumer
>
_pipeFuture
;
MojoDataPipeConsumer
_data
;
}
class
SoundEffectStream
{
...
...
examples/game/lib/sound_manager.dart
View file @
67c481b2
...
...
@@ -54,7 +54,6 @@ class SoundManager {
static
void
purgeSharedInstance
()
{
if
(
_sharedSoundManager
==
null
)
return
;
_sharedSoundManager
.
_running
=
false
;
_sharedSoundManager
=
null
;
}
...
...
@@ -72,7 +71,6 @@ class SoundManager {
bool
enableBackgroundMusic
;
bool
enableSoundEffects
;
bool
_running
=
true
;
int
_lastTimeStamp
;
void
playEvent
(
SoundEvent
evt
,
[
double
volume
=
1.0
,
double
pitch
=
1.0
,
double
pan
=
0.0
])
{
...
...
examples/game/lib/sprites.dart
View file @
67c481b2
...
...
@@ -10,6 +10,7 @@ import 'dart:math' as math;
import
'dart:typed_data'
;
import
'dart:sky'
;
import
'package:mojo/core.dart'
;
import
'package:mojo/mojo/url_response.mojom.dart'
;
import
'package:sky/animation/curves.dart'
;
import
'package:sky/base/scheduler.dart'
as
scheduler
;
...
...
packages/flutter/lib/mojo/asset_bundle.dart
View file @
67c481b2
...
...
@@ -18,6 +18,7 @@ abstract class AssetBundle {
void
close
();
ImageResource
loadImage
(
String
key
);
Future
<
String
>
loadString
(
String
key
);
Future
<
core
.
MojoDataPipeConsumer
>
load
(
String
key
);
}
class
NetworkAssetBundle
extends
AssetBundle
{
...
...
@@ -27,13 +28,15 @@ class NetworkAssetBundle extends AssetBundle {
void
close
()
{
}
ImageResource
loadImage
(
String
key
)
{
return
image_cache
.
load
(
_baseUrl
.
resolve
(
key
).
toString
());
}
String
_urlFromKey
(
String
key
)
=>
_baseUrl
.
resolve
(
key
).
toString
();
Future
<
String
>
loadString
(
String
key
)
{
return
fetchString
(
_baseUrl
.
resolve
(
key
).
toString
())
;
Future
<
core
.
MojoDataPipeConsumer
>
load
(
String
key
)
async
{
return
(
await
fetchUrl
(
_urlFromKey
(
key
))).
body
;
}
ImageResource
loadImage
(
String
key
)
=>
image_cache
.
load
(
_urlFromKey
(
key
));
Future
<
String
>
loadString
(
String
key
)
=>
fetchString
(
_urlFromKey
(
key
));
}
Future
_fetchAndUnpackBundle
(
String
relativeUrl
,
AssetBundleProxy
bundle
)
async
{
...
...
@@ -66,19 +69,23 @@ class MojoAssetBundle extends AssetBundle {
ImageResource
loadImage
(
String
key
)
{
return
_imageCache
.
putIfAbsent
(
key
,
()
{
Completer
<
sky
.
Image
>
completer
=
new
Completer
<
sky
.
Image
>();
_bundle
.
ptr
.
getAsStream
(
key
).
then
((
response
)
{
new
sky
.
ImageDecoder
(
response
.
assetData
.
handle
.
h
,
completer
.
complete
);
load
(
key
).
then
((
assetData
)
{
new
sky
.
ImageDecoder
(
assetData
.
handle
.
h
,
completer
.
complete
);
});
return
new
ImageResource
(
completer
.
future
);
});
}
Future
<
String
>
_fetchString
(
String
key
)
async
{
core
.
MojoDataPipeConsumer
pipe
=
(
await
_bundle
.
ptr
.
getAsStream
(
key
)).
assetData
;
core
.
MojoDataPipeConsumer
pipe
=
await
load
(
key
)
;
ByteData
data
=
await
core
.
DataPipeDrainer
.
drainHandle
(
pipe
);
return
new
String
.
fromCharCodes
(
new
Uint8List
.
view
(
data
.
buffer
));
}
Future
<
core
.
MojoDataPipeConsumer
>
load
(
String
key
)
async
{
return
(
await
_bundle
.
ptr
.
getAsStream
(
key
)).
assetData
;
}
Future
<
String
>
loadString
(
String
key
)
{
return
_stringCache
.
putIfAbsent
(
key
,
()
=>
_fetchString
(
key
));
}
...
...
packages/flutter/lib/mojo/net/fetch.dart
View file @
67c481b2
...
...
@@ -12,6 +12,8 @@ import 'package:mojo_services/mojo/network_service.mojom.dart';
import
'package:mojo_services/mojo/url_loader.mojom.dart'
;
import
'package:sky/mojo/shell.dart'
as
shell
;
export
'package:mojo/mojo/url_response.mojom.dart'
show
UrlResponse
;
NetworkServiceProxy
_initNetworkService
(
)
{
NetworkServiceProxy
networkService
=
new
NetworkServiceProxy
.
unbound
();
shell
.
requestService
(
"mojo:authenticated_network_service"
,
networkService
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment