- Joined
- Jun 21, 2012
- Messages
- 431
JASS:
library TerrainSkin/*
****************************************************************************************************************
*
* ************************************************************************************************************
*
* */ uses /*
* */ DimensionalArray /* hiveworkshop.com/forums/submissions-414/snippet-dimensional-array-265011/
* */ WorldBounds /* github.com/nestharus/JASS/blob/master/jass/Systems/WorldBounds/script.j
*
* ************************************************************************************************************
*
* TerrainSkin
* ___________
* v1.0.1.1
* by Trigger.edge
*
* Change the terrain texture without lost the original set.
*
* API:
* ____
* struct TerrainSkin extends array
* - static method create takes real x, real y, integer terrainType, boolean permanent returns TerrainSkin
* - creates a TerrainSkin.
* - method destroy takes nothing returns nothing
* - destroy it.
* - static method getDefault takes real x, real y returns integer
* - get default terrain set.
*
* Credits:
* ________
* - Nestharus: WorldBounds
*
***************************************************************************************************************/
struct TerrainSkin extends array
private static Array data=0
private static method getTile takes real xy, real mincord, real maxcord returns integer
local integer tile
if(xy<0)then
set tile=R2I(mincord)
loop
exitwhen(tile>=0 or tile>=xy-64)
set tile=tile+128
endloop
else
set tile=R2I(maxcord)
loop
exitwhen(tile<=0 or tile<=xy+64)
set tile=tile-128
endloop
endif
return tile
endmethod
static method getDefault takes real x, real y returns integer
local integer ix=getTile(x,WorldBounds.minX,WorldBounds.maxX)
local integer iy=getTile(y,WorldBounds.minY,WorldBounds.maxY)
local integer i=data[ix][iy].integer
if(0==i)then
set data[ix][iy].integer=GetTerrainType(ix,iy)
return data[ix][iy].integer
endif
return i
endmethod
private method changeSkin takes real x, real y, integer terrainType returns nothing
local integer ix=getTile(x,WorldBounds.minX,WorldBounds.maxX)
local integer iy=getTile(y,WorldBounds.minY,WorldBounds.maxY)
if(not data[ix][iy].has.integer)then
set data[ix][iy].integer=GetTerrainType(ix,iy)
endif
call SetTerrainType(ix,iy,terrainType,-1,1,0)
endmethod
static method create takes real x, real y, integer terrainType, boolean permanent returns TerrainSkin
local thistype this=data[0].integer
if(0==data[this].integer)then
set data[0].integer=this+1
else
set data[0].integer=data[this].integer
call data[this].remove.integer()
endif
set data[0][this].real=x
set data[1][this].real=y
set data[-1][this].integer=terrainType
call .changeSkin(x,y,terrainType)
return this
endmethod
method destroy takes nothing returns nothing
call .changeSkin(data[0][this].real,data[1][this].real,data[-1][this].integer)
call data[0][this].remove.real()
call data[1][this].remove.real()
call data[-1][this].remove.integer()
set data[this].integer=data[0].integer
set data[0].integer=this
endmethod
private static method onInit takes nothing returns nothing
set data=Array.create()
set data[0].integer=1
endmethod
endstruct
endlibrary
Last edited: