Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package otherlib.generic_girl {
- import flash.display.Sprite;
- import otherlib.core.DisplayFrame;
- /*
- * we need a variation on the singleton pattern.
- * Instead of a single dataset shared between all class instance
- * we need for each archetype to share a set of data
- *
- * so we implemnt this by taking the dataset (which is just an array)
- * and storing it in a static Object instance, indexed by arch name
- */
- public class MinipicManager {
- static var archetypes:Object = {};
- public function MinipicManager() {
- }
- /*
- * get the array for this archetype
- * if one doesn't exist yet, create it,
- * and add it to the object, indexed by arch
- */
- function get_list(arch:String):Array
- {
- var list:Array = archetypes[arch];
- if(list == null) {
- list = [];
- archetypes[arch] = list;
- }
- return list;
- }
- public function add(base:String, arch:String, path:String)
- {
- var list:Array = get_list(arch);
- var mc:Sprite = new DisplayFrame(50,50);
- list.push({
- sprite : mc,
- used : false
- });
- var pi = new PictureImage({ path : base + "/" + path });
- pi.make_mc(0, mc);
- }
- public function release(arch:String, incoming:Sprite)
- {
- var list:Array = get_list(arch);
- for each (var o in list) {
- /*
- * "===" is strict equivalence.
- * not only must the objects reduce to the
- * same value, they must be the same instance.
- *
- * is there a !== form? I'm about to find out
- */
- if(incoming !== o.sprite) {
- continue;
- }
- o.used = false;
- }
- }
- public function next_pic(arch):Sprite
- {
- var count = 0;
- var list:Array = get_list(arch);
- for each (var o in list) {
- if(o.used) {
- count ++;
- continue;
- }
- o.used = true;
- // "sprite" is actually a dispaly frame at the moment
- o.sprite.id = arch + ":" + count;
- return o.sprite;
- }
- throw new Error("No free pics for archetype '" + arch + "'");
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement