Implemented Campaign Importer/Exporter!

This commit is contained in:
Jorge Parra 2023-03-17 23:56:49 -04:00
parent 4fa1eb6040
commit ab42241199

View File

@ -0,0 +1,210 @@
local campaignTokenData = {
GUID = "51b1c9",
Name = "Custom_Model",
Transform = {
posX = 2.80123329,
posY = 1.681688,
posZ = -23.6498032,
rotX = -2.22745348E-06,
rotY = 269.999664,
rotZ = -1.6614282E-06,
scaleX = 2.00499868,
scaleY = 2.00499868,
scaleZ = 2.00499868
},
Nickname = "Arkham Coin",
Description = "SCED Importer Token",
GMNotes = "",
AltLookAngle = {
x = 0.0,
y = 0.0,
z = 0.0
},
ColorDiffuse = {
r = 1.0,
g = 1.0,
b = 1.0
},
LayoutGroupSortIndex = 0,
Value = 0,
Locked = false,
Grid = true,
Snap = true,
IgnoreFoW = false,
MeasureMovement = false,
DragSelectable = true,
Autoraise = true,
Sticky = true,
Tooltip = true,
GridProjection = false,
HideWhenFaceDown = false,
Hands = false,
CustomMesh = {
MeshURL = "http://cloud-3.steamusercontent.com/ugc/943949966265929204/A38BB5D72419E6298385556D931877C0A1A55C17/",
DiffuseURL = "http://cloud-3.steamusercontent.com/ugc/254843371583188147/920981125E37B5CEB6C400E3FD353A2C428DA969/",
NormalURL = "",
ColliderURL = "http://cloud-3.steamusercontent.com/ugc/943949966265929204/A38BB5D72419E6298385556D931877C0A1A55C17/",
Convex = true,
MaterialIndex = 2,
TypeIndex = 0,
CustomShader = {
SpecularColor = {
r = 0.7222887,
g = 0.507659256,
b = 0.339915335
},
SpecularIntensity = 0.4,
SpecularSharpness = 7.0,
FresnelStrength = 0.0
},
CastShadows = true
},
LuaScript = "",
LuaScriptState = "",
XmlUI = ""
}
-- values for physics.cast
local PHYSICS_POSITION = { -00.0, 2, -27 }
local PHYSICS_ROTATION = 0
local PHYSICS_SCALE = { 05.0, 1, 05.0 }
-- enable this for debugging
local SHOW_RAYS = false
local campaignData = {}
local campaignZone = getObjectFromGUID("b6e806")
local tokenZone = getObjectFromGUID("ef3b5f")
local logZone = getObjectFromGUID("cc3540")
local campaignBoxGUID = ""
function onLoad(save_state)
self.createButton({
click_function = "findCampaignFromToken",
function_owner = self,
label = "Import",
position = {x=-1, y=0.2, z=0},
width = 350,
height = 150,
scale = {2, 1, 2},
})
self.createButton({
click_function = "createCampaignToken",
function_owner = self,
label = "Export",
position = {x=1, y=0.2, z=0},
width = 350,
height = 150,
scale = {2, 1, 2},
})
end
function findCampaignFromToken(_, _, _)
local coin = nil
for _, obj in ipairs(tokenZone.getObjects()) do
if obj.getDescription() == "SCED Importer Token" then
coin = obj
end
end
if coin == nil then
broadcastToAll("Could not find importer token", Color.Red)
else
local importData = JSON.decode(coin.getGMNotes())
campaignBoxGUID = importData[1]
local campaignBox = getObjectFromGUID(campaignBoxGUID)
if campaignBox.type == "Generic" then
campaignBox.call("buttonClick_download")
end
Wait.condition(
function()
if #campaignBox.getObjects() > 0 then
placeCampaignFromToken(importData)
else
createCampaignFromToken(importData)
end
end,
function()
local obj = getObjectFromGUID(campaignBoxGUID)
if obj == nil then
return false
else
return obj.type == "Bag" and obj.getLuaScript() ~= ""
end
end,
2,
function() broadcastToAll("Error loading campaign box") end
)
end
end
function placeCampaignFromToken(importData)
getObjectFromGUID(campaignBoxGUID).call("buttonClick_place")
Wait.condition(
function() createCampaignFromToken(importData) end,
function() return findCampaignLog() ~= nil end,
2,
function() broadcastToAll("Error placing campaign box") end
)
end
function createCampaignFromToken(importData)
findCampaignLog().destruct()
findChaosBag().destruct()
spawnObjectData({data = importData[2]})
spawnObjectData({data = importData[3]})
broadcastToAll("Campaign successfully imported!", Color.Green)
end
function createCampaignToken(_, _, _)
local campaignBoxGUID = ""
-- find active campaign
for _, obj in ipairs(campaignZone.getObjects()) do
if obj.type == "Bag" and #obj.getObjects() == 0 then
campaignBoxGUID = obj.getGUID()
end
end
if campaignBoxGUID == "" then
broadcastToAll("Campaign box with all placed objects not found!", Color.Red)
return
end
local campaignLog = findCampaignLog()
if campaignLog == nil then
broadcastToAll("Campaign log not found in standard position!", Color.Red)
return
end
local chaosBag = findChaosBag()
if chaosBag == nil then
broadcastToAll("Chaos bag not found in standard position!", Color.Red)
return
end
campaignData = {campaignBoxGUID, campaignLog.getData(), chaosBag.getData()}
campaignTokenData.GMNotes = JSON.encode(campaignData)
spawnObjectData({
data = campaignTokenData,
position = {-21.25, 1.68, 55.59}
})
end
-- helper functions
function findCampaignLog()
for _, obj in ipairs(logZone.getObjects()) do
if string.find(obj.getName(), "Campaign Log") ~= nil then
return obj
end
end
return nil
end
-- checks scripting zone for chaos bag
function findChaosBag()
for _, item in ipairs(getObjectFromGUID("83ef06").getObjects()) do
if item.getDescription() == "Chaos Bag" then
return item
end
end
end