Skip to content

Commit 88a40c6

Browse files
authored
Merge pull request #194 from goplus/main
Release v1.0.0-rc5
2 parents 648ba1f + 4d26cb6 commit 88a40c6

25 files changed

Lines changed: 362 additions & 93 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ _test
1313
haiyang/
1414
feijidazhan/
1515
.idea
16-
*.code-workspace
16+
*.code-workspace
17+
*.wasm
1718

1819
# Binaries for programs and plugins
1920
*.exe

dir.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

dir_js.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

game.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ func (p *Game) initGame() {
123123

124124
// Gopt_Game_Main is required by Go+ compiler as the entry of a .gmx project.
125125
func Gopt_Game_Main(game Gamer) {
126-
setupWorkDir()
127126
game.initGame()
128127
game.(interface{ MainEntry() }).MainEntry()
129128
}
@@ -1294,11 +1293,13 @@ type EffectKind int
12941293
const (
12951294
ColorEffect EffectKind = iota
12961295
BrightnessEffect
1296+
GhostEffect
12971297
)
12981298

12991299
var greffNames = []string{
13001300
ColorEffect: "Color",
13011301
BrightnessEffect: "Brightness",
1302+
GhostEffect: "Ghost",
13021303
}
13031304

13041305
func (kind EffectKind) String() string {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/ajstarks/svgo v0.0.0-20210927141636-6d70534b1098
77
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
88
github.com/goplus/canvas v0.1.0
9-
github.com/goplus/gop v1.0.37
9+
github.com/goplus/gop v1.1.0-alpha2
1010
github.com/hajimehoshi/ebiten/v2 v2.2.0
1111
github.com/pkg/errors v0.9.1
1212
github.com/qiniu/audio v0.2.1

go.sum

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
1212
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
1313
github.com/goplus/canvas v0.1.0 h1:Vx3f2+U8UANvWf5/01YsQYKNbZDm1GZCjhlEBFrQkeU=
1414
github.com/goplus/canvas v0.1.0/go.mod h1:Rhcvo5qkpD9WuXFnvnXtrBSY97l6h7sXQuofrmiLNdM=
15-
github.com/goplus/gop v1.0.37 h1:U7/Asf3IyJBC38DXii56JF5hw94TayUs5Vg6XT5Wi14=
16-
github.com/goplus/gop v1.0.37/go.mod h1:JMjZXjcfATZdT+1SIU4bXpaXJIvs6xTNVzjI8+XQhRM=
17-
github.com/goplus/gox v1.8.7/go.mod h1:XWqV75HImeysI8+Q9gAdYyvwlP8jds24xsgYRwTO3JI=
15+
github.com/goplus/gop v1.1.0-alpha2 h1:s3wMFJpprmFBmVRqUIoggQ2wJ3Kb3gX+7J0f8f2Oh8Q=
16+
github.com/goplus/gop v1.1.0-alpha2/go.mod h1:FTu64eb9ZYCwnTfSze6asR8kbxXPs6mbI+kRmUikKf0=
17+
github.com/goplus/gox v1.9.4/go.mod h1:PznHkzl2HARBf7+s2reqcwKm1Z1a6Wae6EntQEh0iJI=
1818
github.com/hajimehoshi/bitmapfont/v2 v2.1.3/go.mod h1:2BnYrkTQGThpr/CY6LorYtt/zEPNzvE/ND69CRTaHMs=
1919
github.com/hajimehoshi/ebiten/v2 v2.2.0 h1:2mP9HrLLqiH9X3MajElYZEjVZU/CGh22iFkjatxhT4w=
2020
github.com/hajimehoshi/ebiten/v2 v2.2.0/go.mod h1:olKl/qqhMBBAm2oI7Zy292nCtE+nitlmYKNF3UpbFn0=

internal/audiorecord/audiorecord_js.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"syscall/js"
66
)
77

8-
const scriptCode = `!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).GopAudioRecorder={})}(this,function(e){var t=new(window.AudioContext||window.webkitAudioContext)({latencyHint:"interactive"}),n=t.createAnalyser();n.fftSize=2048;var o=t.createGain();o.gain.value=0,n.connect(o),o.connect(t.destination);var i,r,a,c=new Uint8Array(n.frequencyBinCount);function s(){i&&(i.getTracks().forEach(function(e){return e.stop()}),i=void 0),r&&(r.disconnect(),r=void 0),clearInterval(a),t.suspend()}e.start=function(e){try{return s(),Promise.resolve(navigator.mediaDevices.getUserMedia({audio:!0})).then(function(o){(r=t.createMediaStreamSource(i=o)).connect(n),t.resume(),a=setInterval(function(){var o,i;n.getByteFrequencyData(c),e((o=0,i=c.length,c.forEach(function(e,n){var r=n*(t.sampleRate||44100)/i;if(r>22050)i-=1;else{var a,c,s=187374169.94399998*(c=(a=r)*a)*c/((c+424.36)*Math.sqrt((c+11599.29)*(c+544496.41))*(c+14884e4))*e/255;s<=0?i-=1:o+=s*s}}),0===i?0:Math.sqrt(o/i)))},100)})}catch(e){return Promise.reject(e)}},e.stop=function(){s()}});`
8+
const scriptCode = `!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).GopAudioRecorder={})}(this,function(t){var e,i=/*#__PURE__*/function(){function t(t){this.audioContext=t,this.connectingToMic=!1,this.mic=null}var e=t.prototype;return e.getLoudness=function(){var t=this;if(this.mic||this.connectingToMic||(this.connectingToMic=!0,navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){t.audioStream=e,t.mic=t.audioContext.createMediaStreamSource(e),t.analyser=t.audioContext.createAnalyser(),t.mic.connect(t.analyser),t.micDataArray=new Float32Array(t.analyser.fftSize)}).catch(function(t){console.warn(t)})),this.mic&&this.audioStream&&this.audioStream.active){this.analyser.getFloatTimeDomainData(this.micDataArray);for(var e=0,i=0;i<this.micDataArray.length;i++)e+=Math.pow(this.micDataArray[i],2);var a=Math.sqrt(e/this.micDataArray.length);return this._lastValue&&(a=Math.max(a,.6*this._lastValue)),this._lastValue=a,a*=1.63,a=Math.sqrt(a),a=Math.round(100*a),(a=Math.min(a,100))/100}return 0},e.release=function(){this.connectingToMic=!1,this.mic&&(this.mic.disconnect(),this.mic=null),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=void 0),this.analyser&&(this.analyser.disconnect(),this.analyser=void 0)},t}(),a=new(window.AudioContext||window.webkitAudioContext)({latencyHint:"interactive"}),n=new i(a);t.start=function(t){try{return clearInterval(e),a.resume(),e=setInterval(function(){t(n.getLoudness())},100),Promise.resolve()}catch(t){return Promise.reject(t)}},t.stop=function(){clearInterval(e),n.release()}});`
99

1010
var scriptInited bool
1111

internal/effect/shader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var ShaderFrag = []byte(`package main
55
var (
66
Color float
77
Brightness float
8+
Ghost float
89
)
910
1011
func convertRGB2HSV(rgb vec3) vec3 {
@@ -109,6 +110,12 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
109110
txtcolor = vec4(rgb,txtcolor.a)
110111
}
111112
113+
//0 ~ 100
114+
if Ghost > 0.0{
115+
//1 - (Math.max(0, Math.min(x, 100)) / 100)
116+
txtcolor *= 1.0 - (max(0.0, min(Ghost, 100.0)) / 100.0)
117+
}
118+
112119
return txtcolor
113120
}
114121
`)

quote.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package spx
2+
3+
import (
4+
"fmt"
5+
"math"
6+
7+
"github.com/goplus/spx/internal/gdi"
8+
xfont "github.com/goplus/spx/internal/gdi/font"
9+
"github.com/hajimehoshi/ebiten/v2"
10+
"golang.org/x/image/colornames"
11+
"golang.org/x/image/font"
12+
)
13+
14+
const (
15+
quotePadding = 5.0
16+
quoteLineWidth = 8.0
17+
quoteHeadLen = 16.0
18+
quoteTextPadding = 3.0
19+
quoteBorderRadis = 10.0
20+
)
21+
22+
var (
23+
quoteMsgFont gdi.Font
24+
quoteDesFont gdi.Font
25+
)
26+
27+
func init() {
28+
const dpi = 72
29+
quoteMsgFont = xfont.NewDefault(&xfont.Options{
30+
Size: 35,
31+
DPI: dpi,
32+
Hinting: font.HintingFull,
33+
})
34+
quoteDesFont = xfont.NewDefault(&xfont.Options{
35+
Size: 18,
36+
DPI: dpi,
37+
Hinting: font.HintingFull,
38+
})
39+
}
40+
41+
type quoter struct {
42+
sprite *Sprite
43+
message string
44+
description string
45+
46+
cachedImg *ebiten.Image
47+
}
48+
49+
func (p *Sprite) quote_(message, description string) {
50+
old := p.quoteObj
51+
if old == nil {
52+
p.quoteObj = &quoter{sprite: p, message: message, description: description}
53+
p.g.addShape(p.quoteObj)
54+
} else {
55+
old.message, old.description = message, description
56+
old.cachedImg = nil
57+
p.g.activateShape(old)
58+
}
59+
}
60+
61+
func (p *Sprite) waitStopQuote(secs float64) {
62+
p.g.Wait(secs)
63+
p.doStopQuote()
64+
}
65+
66+
func (p *Sprite) doStopQuote() {
67+
if p.quoteObj != nil {
68+
p.g.removeShape(p.quoteObj)
69+
p.quoteObj = nil
70+
}
71+
}
72+
73+
func (p *quoter) draw(dc drawContext) {
74+
img := p.getImage()
75+
if img == nil {
76+
return
77+
}
78+
imgW, imgH := img.Size()
79+
w, h := dc.Size()
80+
op := new(ebiten.DrawImageOptions)
81+
x := p.sprite.x + float64(w)/2 - float64(imgW)/2
82+
y := -p.sprite.y - quotePadding - float64(imgH) + float64(h)/2 + float64(imgH)/2
83+
op.GeoM.Translate(x, y)
84+
dc.DrawImage(img, op)
85+
}
86+
87+
func (p *quoter) getImage() *ebiten.Image {
88+
if p.cachedImg != nil {
89+
return p.cachedImg
90+
}
91+
bound := p.sprite.getRotatedRect()
92+
w := math.Max(bound.Size.Height, bound.Size.Width)
93+
w += quotePadding + quoteLineWidth
94+
h := w * 1.15
95+
quoteHeight := h
96+
msgRender := gdi.NewTextRender(quoteMsgFont, 135, 2)
97+
msgRender.AddText(p.message)
98+
msgW, msgH := msgRender.Size()
99+
h += float64(msgH / 2)
100+
desRender := gdi.NewTextRender(quoteDesFont, 135, 2)
101+
var desW, desH int
102+
if p.description != "" {
103+
desRender.AddText((p.description))
104+
desW, desH = desRender.Size()
105+
h += float64(desH + quoteTextPadding)
106+
}
107+
108+
svg := gdi.NewSVG(int(w), int(h))
109+
mainH := int(h) - msgH/2
110+
dy := 0.0
111+
if p.description != "" {
112+
dy = float64(desH) + quoteTextPadding
113+
mainH -= int(dy)
114+
}
115+
half := fmt.Sprintf("m 0 %f q 0 %f %f %f h %f q %f %f 0 %f h -%f v %f h %f q %f %f 0 %f h -%f q %f 0 %f %f z",
116+
dy+quoteBorderRadis,
117+
118+
-quoteBorderRadis,
119+
quoteBorderRadis,
120+
-quoteBorderRadis,
121+
122+
quoteHeadLen,
123+
124+
quoteLineWidth/2,
125+
quoteLineWidth/2,
126+
quoteLineWidth,
127+
128+
quoteHeadLen+3,
129+
130+
float64(mainH)-2*quoteLineWidth,
131+
132+
quoteHeadLen+3,
133+
134+
quoteLineWidth/2,
135+
quoteLineWidth/2,
136+
quoteLineWidth,
137+
138+
quoteHeadLen,
139+
140+
-quoteBorderRadis,
141+
-quoteBorderRadis,
142+
-quoteBorderRadis,
143+
)
144+
svg.Def()
145+
svg.Path(half, `id="quote"`)
146+
svg.DefEnd()
147+
// "["
148+
style := "fill:rgb(144,169,55);stroke:black;"
149+
svg.Use(0, 0, "#quote", style)
150+
// "]"
151+
svg.Gtransform(fmt.Sprintf("rotate(%.1f %f %f)", 180.0, w/2, quoteHeight/2+dy))
152+
svg.Use(0, 0, "#quote", style)
153+
svg.Gend()
154+
svg.End()
155+
156+
img, err := svg.ToImage()
157+
if err != nil {
158+
panic(err)
159+
}
160+
p.cachedImg = ebiten.NewImageFromImage(img)
161+
msgRender.Draw(p.cachedImg, (int(w)-msgW)/2, int(h)-msgH, colornames.White, 0)
162+
if p.description != "" {
163+
desRender.Draw(p.cachedImg, (int(w)-desW)/2, 0, colornames.White, 0)
164+
}
165+
return p.cachedImg
166+
}
167+
168+
func (p *quoter) hit(hc hitContext) (hr hitResult, ok bool) {
169+
return
170+
}

say.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package spx
22

33
import (
4+
"fmt"
45
"image/color"
56
"strconv"
67
"strings"
@@ -71,7 +72,6 @@ func (p *sayOrThinker) draw(dc drawContext) {
7172
w, h := render.Size()
7273
x, y := topx+2, topy-h-(trackCy+24)
7374

74-
7575
pad := 9
7676
w += (pad << 1)
7777
h += (pad << 1)
@@ -163,3 +163,38 @@ func (p *sayOrThinker) hit(hc hitContext) (hr hitResult, ok bool) {
163163
}
164164

165165
// -------------------------------------------------------------------------------------
166+
167+
func (p *Sprite) sayOrThink(msgv interface{}, style int) {
168+
msg, ok := msgv.(string)
169+
if !ok {
170+
msg = fmt.Sprint(msgv)
171+
}
172+
173+
if msg == "" {
174+
p.doStopSay()
175+
return
176+
}
177+
178+
old := p.sayObj
179+
if old == nil {
180+
p.sayObj = &sayOrThinker{sp: p, msg: msg, style: style}
181+
p.g.addShape(p.sayObj)
182+
} else {
183+
old.msg, old.style = msg, style
184+
p.g.activateShape(old)
185+
}
186+
}
187+
188+
func (p *Sprite) waitStopSay(secs float64) {
189+
p.g.Wait(secs)
190+
p.doStopSay()
191+
}
192+
193+
func (p *Sprite) doStopSay() {
194+
if p.sayObj != nil {
195+
p.g.removeShape(p.sayObj)
196+
p.sayObj = nil
197+
}
198+
}
199+
200+
// -------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)