all: replace interface{} with any (#2430)

Closes #2429
This commit is contained in:
Artem Yadelskyi 2022-11-03 08:33:09 +02:00 committed by GitHub
parent abbd4bddf1
commit 10415d417a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 51 additions and 51 deletions

View File

@ -43,7 +43,7 @@ type imageImportCheckError struct {
Import string
}
func runImageImportCheck(pass *analysis.Pass) (interface{}, error) {
func runImageImportCheck(pass *analysis.Pass) (any, error) {
pkgPath := pass.Pkg.Path()
if strings.HasPrefix(pkgPath, "github.com/hajimehoshi/ebiten/v2/examples/") {
return nil, nil

View File

@ -133,7 +133,7 @@ type Stroke struct {
// draggingObject represents a object (sprite in this case)
// that is being dragged.
draggingObject interface{}
draggingObject any
}
func NewStroke(source StrokeSource) *Stroke {
@ -174,11 +174,11 @@ func (s *Stroke) PositionDiff() (int, int) {
return dx, dy
}
func (s *Stroke) DraggingObject() interface{} {
func (s *Stroke) DraggingObject() any {
return s.draggingObject
}
func (s *Stroke) SetDraggingObject(object interface{}) {
func (s *Stroke) SetDraggingObject(object any) {
s.draggingObject = object
}

View File

@ -295,7 +295,7 @@ func outputKeyRectsGo(k map[ebiten.Key]image.Rectangle) error {
if err != nil {
return err
}
return tmpl.Execute(f, map[string]interface{}{
return tmpl.Execute(f, map[string]any{
"License": license,
"KeyRectsMap": k,
})

View File

@ -147,7 +147,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
cx, cy := ebiten.CursorPosition()
op := &ebiten.DrawRectShaderOptions{}
op.Uniforms = map[string]interface{}{
op.Uniforms = map[string]any{
"Time": float32(g.time) / 60,
"Cursor": []float32{float32(cx), float32(cy)},
"ScreenSize": []float32{float32(w), float32(h)},

View File

@ -325,7 +325,7 @@ var eventTmpl = template.Must(template.New("event.go").Parse(`{{.License}}
package {{.Package}}
type Event interface{}
type Event any
{{range .Events}}// {{.Comment}}
type {{.Name}} struct {

View File

@ -243,7 +243,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) {
var body [16]float32
var translation [4]float32
colorm.Elements(body[:], translation[:])
uniforms = shader.convertUniforms(map[string]interface{}{
uniforms = shader.convertUniforms(map[string]any{
builtinshader.UniformColorMBody: body[:],
builtinshader.UniformColorMTranslation: translation[:],
})
@ -474,7 +474,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
var body [16]float32
var translation [4]float32
colorm.Elements(body[:], translation[:])
uniforms = shader.convertUniforms(map[string]interface{}{
uniforms = shader.convertUniforms(map[string]any{
builtinshader.UniformColorMBody: body[:],
builtinshader.UniformColorMTranslation: translation[:],
})
@ -502,7 +502,7 @@ type DrawTrianglesShaderOptions struct {
// If the uniform variable type is an array, a vector or a matrix,
// you have to specify linearly flattened values as a slice.
// For example, if the uniform variable type is [4]vec4, the number of the slice values will be 16.
Uniforms map[string]interface{}
Uniforms map[string]any
// Images is a set of the source images.
// All the images' sizes must be the same.
@ -662,7 +662,7 @@ type DrawRectShaderOptions struct {
// If the uniform variable type is an array, a vector or a matrix,
// you have to specify linearly flattened values as a slice.
// For example, if the uniform variable type is [4]vec4, the number of the slice values will be 16.
Uniforms map[string]interface{}
Uniforms map[string]any
// Images is a set of the source images.
// All the images' sizes must be the same.

View File

@ -22,6 +22,6 @@ import (
const IsDebug = true
func Logf(format string, args ...interface{}) {
func Logf(format string, args ...any) {
fmt.Printf(format, args...)
}

View File

@ -18,5 +18,5 @@ package debug
const IsDebug = false
func Logf(format string, args ...interface{}) {
func Logf(format string, args ...any) {
}

View File

@ -173,7 +173,7 @@ func (g *gamepads) setNativeWindow(nativeWindow uintptr) {
g.m.Lock()
defer g.m.Unlock()
var n interface{} = g.native
var n any = g.native
if n, ok := n.(interface{ setNativeWindow(uintptr) }); ok {
n.setNativeWindow(nativeWindow)
}

View File

@ -1268,7 +1268,7 @@ func _GetMessageTime() int32 {
return int32(r)
}
func _GetModuleHandleExW(dwFlags uint32, lpModuleName interface{}) (_HMODULE, error) {
func _GetModuleHandleExW(dwFlags uint32, lpModuleName any) (_HMODULE, error) {
var ptr unsafe.Pointer
switch moduleName := lpModuleName.(type) {
case string:

View File

@ -31,8 +31,8 @@ func download(buf *bytes.Buffer, mime string, path string) {
a := global.Get("document").Call("createElement", "a")
blob := global.Get("Blob").New(
[]interface{}{jsData},
map[string]interface{}{"type": mime},
[]any{jsData},
map[string]any{"type": mime},
)
a.Set("href", global.Get("URL").Call("createObjectURL", blob))
a.Set("download", path)

View File

@ -86,7 +86,7 @@ func Example_listDevices() {
// printJSON prints label, then v as JSON encoded with indent to stdout. It panics on any error.
// It's meant to be used by examples to print the output.
func printJSON(label string, v interface{}) {
func printJSON(label string, v any) {
fmt.Print(label)
w := json.NewEncoder(os.Stdout)
w.SetIndent("", "\t")

View File

@ -17,7 +17,7 @@ import (
// var data []uint8
// ...
// gl.TexImage2D(glconst.TEXTURE_2D, ..., glconst.UNSIGNED_BYTE, gl.Ptr(&data[0]))
func Ptr(data interface{}) unsafe.Pointer {
func Ptr(data any) unsafe.Pointer {
if data == nil {
return unsafe.Pointer(nil)
}

View File

@ -48,7 +48,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
op := &ebiten.DrawRectShaderOptions{}
op.Blend = ebiten.BlendCopy
op.Uniforms = map[string]interface{}{
op.Uniforms = map[string]any{
"Color": []float32{1, 1, 1, 1},
}
g.dst.DrawRectShader(w, h, s, op)
@ -78,7 +78,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
op := &ebiten.DrawRectShaderOptions{}
op.Blend = ebiten.BlendCopy
op.Uniforms = map[string]interface{}{
op.Uniforms = map[string]any{
"Dummy": float32(0),
"R": float32(0.5),
"G": float32(1),

View File

@ -44,7 +44,7 @@ func (s *Shader) MarkDisposed() {
s.shader = nil
}
func (s *Shader) ConvertUniforms(uniforms map[string]interface{}) [][]float32 {
func (s *Shader) ConvertUniforms(uniforms map[string]any) [][]float32 {
nameToF32s := map[string][]float32{}
for name, v := range uniforms {
switch v := v.(type) {

View File

@ -359,7 +359,7 @@ func (u *userInterfaceImpl) loop(game Game) <-chan error {
}
// TODO: Should cf be released after the game ends?
cf = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
cf = js.FuncOf(func(this js.Value, args []js.Value) any {
// f can be blocked but callbacks must not be blocked. Create a goroutine (#1161).
go f()
return nil
@ -419,7 +419,7 @@ func init() {
if !document.Get("body").Truthy() {
ch := make(chan struct{})
window.Call("addEventListener", "load", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
window.Call("addEventListener", "load", js.FuncOf(func(this js.Value, args []js.Value) any {
close(ch)
return nil
}))
@ -465,7 +465,7 @@ func init() {
setCanvasEventHandlers(canvas)
// Pointer Lock
document.Call("addEventListener", "pointerlockchange", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
document.Call("addEventListener", "pointerlockchange", js.FuncOf(func(this js.Value, args []js.Value) any {
if document.Get("pointerLockElement").Truthy() {
return nil
}
@ -478,22 +478,22 @@ func init() {
theUI.input.recoverCursorPosition()
return nil
}))
document.Call("addEventListener", "pointerlockerror", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
document.Call("addEventListener", "pointerlockerror", js.FuncOf(func(this js.Value, args []js.Value) any {
js.Global().Get("console").Call("error", "pointerlockerror event is fired. 'sandbox=\"allow-pointer-lock\"' might be required at an iframe. This function on browsers must be called as a result of a gestural interaction or orientation change.")
return nil
}))
document.Call("addEventListener", "fullscreenerror", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
document.Call("addEventListener", "fullscreenerror", js.FuncOf(func(this js.Value, args []js.Value) any {
js.Global().Get("console").Call("error", "fullscreenerror event is fired. 'allow=\"fullscreen\"' or 'allowfullscreen' might be required at an iframe. This function on browsers must be called as a result of a gestural interaction or orientation change.")
return nil
}))
document.Call("addEventListener", "webkitfullscreenerror", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
document.Call("addEventListener", "webkitfullscreenerror", js.FuncOf(func(this js.Value, args []js.Value) any {
js.Global().Get("console").Call("error", "webkitfullscreenerror event is fired. 'allow=\"fullscreen\"' or 'allowfullscreen' might be required at an iframe. This function on browsers must be called as a result of a gestural interaction or orientation change.")
return nil
}))
}
func setWindowEventHandlers(v js.Value) {
v.Call("addEventListener", "resize", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "resize", js.FuncOf(func(this js.Value, args []js.Value) any {
theUI.updateScreenSize()
// updateImpl can block. Use goroutine.
@ -510,7 +510,7 @@ func setWindowEventHandlers(v js.Value) {
func setCanvasEventHandlers(v js.Value) {
// Keyboard
v.Call("addEventListener", "keydown", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "keydown", js.FuncOf(func(this js.Value, args []js.Value) any {
// Focus the canvas explicitly to activate tha game (#961).
v.Call("focus")
@ -522,7 +522,7 @@ func setCanvasEventHandlers(v js.Value) {
}
return nil
}))
v.Call("addEventListener", "keyup", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "keyup", js.FuncOf(func(this js.Value, args []js.Value) any {
e := args[0]
e.Call("preventDefault")
if err := theUI.input.updateFromEvent(e); err != nil && theUI.err != nil {
@ -533,7 +533,7 @@ func setCanvasEventHandlers(v js.Value) {
}))
// Mouse
v.Call("addEventListener", "mousedown", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "mousedown", js.FuncOf(func(this js.Value, args []js.Value) any {
// Focus the canvas explicitly to activate tha game (#961).
v.Call("focus")
@ -545,7 +545,7 @@ func setCanvasEventHandlers(v js.Value) {
}
return nil
}))
v.Call("addEventListener", "mouseup", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "mouseup", js.FuncOf(func(this js.Value, args []js.Value) any {
e := args[0]
e.Call("preventDefault")
if err := theUI.input.updateFromEvent(e); err != nil && theUI.err != nil {
@ -554,7 +554,7 @@ func setCanvasEventHandlers(v js.Value) {
}
return nil
}))
v.Call("addEventListener", "mousemove", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "mousemove", js.FuncOf(func(this js.Value, args []js.Value) any {
e := args[0]
e.Call("preventDefault")
if err := theUI.input.updateFromEvent(e); err != nil && theUI.err != nil {
@ -563,7 +563,7 @@ func setCanvasEventHandlers(v js.Value) {
}
return nil
}))
v.Call("addEventListener", "wheel", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "wheel", js.FuncOf(func(this js.Value, args []js.Value) any {
e := args[0]
e.Call("preventDefault")
if err := theUI.input.updateFromEvent(e); err != nil && theUI.err != nil {
@ -574,7 +574,7 @@ func setCanvasEventHandlers(v js.Value) {
}))
// Touch
v.Call("addEventListener", "touchstart", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "touchstart", js.FuncOf(func(this js.Value, args []js.Value) any {
// Focus the canvas explicitly to activate tha game (#961).
v.Call("focus")
@ -586,7 +586,7 @@ func setCanvasEventHandlers(v js.Value) {
}
return nil
}))
v.Call("addEventListener", "touchend", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "touchend", js.FuncOf(func(this js.Value, args []js.Value) any {
e := args[0]
e.Call("preventDefault")
if err := theUI.input.updateFromEvent(e); err != nil && theUI.err != nil {
@ -595,7 +595,7 @@ func setCanvasEventHandlers(v js.Value) {
}
return nil
}))
v.Call("addEventListener", "touchmove", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "touchmove", js.FuncOf(func(this js.Value, args []js.Value) any {
e := args[0]
e.Call("preventDefault")
if err := theUI.input.updateFromEvent(e); err != nil && theUI.err != nil {
@ -606,14 +606,14 @@ func setCanvasEventHandlers(v js.Value) {
}))
// Context menu
v.Call("addEventListener", "contextmenu", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "contextmenu", js.FuncOf(func(this js.Value, args []js.Value) any {
e := args[0]
e.Call("preventDefault")
return nil
}))
// Context
v.Call("addEventListener", "webglcontextlost", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
v.Call("addEventListener", "webglcontextlost", js.FuncOf(func(this js.Value, args []js.Value) any {
e := args[0]
e.Call("preventDefault")
window.Get("location").Call("reload")

View File

@ -52,7 +52,7 @@ func (s *Shader) Dispose() {
s.shader = nil
}
func (s *Shader) convertUniforms(uniforms map[string]interface{}) [][]float32 {
func (s *Shader) convertUniforms(uniforms map[string]any) [][]float32 {
return s.shader.ConvertUniforms(uniforms)
}

View File

@ -499,7 +499,7 @@ func TestShaderUniformFirstElement(t *testing.T) {
shaders := []struct {
Name string
Shader string
Uniforms map[string]interface{}
Uniforms map[string]any
}{
{
Name: "float array",
@ -510,7 +510,7 @@ var C [2]float
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return vec4(C[0], 1, 1, 1)
}`,
Uniforms: map[string]interface{}{
Uniforms: map[string]any{
"C": []float32{1, 1},
},
},
@ -523,7 +523,7 @@ var C [1]float
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return vec4(C[0], 1, 1, 1)
}`,
Uniforms: map[string]interface{}{
Uniforms: map[string]any{
"C": []float32{1},
},
},
@ -536,7 +536,7 @@ var C [2]mat2
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return vec4(C[0][0][0], 1, 1, 1)
}`,
Uniforms: map[string]interface{}{
Uniforms: map[string]any{
"C": []float32{1, 0, 0, 0, 0, 0, 0, 0},
},
},
@ -745,7 +745,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
op := &ebiten.DrawRectShaderOptions{}
op.Uniforms = map[string]interface{}{
op.Uniforms = map[string]any{
"Mat2": []float32{
1.0 / 256.0, 2.0 / 256.0,
3.0 / 256.0, 4.0 / 256.0,
@ -783,7 +783,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
op := &ebiten.DrawRectShaderOptions{}
op.Uniforms = map[string]interface{}{
op.Uniforms = map[string]any{
"Mat2": []float32{
1.0 / 256.0, 2.0 / 256.0,
3.0 / 256.0, 4.0 / 256.0,
@ -823,7 +823,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
op := &ebiten.DrawRectShaderOptions{}
op.Uniforms = map[string]interface{}{
op.Uniforms = map[string]any{
"Mat3": []float32{
1.0 / 256.0, 2.0 / 256.0, 3.0 / 256.0,
4.0 / 256.0, 5.0 / 256.0, 6.0 / 256.0,
@ -862,7 +862,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
op := &ebiten.DrawRectShaderOptions{}
op.Uniforms = map[string]interface{}{
op.Uniforms = map[string]any{
"Mat3": []float32{
1.0 / 256.0, 2.0 / 256.0, 3.0 / 256.0,
4.0 / 256.0, 5.0 / 256.0, 6.0 / 256.0,
@ -904,7 +904,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
op := &ebiten.DrawRectShaderOptions{}
op.Uniforms = map[string]interface{}{
op.Uniforms = map[string]any{
"Mat4": []float32{
1.0 / 256.0, 2.0 / 256.0, 3.0 / 256.0, 4.0 / 256.0,
5.0 / 256.0, 6.0 / 256.0, 7.0 / 256.0, 8.0 / 256.0,
@ -944,7 +944,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
op := &ebiten.DrawRectShaderOptions{}
op.Uniforms = map[string]interface{}{
op.Uniforms = map[string]any{
"Mat4": []float32{
1.0 / 256.0, 2.0 / 256.0, 3.0 / 256.0, 4.0 / 256.0,
5.0 / 256.0, 6.0 / 256.0, 7.0 / 256.0, 8.0 / 256.0,