/** * Constructs a set of all assets in the given list of repositories, then builds a map of <code> * MD5Key</code> and <code>Asset</code> for all assets that do not appear in that set. * * <p>This provides the calling function with a list of all assets currently in use by the * campaign that do not appear in one of the listed repositories. It's entirely possible that the * asset is in a different repository or in none at all. * * @param repos list of repositories to exclude * @return Map of all known assets that are NOT in the specified repositories */ public static Map<MD5Key, Asset> findAllAssetsNotInRepositories(List<String> repos) { // For performance reasons, we calculate the size of the Set in advance... int size = 0; for (String repo : repos) { size += assetLoader.getRepositoryMap(repo).size(); } // Now create the aggregate of all repositories. Set<String> aggregate = new HashSet<String>(size); for (String repo : repos) { aggregate.addAll(assetLoader.getRepositoryMap(repo).keySet()); } /* * The 'aggregate' now holds the sum total of all asset keys that are in repositories. Now we go through the * 'assetMap' and copy over <K,V> pairs that are NOT in 'aggregate' to our 'missing' Map. * * Unfortunately, the repository is a Map<String, String> while the return value is going to be a Map<MD5Key, * Asset>, which means each individual entry needs to be checked and references copied. If both were the same * data type, converting both to Set<String> would allow for an addAll() and removeAll() and be done with it! */ Map<MD5Key, Asset> missing = new HashMap<MD5Key, Asset>(Math.min(assetMap.size(), aggregate.size())); for (MD5Key key : assetMap.keySet()) { if (aggregate.contains(key) == false) // Not in any repository so add it. missing.put(key, assetMap.get(key)); } return missing; }
@Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { screenX = scaleX(screenX); screenY = scaleY(screenY); if (world.isMenu()) { if (playButton.isTouchUp(screenX, screenY)) { world.restart(); world.setRunning(); return true; } else if (sfxButton.isTouchUp(screenX, screenY)) { if (AssetLoader.getSfx()) { sfxButton.setSwitchOn(false); AssetLoader.setSfx(false); } else { sfxButton.setSwitchOn(true); AssetLoader.setSfx(true); } return true; } } return false; }
/** * This method accepts the name of a repository (as it appears in the CampaignProperties) and * updates it by adding the additional mappings that are in <code>add</code>. * * <p>This method first retrieves the mapping from the AssetLoader. It then adds in the new * assets. Last, it has to create the new index file. The index file should be stored in the local * repository cache. Note that this function <b>does not</b> update the original (network storage) * repository location. * * <p>If the calling function does not update the network storage for <b>index.gz</b>, a restart * of MapTool will lose the information when the index is downloaded again. * * @param repo name of the repository to update * @param add entries to add to the repository * @return the contents of the new repository in uploadable format */ public static byte[] updateRepositoryMap(String repo, Map<String, String> add) { Map<String, String> repoMap = assetLoader.getRepositoryMap(repo); repoMap.putAll(add); byte[] index = assetLoader.createIndexFile(repo); try { assetLoader.storeIndexFile(repo, index); } catch (IOException e) { log.error("Couldn't save updated index to local repository cache", e); e.printStackTrace(); } return index; }
/** * Request that the asset be loaded from the server * * @param id MD5 of the asset to load from the server */ private static void requestAssetFromServer(MD5Key id, AssetAvailableListener... listeners) { if (id != null) { addAssetListener(id, listeners); assetLoader.requestAsset(id); } }
/** * Add the asset to the asset cache. Listeners for this asset are notified. * * @param asset Asset to add to cache */ public static void putAsset(Asset asset) { if (asset == null) { return; } assetMap.put(asset.getId(), asset); // Invalid images are represented by empty assets. // Don't persist those if (asset.getImage().length > 0) { putInPersistentCache(asset); } // Clear the waiting status assetLoader.completeRequest(asset.getId()); // Listeners List<AssetAvailableListener> listenerList = assetListenerListMap.get(asset.getId()); if (listenerList != null) { for (AssetAvailableListener listener : listenerList) { listener.assetAvailable(asset.getId()); } assetListenerListMap.remove(asset.getId()); } }
public InputHandler(GameWorld world, float scaleFactorX, float scaleFactorY) { this.world = world; bombs = world.getBombs(); this.scaleFactorX = scaleFactorX; this.scaleFactorY = scaleFactorY; menuButtons = new ArrayList<SimpleButton>(); playButton = new SimpleButton(50, 50, 200, 200, AssetLoader.bombTexture2, AssetLoader.bombTexture3); getMenuButtons().add(playButton); sfxButton = new SimpleButton(50, 300, 200, 200, AssetLoader.bombTexture1, AssetLoader.bombTexture3); if (AssetLoader.getSfx()) { sfxButton.setSwitchOn(true); } else { sfxButton.setSwitchOn(false); } getMenuButtons().add(sfxButton); }
/** * Adds an AssetLoader to this AssetManager. * * @param <T> the type of assets the AssetLoader loads * @param loader the AssetLoader to add * @param type the type of assets the AssetLoader loads. */ public <T> void addAssetLoader(AssetLoader<T> loader, Class<T> type) { loaders.put(type, loader); loader.setAssetManager(this); }
/** * Remove all existing repositories and load all the repositories from the currently loaded * campaign. */ public static void updateRepositoryList() { assetLoader.removeAllRepositories(); for (String repo : MapTool.getCampaign().getRemoteRepositoryList()) { assetLoader.addRepository(repo); } }
/** * Determine if the asset is currently being requested. While an asset is being loaded it will be * marked as requested and this function will return true. Once the asset is done loading this * function will return false and the asset will be available from the cache. * * @param key MD5Key of asset being requested * @return True if asset is currently being requested, false otherwise */ public static boolean isAssetRequested(MD5Key key) { return assetLoader.isIdRequested(key); }