Skip to content

Commit

Permalink
Storyboard error no longer crash Live Simulator: 2
Browse files Browse the repository at this point in the history
- It will show error message in bottom screen on error

Added option to enable/disable Storyboard and Video Background in beatmap select menu

New note rendering code
  • Loading branch information
MikuAuahDark committed Jan 4, 2018
1 parent 4d1d7fa commit 0b8323c
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 190 deletions.
14 changes: 6 additions & 8 deletions AquaShine/AquaShine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
-- IN THE SOFTWARE.
--]]---------------------------------------------------------------------------

if jit then
require("table.new")
require("table.clear")
else
if not(pcall(require, "table.new")) then
function table.new()
return {}
end

end

if not(pcall(require, "table.clear")) then
function table.clear(a)
for n, v in pairs(a) do
a[n] = nil
Expand Down Expand Up @@ -354,7 +353,7 @@ end

--! @brief Determines if runs under slow system (mobile devices)
function AquaShine.IsSlowSystem()
return not(jit) or AquaShine.OperatingSystem == "Android" or AquaShine.OperatingSystem == "iOS"
return AquaShine.OperatingSystem == "Android" or AquaShine.OperatingSystem == "iOS"
end

--! @brief Disable screen sleep
Expand Down Expand Up @@ -580,7 +579,7 @@ end
------------------------------
-- Other Internal Functions --
------------------------------
local FileDroppedList = {}
local FileDroppedList = table.new(50, 0)

function AquaShine.StepLoop()
AquaShine.ExitStatus = nil
Expand Down Expand Up @@ -609,7 +608,6 @@ function AquaShine.StepLoop()

love.handlers[name](a, b, c, d, e, f)
end

table.clear(FileDroppedList)

-- Update dt, as we'll be passing it to update
Expand Down
2 changes: 1 addition & 1 deletion beatmap_select_node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function BeatmapSelect.Start(arg)
BeatmapSelect.MainNode:addChild(BackNavigation("Select Beatmap", ":main_menu"))

-- Beatmap info
BeatmapSelect.Info = BeatmapInfo(arg.RandomWasTicked)
BeatmapSelect.Info = BeatmapInfo(arg.RandomWasTicked, NoteLoader)
BeatmapSelect.MainNode:addChild(BeatmapSelect.Info)

-- Each node contain 8 buttons
Expand Down
81 changes: 72 additions & 9 deletions livesim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ local DEPLS = {
LiveShowCleared = Yohane.newFlashFromFilename("flash/live_clear.flsh"),
FullComboAnim = Yohane.newFlashFromFilename("flash/live_fullcombo.flsh"),

StoryboardErrorMsg = "",
StoryboardFunctions = {}, -- Additional function to be added in sandboxed lua storyboard
Routines = {}, -- Table to store all DEPLS effect routines

Expand Down Expand Up @@ -512,6 +513,25 @@ function DEPLS.StoryboardFunctions._SetColorRange(r)
DEPLS.DefaultColorMode = r
end

--! @brief Set post-processing shader
--! @param shader New shader to be used as post-processing
--! @returns Previous shader
function DEPLS.StoryboardFunctions.SetPostProcessingShader(shader)
if type(shader) == nil or (type(shader) == "userdata" and shader:typeOf("Shader")) then
local sh = DEPLS.PostShader
DELS.PostShader = shader
return sh
else
error("bad argument #2 to 'SetPostProcessingShader' (Invalid shader)", 2)
end
end

--! @brief Get the screen dimensions
--! @returns Screen dimensions
function DEPLS.StoryboardFunctions.GetScreenDimensions()
return DEPLS.PostShader:getDimensions()
end

-----------------------------
-- The Live simuator logic --
-----------------------------
Expand Down Expand Up @@ -616,6 +636,9 @@ function DEPLS.Start(argv)
AquaShine.DisableTouchEffect()
EffectPlayer.Clear()

-- Create canvas
DEPLS.Resize()

-- Load tap sound. High priority
local se_volume = AquaShine.LoadConfig("SE_VOLUME", 80) * 0.008
DEPLS.Sound.PerfectTap = AquaShine.GetCachedData("sound/SE_306.ogg", love.audio.newSource, "sound/SE_306.ogg", "static")
Expand Down Expand Up @@ -742,7 +765,15 @@ function DEPLS.Start(argv)
end

-- Load storyboard
DEPLS.StoryboardHandle = noteloader_data:GetStoryboard()
if not(argv.NoStoryboard) then
local s, msg = pcall(noteloader_data.GetStoryboard, noteloader_data)

if s then
DEPLS.StoryboardHandle = msg
else
DEPLS.StoryboardErrorMsg = msg
end
end

-- Load cover art
local noteloader_coverdata = noteloader_data:GetCoverArt()
Expand All @@ -764,8 +795,16 @@ function DEPLS.Start(argv)
-- Initialize storyboard
if DEPLS.StoryboardHandle then
AquaShine.Log("livesim2", "Storyboard init")
DEPLS.StoryboardHandle:Initialize(DEPLS.StoryboardFunctions)
else
local s, msg = pcall(DEPLS.StoryboardHandle.Initialize, DEPLS.StoryboardHandle, DEPLS.StoryboardFunctions)

if not(s) then
DEPLS.StoryboardHandle = nil
DEPLS.StoryboardErrorMsg = msg
AquaShine.Log("livesim2", "Storyboard error: %s", msg)
end
end

if not(DEPLS.StoryboardHandle) and not(argv.NoVideo) then
local video = noteloader_data:GetVideoBackground()

if video then
Expand Down Expand Up @@ -898,6 +937,7 @@ function DEPLS.Start(argv)

-- Load Font
DEPLS.MTLmr3m = AquaShine.LoadFont("MTLmr3m.ttf", 24)
DEPLS.ErrorFont = AquaShine.LoadFont("MTLmr3m.ttf", 14)

-- Set NoteLoader object
DEPLS.NoteLoaderObject = noteloader_data
Expand All @@ -914,6 +954,10 @@ local audiolasttime = 0
function DEPLS.Update(deltaT)
deltaT = deltaT * DEPLS.PlaySpeed

if AquaShine.FFmpegExt then
AquaShine.FFmpegExt.Update(deltaT)
end

if not(DEPLS.Routines.PauseScreen.IsPaused()) then
DEPLS.ElapsedTime = DEPLS.ElapsedTime + deltaT
end
Expand Down Expand Up @@ -989,19 +1033,18 @@ end
function DEPLS.Draw(deltaT)
deltaT = deltaT * DEPLS.PlaySpeed
-- Localize love functions
-- TODO: Remove localize
local graphics = love.graphics
local rectangle = graphics.rectangle
local draw = graphics.draw
local setColor = graphics.setColor
local Images = DEPLS.Images

local Routines = DEPLS.Routines
local ElapsedTime = DEPLS.ElapsedTime
local AllowedDraw = DEPLS.ElapsedTime > 0
local AllowedDraw = DEPLS.ElapsedTime > 0

if AquaShine.FFmpegExt then
AquaShine.FFmpegExt.Update(deltaT)
end
graphics.push("all")
graphics.setCanvas(DEPLS.MainCanvas)

-- If there's storyboard, draw the storyboard instead.
if DEPLS.StoryboardHandle then
Expand Down Expand Up @@ -1031,7 +1074,7 @@ function DEPLS.Draw(deltaT)

for i = 1, 4 do
if BackgroundImage[i][1] then
draw(BackgroundImage[i][1], BackgroundImage[i][2], BackgroundImage[i][3])
graphics.draw(BackgroundImage[i][1], BackgroundImage[i][2], BackgroundImage[i][3])
end
end
end
Expand All @@ -1044,6 +1087,14 @@ function DEPLS.Draw(deltaT)
rectangle("fill", -88, -43, 1136, 726)
setColor(1, 1, 1)
end

if DEPLS.ElapsedTime < 0 then
love.graphics.setFont(DEPLS.ErrorFont)
love.graphics.setColor(0, 0, 0)
love.graphics.print(DEPLS.StoryboardErrorMsg, 1, 601)
love.graphics.setColor(1, 1, 1)
love.graphics.print(DEPLS.StoryboardErrorMsg, 0, 600)
end

if AllowedDraw then
-- Draw combo cheer
Expand Down Expand Up @@ -1105,6 +1156,14 @@ function DEPLS.Draw(deltaT)
if DEPLS.DebugDisplay then
DEPLS.DrawDebugInfo()
end

graphics.pop()
graphics.push()
graphics.origin()
graphics.setShader(DEPLS.PostShader)
graphics.draw(DEPLS.MainCanvas)
graphics.setShader()
graphics.pop()
end

-- LOVE2D mouse/touch pressed
Expand Down Expand Up @@ -1248,6 +1307,10 @@ function DEPLS.KeyReleased(key)
end
end

function DEPLS.Resize(w, h)
DEPLS.MainCanvas = love.graphics.newCanvas()
end

function DEPLS.Exit()
-- Stop audio
if DEPLS.Sound.LiveAudio then
Expand Down
34 changes: 15 additions & 19 deletions note.lua
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,8 @@ function SingleNoteObject.Update(this, deltaT)
end
end

local setBlendMode = love.graphics.setBlendMode
function SingleNoteObject.Draw(this)
local draw = love.graphics.draw
local setColor = love.graphics.setColor

setColor(1, 1, 1, DEPLS.LiveOpacity * this.Opacity)
draw(this.NoteImage, this.FirstCircle[1], this.FirstCircle[2], this.Rotation or 0, this.CircleScale, this.CircleScale, 64, 64)

setColor(1, 1, 1)
return this:NoteFunction()
end

function SingleNoteObject.SetTouchID(this, touchid)
Expand Down Expand Up @@ -544,31 +537,30 @@ end
--! @brief LongNoteObject draw routine
--! @param this NoteObject
function LongNoteObject.Draw(this)
local NoteImage
local setColor = love.graphics.setColor
local draw = love.graphics.draw

-- Draw note trail
setColor(1, 1, this.TouchID and 0.5 or 1, DEPLS.LiveOpacity * (this.TouchID and this.LNTrail or 1))
draw(this.LongNoteMesh)
love.graphics.setColor(1, 1, this.TouchID and 0.5 or 1, DEPLS.LiveOpacity * (this.TouchID and this.LNTrail or 1))
love.graphics.draw(this.LongNoteMesh)

-- Draw note object
--[[
setColor(1, 1, 1, DEPLS.LiveOpacity * this.Opacity)
draw(this.NoteImage, this.FirstCircle[1], this.FirstCircle[2], this.Rotation or 0, this.CircleScale, this.CircleScale, 64, 64)
-- Draw simultaneous note bar if it is
if this.SimulNoteImage then
draw(this.SimulNoteImage, this.FirstCircle[1], this.FirstCircle[2], 0, this.CircleScale, this.CircleScale, 64, 64)
end
]]
this:NoteFunction()

local draw_endcircle = this.EndCircleScale > 0
-- Draw end note trail if it is
if draw_endcircle then
setColor(1, 1, 1, DEPLS.LiveOpacity * this.Opacity2)
draw(this.EndNoteImage, this.SecondCircle[1], this.SecondCircle[2], 0, this.EndCircleScale, this.EndCircleScale, 64, 64)
love.graphics.setColor(1, 1, 1, DEPLS.LiveOpacity * this.Opacity2)
love.graphics.draw(this.EndNoteImage, this.SecondCircle[1], this.SecondCircle[2], 0, this.EndCircleScale, this.EndCircleScale, 64, 64)
end

setColor(1, 1, 1)
love.graphics.setColor(1, 1, 1)
if this.TouchID and not(DEPLS.MinimalEffect) then
love.graphics.push()
love.graphics.translate(this.FirstCircle[1], this.FirstCircle[2])
Expand All @@ -579,7 +571,7 @@ function LongNoteObject.Draw(this)
love.graphics.pop()
end

setColor(1, 1, 1)
love.graphics.setColor(1, 1, 1)
end

--! @brief LongNoteObject on hold note
Expand Down Expand Up @@ -769,7 +761,8 @@ local function initnote_pos(a)
for i = 1, #Note[a] do
local obj = Note[a][i]

obj.NoteImage = DEPLS.NoteImageLoader.LoadNoteImage(obj.Attribute, a, obj.TokenNote, obj.SimulNote, obj.StarNote, obj.SlideNote, obj.Rotation)
--obj.NoteImage = DEPLS.NoteImageLoader.LoadNoteImage(obj.Attribute, a, obj.TokenNote, obj.SimulNote, obj.StarNote, obj.SlideNote, obj.Rotation)
obj.NoteFunction = DEPLS.NoteImageLoader.GetNoteImageFunction()
end
end

Expand Down Expand Up @@ -932,6 +925,7 @@ end
--! Function to draw the note
function Note.Draw()
local ElapsedTime = DEPLS.ElapsedTime
love.graphics.push("all")

for i = 1, 9 do
for j = 1, #Note[i] do
Expand All @@ -945,6 +939,8 @@ function Note.Draw()
end
end
end

love.graphics.pop()
end

--! Function to draw the timing icon
Expand Down
Loading

0 comments on commit 0b8323c

Please sign in to comment.