Skip to content

Commit

Permalink
Rect saves now use extentX and extentY instead of min/max x/y
Browse files Browse the repository at this point in the history
Also fixed loading for generators that were saved at the map border.
  • Loading branch information
Son-Guhun committed Dec 20, 2019
1 parent 6d4cf5b commit 6b291ec
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 61 deletions.
2 changes: 2 additions & 0 deletions release/trigger/07-Player Commands/02-Commands Fix.j
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ private function OnCommand takes nothing returns boolean
if args == "darkness" then
call ResetTerrainFog()
call SetDayNightModels("Environment\\DNC\\DNCLordaeron\\DNCLordaeronTerrain\\DNCLordaeronTerrain.mdl", "Environment\\DNC\\DNCLordaeron\\DNCLordaeronUnit\\DNCLordaeronUnit.mdl")
elseif args == "selection" then
call BlzFrameSetFocus(BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME, 0), true)
endif

return false
Expand Down
6 changes: 2 additions & 4 deletions release/trigger/07-Player Commands/50-Commands Usav.j
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ private function onCommand takes nothing returns boolean

set saveData.centerX = GetUnitX(generator)
set saveData.centerY = GetUnitY(generator)
set saveData.minX = GetRectMinX(userRect)
set saveData.minY = GetRectMinY(userRect)
set saveData.maxX = GetRectMaxX(userRect)
set saveData.maxY = GetRectMaxY(userRect)
set saveData.extentX = GUDR_GetGeneratorExtentX(generator)
set saveData.extentY = GUDR_GetGeneratorExtentY(generator)
endif

call SaveUnits(saveData)
Expand Down
61 changes: 41 additions & 20 deletions release/trigger/18-Rects/1-UserDefinedRects.j
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ function ToggleGUDRVisibility takes unit whichUnit, boolean switch, boolean show
boolean show => //!If switch is false, the visibility will be set to this value.
endfunction

function MoveGUDR takes unit centerUnit, real offsetX, real offsetY, boolean expand returns boolean
function MoveGUDR takes unit centerUnit, real extentX, real extentY, boolean expand returns boolean
unit centerUnit => //!The GUDR generator.
real offsetX
real offsetY
real extentX
real extentY
boolean expand => //!If true, the region's current borders will be expanded by the offsets.
//!If false, the region's borders will be set to the specified offets. (center +- offset)
endfunction
Expand Down Expand Up @@ -96,8 +96,8 @@ private struct Indices extends array
//! runtextmacro GUDR_INDEX("GROUP", "6")
//! runtextmacro GUDR_INDEX("HIDDEN", "7")
//! runtextmacro GUDR_INDEX("WEATHER_TYPE", "8")
//! runtextmacro GUDR_INDEX("OFFSET_X", "9")
//! runtextmacro GUDR_INDEX("OFFSET_Y", "10")
//! runtextmacro GUDR_INDEX("EXTENT_X", "9")
//! runtextmacro GUDR_INDEX("EXTENT_Y", "10")
endstruct

//! runtextmacro DeclareParentHashtableWrapperModule("hashTable", "true", "hT", "private")
Expand All @@ -106,8 +106,12 @@ endstruct
private struct UserDefinedRect extends array
// //! runtextmacro HashStruct_SetHashtableWrapper("hashTable")

//! runtextmacro HashStruct_NewPrimitiveFieldEx("hT", "offsetX","real","Indices.OFFSET_X")
//! runtextmacro HashStruct_NewPrimitiveFieldEx("hT", "offsetY","real","Indices.OFFSET_Y")
//! runtextmacro HashStruct_NewPrimitiveFieldEx("hT", "extentX","real","Indices.EXTENT_X")
//! runtextmacro HashStruct_NewPrimitiveFieldEx("hT", "extentY","real","Indices.EXTENT_Y")

static method get takes unit whichUnit returns thistype
return GetHandleId(whichUnit)
endmethod
endstruct
//=============================
//FUNCTIONS THAT RETURN BOOLEANS
Expand Down Expand Up @@ -162,6 +166,14 @@ function GUDR_GetGeneratorIdWeatherType takes integer generatorId returns intege
return LoadInteger(hashTable, generatorId, Indices.WEATHER_TYPE)
endfunction

function GUDR_GetGeneratorIdExtentX takes UserDefinedRect generatorId returns real
return generatorId.extentX
endfunction

function GUDR_GetGeneratorIdExtentY takes UserDefinedRect generatorId returns real
return generatorId.extentY
endfunction

//Unit as parameter

function GUDR_GetGeneratorRect takes unit generator returns rect
Expand All @@ -180,9 +192,18 @@ function GUDR_GetGeneratorWeatherType takes unit generator returns integer
return GUDR_GetGeneratorIdWeatherType(GetHandleId(generator))
endfunction

function GUDR_GetGeneratorExtentX takes unit generator returns real
return GUDR_GetGeneratorIdExtentX(GetHandleId(generator))
endfunction

function GUDR_GetGeneratorExtentY takes unit generator returns real
return GUDR_GetGeneratorIdExtentY(GetHandleId(generator))
endfunction

function GUDR_ConvertWeatherType takes integer weatherType returns integer
return LoadInteger(hashTable, 0, weatherType)
endfunction


private function GetGeneratorIdLightning takes integer genId, integer i returns lightning
return LoadLightningHandle(hashTable, genId, i)
Expand Down Expand Up @@ -420,7 +441,7 @@ function ToggleGUDRVisibility takes unit whichUnit, boolean toggle, boolean show
return true
endfunction

function MoveGUDR takes unit centerUnit, real offsetX, real offsetY, boolean expand returns boolean
function MoveGUDR takes unit centerUnit, real extentX, real extentY, boolean expand returns boolean
local UserDefinedRect unitId = GetHandleId(centerUnit)
local real centerX = GetUnitX(centerUnit)
local real centerY = GetUnitY(centerUnit)
Expand All @@ -440,20 +461,20 @@ function MoveGUDR takes unit centerUnit, real offsetX, real offsetY, boolean exp

//If user wants to expand or contract the current region, Load the current value of its borders
if expand then
set offsetX = RMaxBJ(offsetX + unitId.offsetX, 32)
set offsetY = RMaxBJ(offsetY + unitId.offsetY, 32)
set extentX = RMaxBJ(extentX + unitId.extentX, 32)
set extentY = RMaxBJ(extentY + unitId.extentY, 32)
else
set offsetX = RMaxBJ(offsetX, 32)
set offsetY = RMaxBJ(offsetY, 32)
set extentX = RMaxBJ(extentX, 32)
set extentY = RMaxBJ(extentY, 32)
endif
set unitId.offsetX = offsetX
set unitId.offsetY = offsetY
set unitId.extentX = extentX
set unitId.extentY = extentY

//Set the values of the borders based on the offsets
set minX = centerX - offsetX
set maxX = centerX + offsetX
set minY = centerY - offsetY
set maxY = centerY + offsetY
set minX = centerX - extentX
set maxX = centerX + extentX
set minY = centerY - extentY
set maxY = centerY + extentY

//Update Rect
static if LIBRARY_AutoRectEnvironment then
Expand Down Expand Up @@ -519,8 +540,8 @@ function CreateGUDR takes unit centerUnit returns boolean
call SaveBoolean(hashTable, unitId, Indices.HIDDEN, true) //Save show/hide boolean as true, because nothing is being hidden
call SaveInteger(hashTable, unitId, Indices.WEATHER_TYPE, 1) //Save 1 as it is the value of 'RAhr'

set unitId.offsetX = 32
set unitId.offsetY = 32
set unitId.extentX = 32
set unitId.extentY = 32

set userDefRect = null
return true
Expand Down
6 changes: 2 additions & 4 deletions release/trigger/28-Save System/07-SaveDestructable.j
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ function SaveLoopActions2 takes nothing returns nothing
set playerId.saveData = SaveData.create(saver, SaveNLoad_FOLDER() + SubString(GetEventPlayerChatString(), 6, 129))
set playerId.saveData.centerX = GetUnitX(generator)
set playerId.saveData.centerY = GetUnitY(generator)
set playerId.saveData.minX = GetRectMinX(rectangle)
set playerId.saveData.minY = GetRectMinY(rectangle)
set playerId.saveData.maxX = GetRectMaxX(rectangle)
set playerId.saveData.maxY = GetRectMaxY(rectangle)
set playerId.saveData.extentX = GUDR_GetGeneratorExtentX(generator)
set playerId.saveData.extentY = GUDR_GetGeneratorExtentY(generator)

call EnumDestructablesInRect(rectangle, Condition(function SaveFilter), null)

Expand Down
6 changes: 2 additions & 4 deletions release/trigger/28-Save System/08-SaveTerrain.j
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ function SaveTerrain takes nothing returns nothing
set playerId.saveData = SaveData.create(GetTriggerPlayer(), SaveNLoad_FOLDER() + SubString(GetEventPlayerChatString(), 6, 129))
set playerId.saveData.centerX = GetUnitX(generator)
set playerId.saveData.centerY = GetUnitY(generator)
set playerId.saveData.minX = GetRectMinX(saveRect)
set playerId.saveData.minY = GetRectMinY(saveRect)
set playerId.saveData.maxX = GetRectMaxX(saveRect)
set playerId.saveData.maxY = GetRectMaxY(saveRect)
set playerId.saveData.extentX = GUDR_GetGeneratorExtentX(generator)
set playerId.saveData.extentY = GUDR_GetGeneratorExtentY(generator)

set saveRect = GUDR_GetGeneratorRect(generator)
set playerId.minX = GetRectMinX(saveRect)
Expand Down
4 changes: 2 additions & 2 deletions release/trigger/28-Save System/15-SaveNLoad.j
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ static if LIBRARY_UserDefinedRects then
function Save_GetGUDRSaveString takes integer generatorId returns string
local rect userRect = GUDR_GetGeneratorIdRect(generatorId)

local real length = GetRectMaxX(userRect) - GetRectCenterX(userRect)
local real height = GetRectMaxY(userRect) - GetRectCenterY(userRect)
local real length = GUDR_GetGeneratorIdExtentX(generatorId)
local real height = GUDR_GetGeneratorIdExtentY(generatorId)
local integer weatherType = GUDR_GetGeneratorIdWeatherType(generatorId)
local boolean hidden
local TerrainFog fog
Expand Down
42 changes: 16 additions & 26 deletions release/trigger/28-Save System/16-SaveIO.j
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ struct SaveData extends array

//! runtextmacro TableStruct_NewPrimitiveField("centerX", "real")
//! runtextmacro TableStruct_NewPrimitiveField("centerY", "real")
//! runtextmacro TableStruct_NewPrimitiveField("minX", "real")
//! runtextmacro TableStruct_NewPrimitiveField("minY", "real")
//! runtextmacro TableStruct_NewPrimitiveField("maxX", "real")
//! runtextmacro TableStruct_NewPrimitiveField("maxY", "real")
//! runtextmacro TableStruct_NewPrimitiveField("extentX", "real")
//! runtextmacro TableStruct_NewPrimitiveField("extentY", "real")

private method start takes nothing returns nothing
if GetLocalPlayer() == .player then
Expand Down Expand Up @@ -160,7 +158,7 @@ function SomeRandomName takes nothing returns nothing //") // Not calling Prelo

private method getMetaString takes nothing returns string
return FormatStringLocal(IO_ABILITY(), "v" + I2S(.VERSION) + "," + I2S(.current) + "," + R2S(.centerX) + "," + R2S(.centerY) + "," + /*
*/ R2S(.minX) + "," + R2S(.minY) + "," + R2S(.maxX) + "," + R2S(maxY))
*/ R2S(.extentX) + "," + R2S(.extentY))
endmethod

method destroy takes nothing returns nothing
Expand Down Expand Up @@ -192,6 +190,10 @@ function SomeRandomName takes nothing returns nothing //") // Not calling Prelo
call .currentClear()
call .folderClear()
call .playerClear()
call .centerXClear()
call .centerYClear()
call .extentXClear()
call .extentYClear()

implement GMUI_deallocate_this
endif
Expand All @@ -206,10 +208,8 @@ struct SaveLoader extends array
//! runtextmacro TableStruct_NewReadonlyPrimitiveField("version", "integer")
//! runtextmacro TableStruct_NewPrimitiveField("centerX", "real")
//! runtextmacro TableStruct_NewPrimitiveField("centerY", "real")
//! runtextmacro TableStruct_NewReadonlyPrimitiveField("minX", "real")
//! runtextmacro TableStruct_NewReadonlyPrimitiveField("minY", "real")
//! runtextmacro TableStruct_NewReadonlyPrimitiveField("maxX", "real")
//! runtextmacro TableStruct_NewReadonlyPrimitiveField("maxY", "real")
//! runtextmacro TableStruct_NewReadonlyPrimitiveField("extentX", "real")
//! runtextmacro TableStruct_NewReadonlyPrimitiveField("extentY", "real")

//! runtextmacro TableStruct_NewReadonlyPrimitiveField("atOriginal", "boolean")

Expand All @@ -219,7 +219,7 @@ struct SaveLoader extends array
//! runtextmacro TableStruct_NewReadonlyHandleField("player", "player")

method isRectSave takes nothing returns boolean
return this.minX != 0
return this.extentX != 0
endmethod

// Reads the current file and increments the counter.
Expand Down Expand Up @@ -275,19 +275,11 @@ struct SaveLoader extends array

if data != "" then
set index = CutToComma(data)
set .minX = S2R((SubString(data, 0, index)))
set .extentX = S2R((SubString(data, 0, index)))
set data = SubString(data, index+1, StringLength(data))

set index = CutToComma(data)
set .minY = S2R(SubString(data, 0, index))
set data = SubString(data, index+1, StringLength(data))

set index = CutToComma(data)
set .maxX = S2R((SubString(data, 0, index)))
set data = SubString(data, index+1, StringLength(data))

set index = CutToComma(data)
set .maxY = S2R(SubString(data, 0, index))
set .extentY = S2R(SubString(data, 0, index))
set data = SubString(data, index+1, StringLength(data))
endif

Expand All @@ -309,7 +301,7 @@ struct SaveLoader extends array

if SubString(data, 0, 1) == "v" then
call .parseData(data)
if .minX == 0 then
if .extentX == 0 then
set .atOriginal = true
endif
else
Expand All @@ -322,7 +314,7 @@ struct SaveLoader extends array
endif

call BJDebugMsg(R2S(.centerX) + "," + R2S(.centerY))
call BJDebugMsg(R2S(.minX) + "," + R2S(.minY) + "," + R2S(.maxX) + "," + R2S(.maxY))
call BJDebugMsg(R2S(.extentX) + "," + R2S(.extentY))

return this
endmethod
Expand All @@ -339,10 +331,8 @@ struct SaveLoader extends array

call .centerXClear()
call .centerYClear()
call .minXClear()
call .maxXClear()
call .minYClear()
call .maxYClear()
call .extentXClear()
call .extentYClear()

call .atOriginalClear()
implement GMUI_deallocate_this
Expand Down
2 changes: 1 addition & 1 deletion release/trigger/28-Save System/17-RectSaveLoader.j
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function onReceiveSize takes nothing returns nothing

set UnitData.get(generator).saveData = saveData
call CreateGUDR(generator)
call MoveGUDR(generator, saveData.maxX - saveData.centerX, saveData.maxY - saveData.centerY, false)
call MoveGUDR(generator, saveData.extentX, saveData.extentY, false)

if GetLocalPlayer() == GetTriggerPlayer() then
call ClearSelection()
Expand Down

0 comments on commit 6b291ec

Please sign in to comment.