- Joined
- Sep 26, 2009
- Messages
- 9,534
Expands on the API of handles to allow any handle other than weathereffects or terrain deformations to be saved/loaded from a hashtable. Pow!
This is a compliment to the common.j natives and to the TypeCasting Library.
This is a compliment to the common.j natives and to the TypeCasting Library.
JASS:
library Handle
/**************************************************************************************************************
* Handle API
* ¯¯¯¯¯¯¯¯¯¯
* You can now save <every type> into hashtables and load almost** everything, thanks to these functions.
*
* Since many JASS types extend a handle instead of an agent, this library enables some very useful commands.
* Thanks to KingKing for the "ConvertFogState" trick used in many of these functions and for inspiration.
* Thanks to Vexorian for the awesome JassHelper; any/all of these functions will inline when you use them.
*
*
* Example Useage
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* call SaveHandle(hash, 0, 0, CreateTextTag())
* call SaveHandle(hash, 0, 1, TriggerAddAction(t, function thistype.onLoop))
*
* call SetPlayerState(p, LoadPlayerStateHandle(hash, 0, 2), GetPlayerState(p, LoadPlayerStateHandle(hash, 0, 3)))
* call SetUnitState(u, LoadUnitStateHandle(hash, 0, 4), 9001)
*
*
* function SaveHandle takes hashtable table, integer parentKey, integer childKey, handle h returns boolean
*
* -> This is basically the same thing as SaveAgentHandle, only it saves *any handle* -- it does not have to
* be an agent-type. This is extremely useful for many reasons like generic saves and for saving types
* which could never be saved before (attacktype, damagetype, pathingtype, etc.)
*
* function SaveHandleId takes hashtable table, integer parentKey, integer childKey, handle h returns nothing
*
* -> This is pretty much a shortcut from typing GetHandleId() each time you just want to save a handle's
* integer reference.
*
* function Load$NAME$Handle takes hashtable table, integer parentKey, integer childKey returns $TYPE$
*
* -> Loads the handle of almost everything that wasn't in the hashtable API natives.
*
* function Load$NAME$HandleEx takes hashtable table, integer parentKey, integer childKey returns $TYPE$
*
* -> If you saved the handle as an integer, this will load/typecast the desired handle from that integer.
* I recommend using this method instead of simple Load$NAME$Handle because it's faster to do it this way.
* Just keep in mind that you can't use this function for types that were already in the hashtable native
* API functions - they must be loaded normally or from KingKing's typecasting library.
*/
function SaveHandle takes hashtable table, integer parentKey, integer childKey, handle h returns boolean
return SaveFogStateHandle(table, parentKey, childKey, ConvertFogState(GetHandleId(h)))
endfunction
function SaveHandleId takes hashtable table, integer parentKey, integer childKey, handle h returns nothing
call SaveInteger(table, parentKey, childKey, GetHandleId(h))
endfunction
//! textmacro ConvertHandleType takes NAME, TYPE
function Load$NAME$Handle takes hashtable table, integer parentKey, integer childKey returns $TYPE$
return Convert$NAME$(GetHandleId(LoadFogStateHandle(table, parentKey, childKey)))
endfunction
function Load$NAME$HandleEx takes hashtable table, integer parentKey, integer childKey returns $TYPE$
return Convert$NAME$(LoadInteger(table, parentKey, childKey))
endfunction
//! endtextmacro
//! runtextmacro ConvertHandleType("Race", "race")
//! runtextmacro ConvertHandleType("AllianceType", "alliancetype")
//! runtextmacro ConvertHandleType("RacePref", "racepreference")
//! runtextmacro ConvertHandleType("IGameState", "igamestate")
//! runtextmacro ConvertHandleType("FGameState", "fgamestate")
//! runtextmacro ConvertHandleType("PlayerState", "playerstate")
//! runtextmacro ConvertHandleType("PlayerScore", "playerscore")
//! runtextmacro ConvertHandleType("PlayerGameResult", "playergameresult")
//! runtextmacro ConvertHandleType("UnitState", "unitstate")
//! runtextmacro ConvertHandleType("AIDifficulty", "aidifficulty")
//! runtextmacro ConvertHandleType("GameEvent", "gameevent")
//! runtextmacro ConvertHandleType("PlayerEvent", "playerevent")
//! runtextmacro ConvertHandleType("PlayerUnitEvent", "playerunitevent")
//! runtextmacro ConvertHandleType("WidgetEvent", "widgetevent")
//! runtextmacro ConvertHandleType("DialogEvent", "dialogevent")
//! runtextmacro ConvertHandleType("UnitEvent", "unitevent")
//! runtextmacro ConvertHandleType("LimitOp", "limitop")
//! runtextmacro ConvertHandleType("UnitType", "unittype")
//! runtextmacro ConvertHandleType("GameSpeed", "gamespeed")
//! runtextmacro ConvertHandleType("Placement", "placement")
//! runtextmacro ConvertHandleType("StartLocPrio", "startlocprio")
//! runtextmacro ConvertHandleType("GameDifficulty", "gamedifficulty")
//! runtextmacro ConvertHandleType("GameType", "gametype")
//! runtextmacro ConvertHandleType("MapFlag", "mapflag")
//! runtextmacro ConvertHandleType("MapVisibility", "mapvisibility")
//! runtextmacro ConvertHandleType("MapSetting", "mapsetting")
//! runtextmacro ConvertHandleType("MapDensity", "mapdensity")
//! runtextmacro ConvertHandleType("MapControl", "mapcontrol")
//! runtextmacro ConvertHandleType("PlayerColor", "playercolor")
//! runtextmacro ConvertHandleType("PlayerSlotState", "playerslotstate")
//! runtextmacro ConvertHandleType("VolumeGroup", "volumegroup")
//! runtextmacro ConvertHandleType("CameraField", "camerafield")
//! runtextmacro ConvertHandleType("BlendMode", "blendmode")
//! runtextmacro ConvertHandleType("RarityControl", "raritycontrol")
//! runtextmacro ConvertHandleType("TexMapFlags", "texmapflags")
//! runtextmacro ConvertHandleType("EffectType", "effecttype")
//! runtextmacro ConvertHandleType("Version", "version")
//! runtextmacro ConvertHandleType("ItemType", "itemtype")
//! runtextmacro ConvertHandleType("AttackType", "attacktype")
//! runtextmacro ConvertHandleType("DamageType", "damagetype")
//! runtextmacro ConvertHandleType("WeaponType", "weapontype")
//! runtextmacro ConvertHandleType("SoundType", "soundtype")
//! runtextmacro ConvertHandleType("PathingType", "pathingtype")
/*
* Handles that were already in the hashtable API but cannot be saved with <SaveAgentHandle>:
*
* triggeraction -> LoadTriggerActionHandle
* texttag -> LoadTextTagHandle
* unitpool -> LoadUnitPoolHandle
* itempool -> LoadItemPoolHandle
*
* **Things which still cannot be typecasted:
*
* terraindeformation
* weathereffect
* camerasetup
*/
//*************************************************************************************************************
endlibrary
Last edited: