|
Table of Contents
Scripts > ExportHeightfieldAsTiles
Script contentshvar hMap
set hMap <GetMap "HF">
int nx ny
set nx <map.GetWidth hMap>
set ny <map.GetHeight hMap>
assert nx "Map not initialised!"
string FileName
set FileName <file.SaveDlg "hf2" NULL "HF2 files (*.hf2)|*.hf2|All files (*.*)|*.*|">
if <not <strlen FileName>>
return false
endif
string BaseFileName
set BaseFileName <file.GetFilenameNoExt FileName>
string FileExt
set FileExt <file.GetExt FileName>
hvar hFormat
set hFormat <GetFormat "HF" 0 FileExt>
assert hFormat "Cannot find format!"
int TileSize
set TileSize 512
if <not <EditUI &TileSize "Enter tile size">>
return false
endif
assert <isgt TileSize 1> "Invalid tile size!"
int nTilesX
set nTilesX <div nx TileSize>
if <mod nx TileSize>
incr nTilesX
endif
int nTilesY
set nTilesY <div ny TileSize>
if <mod ny TileSize>
incr nTilesY
endif
int ti tj
set tj 0
do
set ti 0
do
int x1 x2 y1 y2
set x1 <mul ti TileSize>
set y1 <mul tj TileSize>
set x2 <add x1 <sub TileSize 1>>
set y2 <add y1 <sub TileSize 1>>
if <not <islt x2 nx>>
set x2 <sub nx 1>
endif
if <not <islt y2 ny>>
set y2 <sub ny 1>
endif
string TileName
set TileName <strcat BaseFileName <strcat "_x" ti>>
set TileName <strcat TileName <strcat "_y" tj>>
set TileName <strcat TileName <strcat "." FileExt>>
assert <file.export.areaH hMap TileName hFormat x1 x2 y1 y2> "Export failed!"
while <islt <incr ti> nTilesX>
while <islt <incr tj> nTilesY>
return true
CommentsNone. Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
|