1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2011-2013 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Manages all assets usable by an Mnit app
27 # An String is an asset, returned from a text file
32 # An Image is an asset
38 # Load a genereal asset from file name
39 # Will find the file within the assets/ directory
40 # Crashes if file not found
41 fun load_asset
( id
: String ): Asset
43 var asset
= try_loading_asset
( id
)
44 if asset
== null then # error
45 print_error
"asset <{id}> could not be loaded."
52 # Load an Image assets
53 # Crashes if file not found or not an image
54 fun load_image
( id
: String ): Image
56 var asset
= load_asset
( id
)
57 if asset
isa Image then
60 print_error
"asset <{id}> is not an image."
65 # Load an assets without error if not found
66 fun try_loading_asset
( id
: String ): nullable Asset is abstract