mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
web: Remove IsNodeJS
gjbt now creates a pseudo-Node environment by creating window.process object, and this conflicted with an assumption that Ebiten doesn't nothing on Node environment. See https://github.com/myitcv/gjbt/pull/13 for the detail. This change allows Ebiten work on pseudo-Node environment. Even after this change, Ebiten doesn't work on real Node environment due to lack of DOM.
This commit is contained in:
parent
e196ee59f7
commit
f19e349d38
@ -21,8 +21,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gopherjs/gopherwasm/js"
|
"github.com/gopherjs/gopherwasm/js"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/web"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -118,10 +116,6 @@ type context struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Init() error {
|
func Init() error {
|
||||||
if web.IsNodeJS() {
|
|
||||||
return fmt.Errorf("opengl: Node.js is not supported")
|
|
||||||
}
|
|
||||||
|
|
||||||
if js.Global.Get("WebGLRenderingContext") == js.Undefined {
|
if js.Global.Get("WebGLRenderingContext") == js.Undefined {
|
||||||
return fmt.Errorf("opengl: WebGL is not supported")
|
return fmt.Errorf("opengl: WebGL is not supported")
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/hooks"
|
"github.com/hajimehoshi/ebiten/internal/hooks"
|
||||||
"github.com/hajimehoshi/ebiten/internal/input"
|
"github.com/hajimehoshi/ebiten/internal/input"
|
||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||||
"github.com/hajimehoshi/ebiten/internal/web"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var canvas js.Value
|
var canvas js.Value
|
||||||
@ -227,10 +226,6 @@ func (u *userInterface) loop(g GraphicsContext) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Do nothing in node.js.
|
|
||||||
if web.IsNodeJS() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if document.Get("body") == js.Null {
|
if document.Get("body") == js.Null {
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
window.Call("addEventListener", "load", js.NewCallback(func([]js.Value) {
|
window.Call("addEventListener", "load", js.NewCallback(func([]js.Value) {
|
||||||
|
@ -28,21 +28,11 @@ var (
|
|||||||
isNodeJS = false
|
isNodeJS = false
|
||||||
)
|
)
|
||||||
|
|
||||||
func IsNodeJS() bool {
|
|
||||||
isNodeJSOnce.Do(func() {
|
|
||||||
isNodeJS = js.Global.Get("process") != js.Undefined
|
|
||||||
})
|
|
||||||
return isNodeJS
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsBrowser() bool {
|
func IsBrowser() bool {
|
||||||
return !IsNodeJS()
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsIOSSafari() bool {
|
func IsIOSSafari() bool {
|
||||||
if IsNodeJS() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
ua := js.Global.Get("navigator").Get("userAgent").String()
|
ua := js.Global.Get("navigator").Get("userAgent").String()
|
||||||
if !strings.Contains(ua, "iPhone") {
|
if !strings.Contains(ua, "iPhone") {
|
||||||
return false
|
return false
|
||||||
@ -51,9 +41,6 @@ func IsIOSSafari() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsAndroidChrome() bool {
|
func IsAndroidChrome() bool {
|
||||||
if IsNodeJS() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
ua := js.Global.Get("navigator").Get("userAgent").String()
|
ua := js.Global.Get("navigator").Get("userAgent").String()
|
||||||
if !strings.Contains(ua, "Android") {
|
if !strings.Contains(ua, "Android") {
|
||||||
return false
|
return false
|
||||||
|
@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
package web
|
package web
|
||||||
|
|
||||||
func IsNodeJS() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsBrowser() bool {
|
func IsBrowser() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user