Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added loading bar to steemworlds addon #15

Merged
merged 2 commits into from
May 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 77 additions & 15 deletions STEEM.CRAFT/addons/steemworlds.sk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# ==============
# steemworlds.sk v0.0.5
# steemworlds.sk v0.0.6
# ==============
# steemworlds.sk is part of the STEEM.CRAFT addons.
# ==============
Expand Down Expand Up @@ -238,12 +238,25 @@ function saveSteemWorld(player:player):
# > It is estimated that every chunk takes at least 10 seconds to process.
message "%getChatPrefix()% Your world is now being saved. This will take at least %(size of {_chunks::*} * 10) + 70% seconds." to {_player}

#
# > The bossbar is perfect to represent a loading bar, use it here.
set {_bossbar} to createBossBar("&lSaving world...","yellow","10")
set {_progress} to 0.0
{_bossbar}.setProgress({_progress})
{_bossbar}.addPlayer({_player})
{_bossbar}.setVisible(true)

#
# > Since getting the block number of a transaction is currenttly not working for me,
# > the start block number is saved here. This is used to query the history of the account
# > and check only transactions that have been broadcasted after this block number.
set {_startHeadBlockNumber} to getHeadBlockNumber()

#
# > Set the plot size to allow the progress percentage later.
set {_plotsize} to size of {_chunks::*}
set {_pdone} to 100 / {_plotsize}

#
# > All chunks are now looped. A schematic file is created and splitted
# > into usable parts and encoded with base64.
Expand Down Expand Up @@ -309,14 +322,15 @@ function saveSteemWorld(player:player):
#
# > Only the short world name is necessary here.
replace "steemworlds-" with "" in {_shortworld}

#
# > Now, the splitted chunks are being looped through. Every splitted chunk
# > gets a custom json transaction, which is currently set by simply settings
# > a string.
loop {_chunksplit::*}:
add 1 to {_partid}
set {_txcontent} to "{""w"":""%{_shortworld}%"",""x"":%{_chunkx}%,""z"":%{_chunkz}%,""s"":%size of {_chunksplit::*}%,""i"":%{_partid}%,""data"":""%{_chunksplit::%{_partid}%}%""}"

#
# > Now, the custom json is broadcasted. The saving process will repeat the
# > process in case of any error.
Expand All @@ -327,13 +341,21 @@ function saveSteemWorld(player:player):
wait 1 tick
if getSteemResponse({_txuuid}) is "done":
set {_done} to true
message "%getChatPrefix()% %{_loopnumber}% of %size of {_chunks::*}% chunks done." to {_player}

#
# > Tell the player about the current status of the world broadcasting.
{_bossbar}.setTitle("&lBroadcasting chunks...")
set {_progress} to (({_loopnumber} * {_pdone})/100)/2
{_bossbar}.setProgress({_progress})

#
# > If there has been a error, wait 1 second and repeat.
else:
message "%getChatPrefix()% Error. Repeating." to {_player}
wait 1 second

delete {_done}

#
# > If there are still some splits to go, wait 3 seconds after one has been done.
if size of {_chunksplit::*} >= {_partid}:
Expand All @@ -343,17 +365,18 @@ function saveSteemWorld(player:player):
# > Tell the player that the world has been saved and that it needs to wait
# > until the transactions are consensus, since I currently can't get the block
# > number of the transaction directly.
message "%getChatPrefix()% Your world has been saved." to {_player}
message "%getChatPrefix()% Waiting for transactions to get consensus." to {_player}

#
# > A timer will count down until ready.
set {_timer} to 80
loop 80 times:
send action bar "&fWait &6&l%{_timer}%&f seconds" to {_player}
add 0.005 to {_progress}
{_bossbar}.setTitle("&lWait &6&l%{_timer}%&f&l seconds...")
{_bossbar}.setProgress({_progress})
remove 1 from {_timer}
wait 1 second

#
# > Tell the player that the world is now being broadcasted.
{_bossbar}.setTitle("&lBroadcasting world...")

#
# > Go through the last 1000 transactions of the user.
set {_history} to getAccountHistory({_steemname},-1,1000)
Expand Down Expand Up @@ -392,6 +415,7 @@ function saveSteemWorld(player:player):
{_finaljson}.put("app", "{@commentapp}")
{_finaljson}.put("tags", {@commenttags})
{_finaljson}.put("format", "{@commentformat}")

#
# > To shrink down the reference parts, this data is being compressed and encoded into base64.
{_finaljson}.put("world", compressBase64({_arraynode}.toString()))
Expand All @@ -415,10 +439,25 @@ function saveSteemWorld(player:player):

if getSteemResponse({_txuuid}) is "done":
message "%getChatPrefix()% Your world has been saved sucessfully." to {_player}
#
# > Set the loading bossbar to 100% and the title to a success message
# > to tell the player that everything worked.
{_bossbar}.setTitle("&lWorld sucessfully saved.")
{_bossbar}.setProgress(1.0)
else:
message "%getChatPrefix()% A error occured." to {_player}
message "%getChatPrefix()% %getSteemResponse({_txuuid})%" to {_player}

#
# > Remove the bossbar after one second.
wait 1 second

#
# > Remove all players from the bossbar to no longer display it
# > to the players, only deleting it is not enough.
{_bossbar}.removeAll()
delete {_bossbar}

#
# > Function - loadSteemWorld:
# > Loads the speficied world.
Expand Down Expand Up @@ -450,8 +489,15 @@ function loadSteemWorld(steemname:text,worldname:text,player:player):
#
# > Tell the player that the world is now being loaded.
message "%getChatPrefix()% Loading %{_steemname}%'s world..." to {_player}
send action bar "&lLoading world..." to {_player}


#
# > The bossbar is perfect to represent a loading bar, use it here.
set {_bossbar} to createBossBar("&lLoading world...","yellow","10")
set {_progress} to 0.0
{_bossbar}.setProgress({_progress})
{_bossbar}.addPlayer({_player})
{_bossbar}.setVisible(true)

#
# > Loading the content. There is no verification.
set {_c} to getSteemContent({_steemname},{_permlink})
Expand Down Expand Up @@ -506,7 +552,9 @@ function loadSteemWorld(steemname:text,worldname:text,player:player):
if "%{_ops}.get({_tx}).getOp().getRequiredPostingAuths().get(0)%" contains "name=%{_steemname}%":
#
# > Tell the player how the loading process is doing.
send action bar "&lLoading... [%{_partnumber} * {_pdone}%%%]" to {_player}
{_bossbar}.setTitle("&lLoading... [%{_partnumber} * {_pdone}%%%]")
set {_progress} to (({_partnumber} * {_pdone})/100)/1.5
{_bossbar}.setProgress({_progress})
#
# > Get the json Metadata as a string and check if the world matches with the
# > world which should be loaded.
Expand All @@ -522,7 +570,9 @@ function loadSteemWorld(steemname:text,worldname:text,player:player):
set {_plotparts::%{_x}%|%{_z}%|%{_i}%} to {_data}
#
# > Tell the player about the current status.
send action bar "&lDecompressing world..." to {_player}
{_bossbar}.setTitle("&lDecompressing world...")
set {_progress} to 0.5
{_bossbar}.setProgress({_progress})

#
# > Set some variables to calculate the percentage of a loaded world.
Expand Down Expand Up @@ -583,7 +633,9 @@ function loadSteemWorld(steemname:text,worldname:text,player:player):
#
# > Tell the player about the current pasting status.
add 1 to {_partnumber}
send action bar "&lPasting chunks... [%{_pdone} * {_partnumber}%%%]" to {_player}
{_bossbar}.setTitle("&lPasting chunks... [%{_pdone} * {_partnumber}%%%]")
set {_progress} to 0.75+(({_partnumber} * {_pdone})/100)/4
{_bossbar}.setProgress({_progress})

#
# > Paste the schematic with the chunk to the world at the speficied vector.
Expand All @@ -592,7 +644,17 @@ function loadSteemWorld(steemname:text,worldname:text,player:player):
#
# > Tell the player that the loading process has been done successfully.
message "%getChatPrefix()% Successfully loaded %{_steemname}%'s world." to {_player}
send action bar "&lLoad successful." to {_player}
{_bossbar}.setTitle("&lLoad successful.")

#
# > Remove the bossbar after one second.
wait 1 second

#
# > Remove all players from the bossbar to no longer display it
# > to the players, only deleting it is not enough.
{_bossbar}.removeAll()
delete {_bossbar}

#
# > Function - createSteemWorld
Expand Down