initial commit

This commit is contained in:
Chr1Z93 2023-04-14 17:34:02 +02:00
parent 3334907581
commit 647553558f
6 changed files with 157 additions and 19 deletions

View File

@ -53,5 +53,5 @@
"scaleZ": 10 "scaleZ": 10
}, },
"Value": 0, "Value": 0,
"XmlUI": "\u003cInclude src=\"playercards/PlayerCardPanel.xml\"/\u003e" "XmlUI": "\u003cInclude src=\"PlayerCardPanel.xml\"/\u003e"
} }

View File

@ -39,6 +39,12 @@ local mythosAreaApi = require("core/MythosAreaApi")
local tokenArrangerApi = require("accessories/TokenArrangerApi") local tokenArrangerApi = require("accessories/TokenArrangerApi")
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
-- online functionality related variables
local MOD_VERSION = "3.1.0"
local SOURCE_REPO = 'https://raw.githubusercontent.com/chr1z93/loadable-objects/main'
local library, requestObj
local dontNotify = {}
--------------------------------------------------------- ---------------------------------------------------------
-- data for tokens -- data for tokens
--------------------------------------------------------- ---------------------------------------------------------
@ -98,7 +104,7 @@ local tokenDrawingStats = {
--------------------------------------------------------- ---------------------------------------------------------
-- saving state of optionPanel to restore later -- saving state of optionPanel to restore later
function onSave() return JSON.encode({ optionPanel = optionPanel }) end function onSave() return JSON.encode({ optionPanel = optionPanel, dontNotify = dontNotify }) end
function onLoad(savedData) function onLoad(savedData)
if savedData then if savedData then
@ -114,6 +120,7 @@ function onLoad(savedData)
if obj ~= nil then obj.interactable = false end if obj ~= nil then obj.interactable = false end
end end
getModVersion()
math.randomseed(os.time()) math.randomseed(os.time())
end end
@ -613,21 +620,17 @@ end
-- Content Importing and XML functions -- Content Importing and XML functions
--------------------------------------------------------- ---------------------------------------------------------
local source_repo = 'https://raw.githubusercontent.com/chr1z93/loadable-objects/main'
local library = nil
local request_obj
function onClick_refreshList() function onClick_refreshList()
local request = WebRequest.get(source_repo .. '/library.json', completed_list_update) local request = WebRequest.get(SOURCE_REPO .. '/library.json', completed_list_update)
request_obj = request requestObj = request
startLuaCoroutine(Global, 'downloadCoroutine') startLuaCoroutine(Global, 'downloadCoroutine')
end end
function onClick_select(player, params) function onClick_select(player, params)
params = JSON.decode(urldecode(params)) params = JSON.decode(urldecode(params))
local url = source_repo .. '/' .. params.url local url = SOURCE_REPO .. '/' .. params.url
local request = WebRequest.get(url, function (request) complete_obj_download(request, params) end ) local request = WebRequest.get(url, function (request) complete_obj_download(request, params) end )
request_obj = request requestObj = request
startLuaCoroutine(Global, 'downloadCoroutine') startLuaCoroutine(Global, 'downloadCoroutine')
end end
@ -656,8 +659,8 @@ function onClick_toggleUi(_, title)
end end
function downloadCoroutine() function downloadCoroutine()
while request_obj do while requestObj do
UI.setAttribute('download_progress', 'percentage', request_obj.download_progress * 100) UI.setAttribute('download_progress', 'percentage', requestObj.download_progress * 100)
coroutine.yield(0) coroutine.yield(0)
end end
return 1 return 1
@ -731,7 +734,7 @@ function complete_obj_download(request, params)
end end
end end
request_obj = nil requestObj = nil
UI.setAttribute('download_progress', 'percentage', 100) UI.setAttribute('download_progress', 'percentage', 100)
end end
@ -755,7 +758,7 @@ function completed_list_update(request)
end end
end end
request_obj = nil requestObj = nil
UI.setAttribute('download_progress', 'percentage', 100) UI.setAttribute('download_progress', 'percentage', 100)
end end
@ -1034,3 +1037,60 @@ function titleSplash(scenarioName)
soundCubeApi.playSoundByName("Deep Bell") soundCubeApi.playSoundByName("Deep Bell")
end end
end end
---------------------------------------------------------
-- Update Notification related functionality
---------------------------------------------------------
-- grabs the latest mod version and release notes from GitHub
-- this is called onLoad()
function getModVersion()
WebRequest.get(SOURCE_REPO .. '/modversion.json', compareVersion)
end
-- compares the modversion with GitHub and reports if a new version is available
-- this is called as callback_function from getModVersion()
function compareVersion(request)
if request.is_error then
log(request.error)
return
end
local metatable = JSON.decode(request.text)
local latestVersion = metatable["latestVersion"]
--if MOD_VERSION == latestVersion then return end
if dontNotify[latestVersion] then return end
local releaseNotes = metatable["releaseNotes"][latestVersion]
if releaseNotes == nil then
log("Release notes for latest version not found!")
else
local ui = UI.getXmlTable()
local releaseNoteWrapper = find_tag_with_id(ui, 'releaseNoteWrapper')
releaseNoteWrapper.children = {}
for _, entry in pairs(releaseNotes["Highlights"]) do
table.insert(releaseNoteWrapper.children,
{ tag = 'Text',
value = entry,
attributes = { class="releaseNote" }
})
end
local header = find_tag_with_id(ui, 'versionHeader')
header.value = "New Version available: " .. latestVersion .. " (current: " .. MOD_VERSION .. ")"
UI.setXmlTable(ui)
end
-- small delay to avoid lagging
Wait.time(function() UI.show("updateNotification") end, 1)
end
-- close / don't show again buttons on the XML use this
function onClick_notification(_, parameter)
if parameter == "dontNotify" then
dontNotify[latestVersion] = true
end
UI.hide("updateNotification")
end

View File

@ -98,16 +98,14 @@
</VerticalLayout> </VerticalLayout>
<!-- Title Splash when starting a scenario --> <!-- Title Splash when starting a scenario -->
<Panel <Panel id="title_splash"
id="title_splash"
height="220" height="220"
position="0 250 0" position="0 250 0"
showAnimation="FadeIn" showAnimation="FadeIn"
hideAnimation="FadeOut" hideAnimation="FadeOut"
active="false" active="false"
animationDuration="2"> animationDuration="2">
<Image <Image id="title_gradient"
id="title_gradient"
height="220" height="220"
image="TitleGradient" /> image="TitleGradient" />
<Text id="title_splash_text" <Text id="title_splash_text"
@ -122,4 +120,6 @@
horizontalOverflow="Overflow"> horizontalOverflow="Overflow">
</Text> </Text>
</Panel> </Panel>
<Include src="OptionPanel.xml"/> <Include src="OptionPanel.xml"/>
<Include src="UpdateNotification.xml"/>

View File

@ -20,7 +20,7 @@
outline="grey" outline="grey"
showAnimation="SlideIn_Right" showAnimation="SlideIn_Right"
hideAnimation="SlideOut_Right" hideAnimation="SlideOut_Right"
animationDuration="0.1" /> animationDuration="0.2" />
<!-- group headers --> <!-- group headers -->
<Row class="group-header" <Row class="group-header"

View File

@ -0,0 +1,78 @@
<Defaults>
<Text color="#FFFFFF"
alignment="MiddleLeft" />
<Text class="releaseNote"
fontSize="18"/>
<!-- buttons at the bottom -->
<Button class="bottomButtons"
hoverClass="hover"
pressClass="press"
selectClass="select"
color="#888888"
minHeight="35"
fontSize="24"
font="font_teutonic-arkham"/>
<Button class="hover"
color="grey"/>
<Button class="press"
color="white"/>
<Button class="select"
color="white"/>
</Defaults>
<TableLayout id="updateNotification"
active="false"
color="#000000"
outlineSize="2 2"
outline="grey"
showAnimation="SlideIn_Top"
hideAnimation="SlideOut_Top"
animationDuration="0.2"
rectAlignment="UpperCenter"
offsetXY="0 -60"
height="200"
width="450">
<!-- Header -->
<Row preferredHeight="60">
<Cell>
<Panel padding="10 0 0 0">
<Text id="versionHeader"
font="font_teutonic-arkham"
fontSize="30"
alignment="MiddleCenter">New Version available: </Text>
</Panel>
</Cell>
</Row>
<!-- Scrollable part with release notes -->
<Row>
<Cell>
<VerticalScrollView horizontalScrollbarVisibility="AutohideAndExpandViewport">
<!-- this part will be updated via script -->
<VerticalLayout id="releaseNoteWrapper"
padding="10 0 0 0"
spacing="5">
<Text class="releaseNote">Entry 1</Text>
<Text class="releaseNote">Entry 2</Text>
</VerticalLayout>
</VerticalScrollView>
</Cell>
</Row>
<!-- Buttons: "Don't show again" and "Close" -->
<Row preferredHeight="50">
<Cell>
<HorizontalLayout minHeight="55"
flexibleHeight="0"
padding="10 10 5 10"
spacing="100">
<Button class="bottomButtons"
onClick="onClick_notification(dontNotify)">Don't show again</Button>
<Button class="bottomButtons"
onClick="onClick_notification(close)">Close</Button>
</HorizontalLayout>
</Cell>
</Row>
</TableLayout>