Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Utility Delegates #179

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

nbness2
Copy link

@nbness2 nbness2 commented Nov 13, 2019

What has been done?

  • Mutliple delegate features have been added to reduce the tediousness and bugs caused by rewriting code many times, and as a by-product make the code look a lot more tidy while keeping readability (depending of course on how you name stuff)
  • Added the functionality to use an AttributeKey<T> as a delegate for a Pawn extension property returning T. Example: var Player.protectItem by PROTECT_ITEM_ATTR
    -- You can operator invoke the AttributeKey<T> with a T value to return an AttributeDelegate<T> with a default value that you passed. Example: var Player.protectItem by PROTECT_ITEM_ATTR(false)
  • Added the functionality to set a Varp as a T delegate for a Player extension property returning T.
    -- IntVarp is included as a sample implementation of VarpDelegate. Example: var Player.questPoints by IntVarp(101)
  • Added the functionality to set a Varbit as a T delegate for a Player extension property returning T.
    -- IntVarbit is included as a sample implementation of VarbitDelegate. Example: var Player.slayerPoints by IntVarbit(4068)
    -- BoolVarbit is included as a sample implementation of VarbitDelegate. Example: var Player.gargoyleSlayer by BoolVarbit(4027)

This allows you to delegate a `Pawn` extension property to an `AttributeKey` for easy get/set. This is meant to reduce or potentially remove the possibility of bugs related to repeating code.
This may be a problem if you worry about getting something that isn't a `T`, but you can set a default value (thus delegating to an `AttributeDelegate` instead) using the invoke operator `()`.

Example: `val Pawn.isSmart by IS_SMART_ATTRIBUTE(defaultValue = true)`
`VarpDelegate` allows you to delegate a `Player` extension property to this to allow for easy getting and setting as well as intermediate translating if needed
An example usage of `IntVarp`: `var Player.questPoints by IntVarp(101) // 101 is the varp for Quest Points`

Now you can `Player.questPoints += 25` or `Player.questPoints = -200`
`VarbitDelegate` allows you to easily get and set the value of a varbit and have intermediate translations if necessary
Example usage: `val Player.slayerPoints by IntVarbit(4068) // 4068 is the varbit id for slayer points`
Example usage: `val Player.gargoyleSlayer by BoolVarbit(4027) // 4027 is the varbit id for Gargoyle Slayer unlock`
@nbness2
Copy link
Author

nbness2 commented Nov 13, 2019

[576657d]
Fixed VarbitDelegate.getVarbit using varbitId rather than varbitDef.varp resulting in either the wrong value being gotten or an exception being thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant