LUADOC - Farming Simulator 19

MapDataGrid

Description
A map data grid that splits a map in multiple sections
Parent
DataGrid
Functions

getRowColumnFromWorldPos

Description
Gets clamped row and column at given world position
Definition
getRowColumnFromWorldPos(float worldX, float worldZ)
Arguments
floatworldXworld position x
floatworldZworld position z
Return Values
integerrowrow
integercolumncolumn
Code
55function MapDataGrid:getRowColumnFromWorldPos(worldX, worldZ)
56 local mapSize = self.mapSize
57 local blocksPerRowColumn = self.blocksPerRowColumn
58
59 local x = (worldX + mapSize*0.5) / mapSize
60 local z = (worldZ + mapSize*0.5) / mapSize
61
62 local row = MathUtil.clamp(math.ceil(blocksPerRowColumn*z), 1, blocksPerRowColumn)
63 local column = MathUtil.clamp(math.ceil(blocksPerRowColumn*x), 1, blocksPerRowColumn)
64
65-- log(worldX, worldZ, " -> ", (worldX + self.mapSize*0.5), (worldZ + self.mapSize*0.5), z, x, row, column)
66
67 return row, column
68end

getValueAtWorldPos

Description
Get value at world position
Definition
getValueAtWorldPos(float worldX, float worldZ)
Arguments
floatworldXworld position x
floatworldZworld position z
Return Values
tablevaluevalue at the given position
Code
34function MapDataGrid:getValueAtWorldPos(worldX, worldZ)
35 local rowIndex, colIndex = self:getRowColumnFromWorldPos(worldX, worldZ)
36 return self:getValue(rowIndex, colIndex), rowIndex, colIndex
37end

new

Description
Creating data grid
Definition
new(integer mapSize, integer blocksPerRowColumn, table customMt)
Arguments
integermapSizemap size
integerblocksPerRowColumnblocks per row and column
tablecustomMtcustom metatable
Return Values
tableinstanceinstance of object
Code
19function MapDataGrid:new(mapSize, blocksPerRowColumn, customMt)
20 local self = DataGrid:new(blocksPerRowColumn, blocksPerRowColumn, customMt or MapDataGrid_mt)
21
22 self.blocksPerRowColumn = blocksPerRowColumn
23 self.mapSize = mapSize
24 self.blockSize = self.mapSize/self.blocksPerRowColumn
25
26 return self
27end

setValueAtWorldPos

Description
Set value at world position
Definition
setValueAtWorldPos(float worldX, float worldZ, table value)
Arguments
floatworldXworld position x
floatworldZworld position z
tablevaluevalue at the given position
Code
44function MapDataGrid:setValueAtWorldPos(worldX, worldZ, value)
45 local rowIndex, colIndex = self:getRowColumnFromWorldPos(worldX, worldZ)
46 self:setValue(rowIndex, colIndex, value)
47end