• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] NextPrev ObjectId

The description is in the documentation header.

NextPrevObjectId can be used for:
To be fair, almost same functionality can be found here in the BJObjectId library. But this library is a bit shorter, and only focusing on next/prev API, without other struct functionality. It seems for me now easier to use. And BJObjectId does not include 'a'-'z' symbols, which is covered here.

JASS:
library NextPrevObjectId /* v1.0  https://www.hiveworkshop.com/threads/nextprev-objectid.313328/

    Provides API to receive an ObjectId's next and prev ObjectId.
 
    Example for using next ObjectId:
    'A009' -> 'A00A'
    'A00z' -> 'A010'
 
    ObjectIds in the object editor work with symbols: 0-9 , A-Z , a-z ... they are ASCII symbols.
    Other ASCII symbols are not being used. The problem would exist if we would use a common +1 loop
    instead of NextPrevObjectId function, then we would also get all the other ASCIIs, which we might not want.
 
    Example with common +1 loop:
    'A009' -> 'A00:'
    'A00z' -> 'A00{'
 
    ^This is usually an unwanted result, which we don't need in our ObjectId loop.
    So this library is supposed to help looping through valid ObjectIds, considering only the wanted ASCII symbols.
 
    API
 
    function GetNextObjectId takes integer objectId returns integer
    function GetPrevObjectId takes integer objectId returns integer

*/
    globals
        private integer array pow256
        private integer array gapValue
    endglobals

    private function GetNextObjectId_private takes integer objectId, integer bytenumber returns integer
        local integer currentByteValue
        if ( bytenumber > -1 and bytenumber < 4 ) then
            set currentByteValue = ModuloInteger(objectId, pow256[bytenumber + 1])  / pow256[bytenumber]
        else
            return objectId
        endif
        if ( currentByteValue != '9' and currentByteValue != 'Z' and currentByteValue != 'z' ) then
            return objectId + pow256[bytenumber]
        else
            if ( currentByteValue != 'z' ) then
                return objectId + gapValue[currentByteValue] * pow256[bytenumber]
            else
                return GetNextObjectId_private(objectId - gapValue[currentByteValue] * pow256[bytenumber], (bytenumber + 1))
            endif
        endif
    endfunction
 
    private function GetPrevObjectId_private takes integer objectId, integer bytenumber returns integer
        local integer currentByteValue
        if ( bytenumber > -1 and bytenumber < 4 ) then
            set currentByteValue = ModuloInteger(objectId, pow256[bytenumber + 1])  / pow256[bytenumber]
        else
            return objectId
        endif
        if ( currentByteValue != '0' and currentByteValue != 'A' and currentByteValue != 'a' ) then
            return objectId - pow256[bytenumber]
        else
            if ( currentByteValue != '0' ) then
                return objectId - gapValue[currentByteValue] * pow256[bytenumber]
            else
                return GetPrevObjectId_private(objectId + gapValue[currentByteValue] * pow256[bytenumber], (bytenumber + 1))
            endif
        endif
    endfunction
 
    function GetPrevObjectId takes integer objectId returns integer
        return GetPrevObjectId_private(objectId, 0)
    endfunction
 
    function GetNextObjectId takes integer objectId returns integer
        return GetNextObjectId_private(objectId, 0)
    endfunction
 
    private module M
        private static method onInit takes nothing returns nothing
            local integer i = 0
            loop
                exitwhen i > 4
                set pow256[i] = R2I(Pow(256, i))
                set i = i + 1
            endloop
            set gapValue['9'] = 'A' - '9'
            set gapValue['Z'] = 'a' - 'Z'
            set gapValue['z'] = 'z' - '0'
            set gapValue['A'] = gapValue['9']
            set gapValue['a'] = gapValue['Z']
            set gapValue['0'] = gapValue['z']
        endmethod
    endmodule
    private struct S extends array
        implement M
    endstruct
endlibrary
 
Top