Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local effects = {}
- local function getBasePath()
- return "effectAPI/"
- end
- local function readEffectFromFile(effPath)
- if not fs.exists(effPath) then return nil end
- local file = fs.open(effPath,"r")
- if file then
- local eff = {}
- eff.name = file.readLine()
- local c = ""
- local line = file.readLine()
- while line do
- c = c.. " "..line
- line = file.readLine()
- end
- file.close()
- eff.play,e = loadstring(c)
- if e then error("LOAD:"..e) end
- return eff
- else
- return nil
- end
- end
- function reloadEffects()
- local basePath = getBasePath()
- local effectPath = fs.combine(basePath,"effects")
- if fs.exists(effectPath) and fs.isDir(effectPath) then
- local files = fs.list(effectPath)
- for i,v in ipairs(files) do
- local ePath = fs.combine(effectPath,v)
- if not fs.isDir(ePath) then
- local newEff = readEffectFromFile(ePath)
- if newEff then effects[newEff.name] = newEff end
- end
- end
- end
- end
- reloadEffects()
- local function _applyEffect(x,y,screen,effect)
- if not effects[effect] then
- reloadEffects()
- end
- if effects[effect] then
- if effects[effect].play == nil then error("Effect "..effect.. " lacks play function.") end
- effects[effect].play(x,y,screen)
- end
- end
- local function _playEffect(x,y,preScreen,newScreen,effect)
- if preScreen then
- _applyEffect(x,y,preScreen,"clearEffect")
- end
- if newScreen then
- _applyEffect(x,y,newScreen,effect)
- end
- end
- function playEffect(x,y,preScreen,newScreen,effect)
- _playEffect(x,y,nil,preScreen,"clearEffect")
- _playEffect(x,y,nil,newScreen,effect)
- end
Advertisement
Add Comment
Please, Sign In to add comment