-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gives a nice example of how to use the `ItemAccessWrapper` builder and where `BaseItemContainer` comes from
- Loading branch information
nbness2
committed
May 4, 2019
1 parent
240897d
commit 2c6dc35
Showing
2 changed files
with
38 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import itemstuff.BaseItem | ||
import container.Container | ||
import item.itemAccessWrapper | ||
|
||
val baseItemAccess = itemAccessWrapper<BaseItem> { | ||
getItemId(BaseItem::itemId) | ||
getItemAmount(BaseItem::itemAmount) | ||
getIsStackable(BaseItem::isStackable) | ||
createItem(::BaseItem) | ||
} | ||
|
||
fun BaseItemContainer(alwaysStackable: Boolean = false, vararg items: BaseItem): Container<BaseItem> = | ||
Container(items.size, alwaysStackable, baseItemAccess, items::get) | ||
|
||
/** | ||
* @author: nbness2 <nbness1337@gmail.com> | ||
* | ||
* Tests for [Container]s Safe Access | ||
*/ | ||
fun main() { | ||
// No tests for getFromSlot and set specifically because they will propagate through some of these tests and make them wrong. | ||
shiftTest() | ||
addItemTest() | ||
hasRoomTest() | ||
verifyTest() | ||
swapSlotTest() | ||
takeItemTest() | ||
} | ||
|
||
|
||
/** | ||
* @author: nbness2 <nbness1337@gmail.com> | ||
* | ||
* | ||
*/ | ||
fun expectedGot(testName: String, expected: Any, got: Any): String = | ||
"Test($testName): Expected $expected -- got $got" | ||
|
This file was deleted.
Oops, something went wrong.