Skip to content

Instantly share code, notes, and snippets.

@TinkerWorX
Created November 20, 2019 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TinkerWorX/147f84434a18f27312ba41f0e4eaf9b5 to your computer and use it in GitHub Desktop.
Save TinkerWorX/147f84434a18f27312ba41f0e4eaf9b5 to your computer and use it in GitHub Desktop.
/* ========== READONLY =========== */
/* == CHANGES WILL BE DISCARDED == */
/* ========== READONLY =========== */
#define HEAL_ID 'u000'
#define MIN_DAMAGE_ID 'u001'
#define MAX_DAMAGE_ID 'u002'
#define ARMOR_ID 'u003'
#define BUILDER_ID 'u004'
#define VILLAGER_ID 'u005'
Units = { }
UnitIds = { }
Unit = { }
Unit.__index = Unit
local nextUnitId = 0
local function GenerateUnitId()
local id = string.format("u%03X", nextUnitId)
while objectexists(id) or UnitIds[id] ~= nil do
nextUnitId = nextUnitId + 1
id = string.format("u%03X", nextUnitId)
end
nextUnitId = nextUnitId + 1
UnitIds[id] = true
return id
end
local nextHeroId = 0
local function GenerateHeroId()
local id = string.format("U%03X", nextHeroId)
while objectexists(id) or UnitIds[id] ~= nil do
nextHeroId = nextHeroId + 1
id = string.format("U%03X", nextHeroId)
end
nextHeroId = nextHeroId + 1
UnitIds[id] = true
return id
end
function Unit:new(key, baseId, isHero)
if Units[key] ~= nil then
return nil
end
local unit = {
activeAbility = { key = "udaa", converter = function(value) return value end },
normalAbilities = { key = "uabi", converter = function(value) return table.concat(value, ",") end },
heroAbilities = { key = "uhab", converter = function(value) return table.concat(value, ",") end },
movementType = { key = "umvt", converter = function(value) return value end },
movementSpeedBase = { key = "umvs", converter = function(value) return value end },
race = { key = "urac", converter = function(value) return value end },
structuresBuilt = { key = "ubui", converter = function(value) return table.concat(value, ",") end },
upgradesUsed = { key = "upgr", converter = function(value) return table.concat(value, ",") end },
requirements = { key = "ureq", converter = function(value) return table.concat(value, ",") end },
goldCost = { key = "ugol", converter = function(value) return value end },
lumberCost = { key = "ulum", converter = function(value) return value end },
foodCost = { key = "ufoo", converter = function(value) return value end },
isBuilding = { key = "ubdg", converter = function(value) if value then return 1 end return 0 end },
buildTime = { key = "ubld", converter = function(value) return value end },
collisionSize = { key = "ucol", converter = function(value) return value end },
pathingMap = { key = "upat", converter = function(value) return value end },
placementRequires = { key = "upap", converter = function(value) return value end },
tooltip = { key = "utip", converter = function(value) return value end },
tooltipExtended = { key = "utub", converter = function(value) return value end },
name = { key = "unam", converter = function(value) return value end },
buttonPositionNormalX = { key = "ubpx", converter = function(value) return value end },
buttonPositionNormalY = { key = "ubpy", converter = function(value) return value end },
hotkeyNormal = { key = "uhot", converter = function(value) return value end },
castBackswing = { key = "ucbs", converter = function(value) return value end },
castPoint = { key = "ucpt", converter = function(value) return value end },
scalingValue = { key = "usca", converter = function(value) return value end },
hitPointsMaximum = { key = "uhpm", converter = function(value) return value end },
hitPointsRegenerationRate = { key = "uhpr", converter = function(value) return value end },
manaInitial = { key = "umpi", converter = function(value) return value end },
manaMaximum = { key = "umpm", converter = function(value) return value end },
manaRegeneration = { key = "umpr", converter = function(value) return value end },
-- attack 1
attack1AnimationBackswingPoint = { key = "ubs1", converter = function(value) return value end },
attack1AnimationDamagePoint = { key = "udp1", converter = function(value) return value end },
attack1CooldownTime = { key = "ua1c", converter = function(value) return value end },
attack1DamageNumberOfDice = { key = "ua1d", converter = function(value) return value end },
attack1DamageSidesPerDie = { key = "ua1s", converter = function(value) return value end },
attack1DamageBase = { key = "ua1b", converter = function(value) return value end },
attack1Range = { key = "ua1r", converter = function(value) return value end },
attack1RangeMotionBuffer = { key = "urb1", converter = function(value) return value end },
attack1TargetsAllowed = { key = "ua1g", converter = function(value) return table.concat(value, ",") end },
attack1WeaponSound = { key = "ucs1", converter = function(value) return value end },
attack1WeaponType = { key = "ua1w", converter = function(value) return value end },
-- attack 2
attack2AnimationBackswingPoint = { key = "ubs2", converter = function(value) return value end },
attack2AnimationDamagePoint = { key = "udp2", converter = function(value) return value end },
attack2CooldownTime = { key = "ua2c", converter = function(value) return value end },
attack2DamageNumberOfDice = { key = "ua2d", converter = function(value) return value end },
attack2DamageSidesPerDie = { key = "ua2s", converter = function(value) return value end },
attack2DamageBase = { key = "ua2b", converter = function(value) return value end },
attack2Range = { key = "ua2r", converter = function(value) return value end },
attack2RangeMotionBuffer = { key = "urb2", converter = function(value) return value end },
attack2TargetsAllowed = { key = "ua2g", converter = function(value) return table.concat(value, ",") end },
attack2WeaponSound = { key = "ucs2", converter = function(value) return value end },
attack2WeaponType = { key = "ua2w", converter = function(value) return value end },
-- attacks
attacksEnabled = { key = "uaen", converter = function(value) return value end },
-- defense
defenseBase = { key = "udef", converter = function(value) return value end },
defenseType = { key = "udty", converter = function(value) return value end },
}
setmetatable(unit, self)
unit.key = key
unit.baseId = baseId
unit.isHero = isHero or false
if unit.isHero then
unit.id = GenerateHeroId()
else
unit.id = GenerateUnitId()
end
table.insert(Units, unit)
return unit
end
function Unit:setBasicInfo(tooltip, tooltipExtended, hotkey)
local position = GetPosition(hotkey)
self.tooltip.value = tooltip .. " (|cffffcc00" .. position.key .. "|r)"
self.tooltipExtended.value = tooltipExtended
self.buttonPositionNormalX.value = position.x
self.buttonPositionNormalY.value = position.y
self.hotkeyNormal.value = position.key
end
function GenerateUnits()
setobjecttype("units")
for index = 1, #Units do
local unit = Units[index]
createobject(unit.baseId, unit.id)
logf("Generating " .. unit.key .. "('" .. unit.id .. "')...")
for k, v in pairs(unit) do
if type(v) == "table" and v.key ~= nil and v.value ~= nil then
logf(" * " .. unit.id .. "[" .. v.key .. "] = " .. tostring(v.converter(v.value)))
makechange(current, v.key, v.converter(v.value))
end
end
end
end
function GenerateUnitsOutput(file)
file = io.open(file, "w")
file:write("/* ========== READONLY =========== */", "\n")
file:write("/* == CHANGES WILL BE DISCARDED == */", "\n")
file:write("/* ========== READONLY =========== */", "\n")
file:write("", "\n")
table.foreach(Units, function(key, value) file:write("#define " .. value.key .. "_ID '" .. value.id .. "'", "\n") end)
file:close()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment