From 681802d030e91e9167f58be0ed850d13072092d3 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Thu, 10 Dec 2020 15:29:48 +0800 Subject: [PATCH] =?UTF-8?q?SKIN=E6=A8=A1=E5=9D=97=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=EF=BC=8C=E5=85=B6=E4=BB=96=E5=A4=9A=E5=AA=92=E4=BD=93=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/bgm.lua | 1 + Zframework/image.lua | 5 +- main.lua | 27 ++++- parts/scenes/load.lua | 2 +- parts/skin.lua | 229 ++++++++++++++++++++---------------------- 5 files changed, 140 insertions(+), 124 deletions(-) diff --git a/Zframework/bgm.lua b/Zframework/bgm.lua index 6288d7a5..cd2d2c89 100644 --- a/Zframework/bgm.lua +++ b/Zframework/bgm.lua @@ -89,6 +89,7 @@ function BGM.init(list) BGM.nowPlay,BGM.playing=nil end end + BGM.loadOne=coroutine.wrap(load) function BGM.loadAll()load(true)end end diff --git a/Zframework/image.lua b/Zframework/image.lua index c2f0c22f..ff927698 100644 --- a/Zframework/image.lua +++ b/Zframework/image.lua @@ -1,4 +1,6 @@ -local IMG={} +local IMG={ + getCount=function()return 0 end, +} function IMG.init(list) IMG.init=nil local count=0 @@ -16,6 +18,7 @@ function IMG.init(list) end IMG.loadOne=nil end + IMG.loadOne=coroutine.wrap(load) function IMG.loadAll()load(true)end end diff --git a/main.lua b/main.lua index 1031f06f..9b74350d 100644 --- a/main.lua +++ b/main.lua @@ -51,7 +51,7 @@ AIFUNC= require"parts/ai" MODES= require"parts/modes" TICK= require"parts/tick" ---Initialize image lib +--Initialize image libs IMG.init{ batteryImage="/mess/power.png", title="mess/title.png", @@ -75,7 +75,30 @@ IMG.init{ electric="mess/electric.png", hbm="mess/hbm.png", } - +SKIN.init{ + "normal(mrz)", + "smooth(mrz)", + "contrast(mrz)", + "glow(mrz)", + "plastic(mrz)", + "jelly(miya)", + "steel(kulumi)", + "pure(mrz)", + "ball(shaw)", + "paper(mrz)", + "gem(notypey)", + "classic(_)", + "brick(notypey)", + "brick_light(notypey)", + "cartoon_cup(earety)", + "crack(earety)", + "retro(notypey)", + "retro_grey(notypey)", + "text_bone(mrz)", + "colored_bone(mrz)", + "white_bone(mrz)", + "WTF", +} --Initialize sound libs SFX.init{ --Stereo sfxs(cannot set position) diff --git a/parts/scenes/load.lua b/parts/scenes/load.lua index da9716c3..3f12be52 100644 --- a/parts/scenes/load.lua +++ b/parts/scenes/load.lua @@ -128,7 +128,7 @@ function scene.update() elseif S.phase==5 then getFont(15+5*S.cur) elseif S.phase==6 then - SKIN.loadOne(S.cur) + SKIN.loadOne() elseif S.phase==7 then local m=MODES[S.cur]--Mode template local M=require("parts/modes/"..m.name)--Mode file diff --git a/parts/skin.lua b/parts/skin.lua index 9abdb55e..e7316165 100644 --- a/parts/skin.lua +++ b/parts/skin.lua @@ -1,127 +1,116 @@ -local gc=love.graphics -local int=math.floor -local function C(x,y) - local _=gc.newCanvas(x,y) - gc.setCanvas(_) - return _ -end -local list={ - "normal(mrz)", - "smooth(mrz)", - "contrast(mrz)", - "glow(mrz)", - "plastic(mrz)", - "jelly(miya)", - "steel(kulumi)", - "pure(mrz)", - "ball(shaw)", - "paper(mrz)", - "gem(notypey)", - "classic(_)", - "brick(notypey)", - "brick_light(notypey)", - "cartoon_cup(earety)", - "crack(earety)", - "retro(notypey)", - "retro_grey(notypey)", - "text_bone(mrz)", - "colored_bone(mrz)", - "white_bone(mrz)", - "WTF", +local SKIN={ + getCount=function()return 0 end, + prevSet=NULL, + nextSet=NULL, + prev=NULL, + next=NULL, + rotate=NULL, + change=NULL, } -local count=#list -local SKIN={} -SKIN.lib={} -SKIN.libMini={} -SKIN.libColor={ - COLOR.red, - COLOR.fire, - COLOR.orange, - COLOR.yellow, - COLOR.lame, - COLOR.grass, - COLOR.green, - COLOR.water, - COLOR.cyan, - COLOR.sky, - COLOR.sea, - COLOR.blue, - COLOR.purple, - COLOR.grape, - COLOR.magenta, - COLOR.pink, - COLOR.dGrey, - COLOR.black, - COLOR.lYellow, - COLOR.grey, - COLOR.lGrey, - COLOR.dPurple, - COLOR.dRed, - COLOR.dGreen, -} -function SKIN.getCount() - return count -end -function SKIN.loadOne(_) - gc.push() - gc.origin() - gc.setDefaultFilter("nearest","nearest") - gc.setColor(1,1,1) - SKIN.lib[_],SKIN.libMini[_]={},{} - local N="media/image/skin/"..list[_]..".png" - local I - if love.filesystem.getInfo(N)then - I=gc.newImage(N) - else - I=gc.newImage("media/image/skin/"..list[1]..".png") - LOG.print("No skin file: "..list[_],"warn") +function SKIN.init(list) + local gc=love.graphics + local int=math.floor + local function C(x,y) + local _=gc.newCanvas(x,y) + gc.setCanvas(_) + return _ end - for i=0,2 do - for j=1,8 do - SKIN.lib[_][8*i+j]=C(30,30) - gc.draw(I,30-30*j,-30*i) + local count=#list function SKIN.getCount()return count end + SKIN.lib={} + SKIN.libMini={} + SKIN.libColor={ + COLOR.red, + COLOR.fire, + COLOR.orange, + COLOR.yellow, + COLOR.lame, + COLOR.grass, + COLOR.green, + COLOR.water, + COLOR.cyan, + COLOR.sky, + COLOR.sea, + COLOR.blue, + COLOR.purple, + COLOR.grape, + COLOR.magenta, + COLOR.pink, + COLOR.dGrey, + COLOR.black, + COLOR.lYellow, + COLOR.grey, + COLOR.lGrey, + COLOR.dPurple, + COLOR.dRed, + COLOR.dGreen, + } - SKIN.libMini[_][8*i+j]=C(6,6) - gc.draw(I,6-6*j,-6*i,nil,.2) + local function load(skip) + for i=1,count do + gc.push() + gc.origin() + gc.setDefaultFilter("nearest","nearest") + gc.setColor(1,1,1) + SKIN.lib[i],SKIN.libMini[i]={},{} + local N="media/image/skin/"..list[i]..".png" + local I + if love.filesystem.getInfo(N)then + I=gc.newImage(N) + else + I=gc.newImage("media/image/skin/"..list[1]..".png") + LOG.print("No skin file: "..list[i],"warn") + end + for y=0,2 do + for x=1,8 do + SKIN.lib[i][8*y+x]=C(30,30) + gc.draw(I,30-30*x,-30*y) + + SKIN.libMini[i][8*y+x]=C(6,6) + gc.draw(I,6-6*x,-6*y,nil,.2) + end + end + I:release() + gc.setCanvas() + gc.pop() + if not skip and i~=count then + coroutine.yield() + end + end + SKIN.loadOne=nil + + function SKIN.prevSet()--Prev skin_set + local _=(SETTING.skinSet-2)%count+1 + SETTING.skinSet=_ + SKIN.change(_) + _=list[_] + TEXT.show(_,1100,100,int(300/#_)+5,"fly") + end + function SKIN.nextSet()--Next skin_set + local _=SETTING.skinSet%count+1 + SETTING.skinSet=_ + SKIN.change(_) + _=list[_] + TEXT.show(_,1100,100,int(300/#_)+5,"fly") + end + function SKIN.prev(i)--Prev skin for [i] + local _=SETTING.skin + _[i]=(_[i]-2)%16+1 + end + function SKIN.next(i)--Next skin for [i] + local _=SETTING.skin + _[i]=_[i]%16+1 + end + function SKIN.rotate(i)--Change direction of [i] + SETTING.face[i]=(SETTING.face[i]+1)%4 + SFX.play("rotate") + end + function SKIN.change(i)--Change to skin_set[i] + SKIN.curText=SKIN.lib[i] + SKIN.curTextMini=SKIN.libMini[i] end end - I:release() - gc.setCanvas() - gc.pop() -end -function SKIN.loadAll() - for i=1,count do - SKIN.loadOne(i) - end -end -function SKIN.prevSet()--Prev skin_set - local _=(SETTING.skinSet-2)%count+1 - SETTING.skinSet=_ - SKIN.change(_) - _=list[_] - TEXT.show(_,1100,100,int(300/#_)+5,"fly") -end -function SKIN.nextSet()--Next skin_set - local _=SETTING.skinSet%count+1 - SETTING.skinSet=_ - SKIN.change(_) - _=list[_] - TEXT.show(_,1100,100,int(300/#_)+5,"fly") -end -function SKIN.prev(i)--Prev skin for [i] - local _=SETTING.skin - _[i]=(_[i]-2)%16+1 -end -function SKIN.next(i)--Next skin for [i] - local _=SETTING.skin - _[i]=_[i]%16+1 -end -function SKIN.rotate(i)--Change direction of [i] - SETTING.face[i]=(SETTING.face[i]+1)%4 - SFX.play("rotate") -end -function SKIN.change(i)--Change to skin_set[i] - SKIN.curText=SKIN.lib[i] - SKIN.curTextMini=SKIN.libMini[i] + + SKIN.loadOne=coroutine.wrap(load) + function SKIN.loadAll()load(true)end end return SKIN \ No newline at end of file