inventorydynamiclist to have more options; fixed wrong shade values for trees; commonresourcepool to check dupes

This commit is contained in:
minjaesong
2019-08-05 04:58:33 +09:00
parent 63b1fcb870
commit 5f4305283d
3 changed files with 65 additions and 33 deletions

View File

@@ -46,6 +46,17 @@ object CommonResourcePool {
t.flip(false, true)
/*return*/t
}
loadAll()
}
fun resourceExists(name: String): Boolean {
loadingList.forEach {
if (it.name == name) return true
}
pool.forEach {
if (it.key == name) return true
}
return false
}
/**
@@ -67,26 +78,30 @@ object CommonResourcePool {
* - net.torvald.UnsafePtr
*/
fun addToLoadingList(identifier: String, loadFunction: () -> Any, destroyFunction: (() -> Unit)?) {
loadingList.addFirst(ResourceLoadingDescriptor(identifier, loadFunction, destroyFunction))
// check if resource is already there
if (!resourceExists(identifier)) {
loadingList.addFirst(ResourceLoadingDescriptor(identifier, loadFunction, destroyFunction))
if (loadCounter == -1)
loadCounter = 1
else
loadCounter += 1
if (loadCounter == -1)
loadCounter = 1
else
loadCounter += 1
}
}
/**
* Consumes the loading list. After the load, the list will be empty
*/
fun loadAll() {
if (loaded) throw IllegalStateException("Assets are already loaded and shipped out :p")
if (loaded) return //throw IllegalStateException("Assets are already loaded and shipped out :p")
while (!loadingList.isEmpty) {
val (name, loadfun, killfun) = loadingList.removeFirst()
if (pool.containsKey(name)) {
// no need for the collision checking; quarantine is done when the loading list is being appended
/*if (pool.containsKey(name)) {
throw IllegalArgumentException("Assets with identifier '$name' already exists.")
}
}*/
//typesMap[name] = type
pool[name] = loadfun.invoke()