How to use hint method of main Package

Best Toxiproxy code snippet using main.hint

g3nworld.go

Source:g3nworld.go Github

copy

Full Screen

1package g3nworld2import (3 "errors"4 "fmt"5 "log"6 "os"7 "time"8 "github.com/g3n/engine/app"9 "github.com/g3n/engine/camera"10 "github.com/g3n/engine/core"11 "github.com/g3n/engine/experimental/collision"12 "github.com/g3n/engine/gls"13 "github.com/g3n/engine/graphic"14 "github.com/g3n/engine/gui"15 "github.com/g3n/engine/light"16 "github.com/g3n/engine/math32"17 "github.com/g3n/engine/renderer"18 "github.com/g3n/engine/util"19 "github.com/g3n/engine/util/helper"20 "github.com/g3n/engine/window"21 "github.com/go-gl/glfw/v3.3/glfw"22 "github.com/mrjrieke/nute/g3nd/g3nmash"23 g3ndpalette "github.com/mrjrieke/nute/g3nd/palette"24 "github.com/mrjrieke/nute/g3nd/worldg3n/g3ndisplay"25 "github.com/mrjrieke/nute/mashupsdk"26 "github.com/mrjrieke/nute/mashupsdk/client"27 "github.com/mrjrieke/nute/mashupsdk/guiboot"28 "github.com/mrjrieke/nute/mashupsdk/server"29)30type mashupSdkApiHandler struct {31}32type worldClientInitHandler struct {33}34// TODO: Can I get rid of this definition?35// -- duplicated in genericrenderer.go.36type IG3nRenderer interface {37 Layout(worldApp *WorldApp, g3nRenderableElements []*g3nmash.G3nDetailedElement)38 InitRenderLoop(worldApp *WorldApp) bool39 RenderElement(worldApp *WorldApp, g3n *g3nmash.G3nDetailedElement) bool40}41type WorldApp struct {42 custos bool // Run in guardian mode43 headless bool // Mode for troubleshooting.44 MSdkApiHandler *mashupSdkApiHandler45 wClientInitHandler *worldClientInitHandler46 displaySetupChan chan *mashupsdk.MashupDisplayHint47 displayPositionChan chan *mashupsdk.MashupDisplayHint48 mainWin *app.Application49 frameRater *util.FrameRater // Render loop frame rater50 scene *core.Node51 cam *camera.Camera52 oc *camera.OrbitControl53 IG3nRenderer IG3nRenderer54 IG3nDisplayRenderer g3ndisplay.IG3nDisplayRenderer55 MashupContext *mashupsdk.MashupContext // Needed for callbacks to other mashups56 // Library for mashup objects57 elementLibraryDictionary map[int64]*g3nmash.G3nDetailedElement58 maxElementId int6459 ConcreteElements map[int64]*g3nmash.G3nDetailedElement // g3n indexes by string...60 elementLoaderIndex map[string]int64 // g3n indexes by loader id...61 ClickedElements []*g3nmash.G3nDetailedElement // g3n indexes by string...62 backgroundG3n *g3nmash.G3nDetailedElement63 Sticky bool64 Focused bool // Whether current window has focus.65 isInit bool66}67var worldApp WorldApp68func NewWorldApp(headless bool, custos bool, renderer IG3nRenderer, displayRenderer g3ndisplay.IG3nDisplayRenderer) *WorldApp {69 worldApp = WorldApp{70 custos: custos,71 headless: headless,72 MSdkApiHandler: &mashupSdkApiHandler{},73 elementLibraryDictionary: map[int64]*g3nmash.G3nDetailedElement{},74 ConcreteElements: map[int64]*g3nmash.G3nDetailedElement{},75 elementLoaderIndex: map[string]int64{},76 ClickedElements: []*g3nmash.G3nDetailedElement{},77 displaySetupChan: make(chan *mashupsdk.MashupDisplayHint, 1),78 displayPositionChan: make(chan *mashupsdk.MashupDisplayHint, 1),79 IG3nRenderer: renderer,80 IG3nDisplayRenderer: displayRenderer,81 }82 return &worldApp83}84type InitEvent struct {85}86func (w *WorldApp) GetAuthToken() string {87 if w.custos {88 return client.GetServerAuthToken()89 } else {90 return server.GetServerAuthToken()91 }92}93func (w *WorldApp) G3nOnFocus(name string, ev interface{}) {94 log.Printf("G3nWorld Focus gained\n")95 if _, iOk := ev.(InitEvent); iOk {96 var postPonedCollections []*g3nmash.G3nDetailedElement97 g3nCollections, err := w.GetG3nDetailedGenreFilteredElements("Collection")98 if err != nil {99 log.Fatalf(err.Error(), err)100 }101 if len(g3nCollections) == 0 {102 log.Fatalf("No elements to render. If running standalone, provide -headless flag.")103 }104 for _, g3nCollection := range g3nCollections {105 if g3nCollection.GetDetailedElement().Colabrenderer != "" {106 postPonedCollections = append(postPonedCollections, g3nCollection)107 } else {108 var g3nCollectionElements []*g3nmash.G3nDetailedElement109 var g3nCollectionErr error110 if g3nCollection.GetDetailedElement().GetRenderer() != "" {111 g3nCollectionElements, g3nCollectionErr = w.GetG3nDetailedFilteredElements(g3nCollection.GetDetailedElement().GetRenderer(), true)112 if len(g3nCollectionElements) == 0 {113 // Try lookup by child elements instead...114 g3nCollectionElements, g3nCollectionErr = w.GetG3nDetailedChildElements(g3nCollection)115 }116 } else {117 g3nCollectionElements, g3nCollectionErr = w.GetG3nDetailedChildElements(g3nCollection)118 }119 if g3nCollectionErr != nil {120 log.Fatalf(err.Error(), g3nCollectionErr)121 }122 // Handoff...123 w.IG3nRenderer.Layout(w, g3nCollectionElements)124 }125 }126 for _, g3nCollection := range postPonedCollections {127 g3nCollectionElements, err := w.GetG3nDetailedChildElements(g3nCollection)128 if err != nil {129 log.Fatalf(err.Error(), err)130 }131 // Handoff...132 w.IG3nRenderer.Layout(w, g3nCollectionElements)133 }134 } else {135 // Focus gained...136 log.Printf("G3n Focus gained\n")137 w.Transform()138 log.Printf("G3n End Focus gained\n")139 }140 log.Printf("G3nWorld End Focus gained\n")141}142func (w *WorldApp) ResetChangeStates() []*mashupsdk.MashupElementState {143 changedElements := []*mashupsdk.MashupElementState{}144 for _, g3nDetailedElement := range w.ConcreteElements {145 if g3nDetailedElement.GetDisplayState() != mashupsdk.Init {146 g3nDetailedElement.ApplyState(mashupsdk.Clicked, false)147 changedElements = append(changedElements, g3nDetailedElement.GetMashupElementState())148 }149 }150 return changedElements151}152func (w *WorldApp) NewElementIdPump() int64 {153 w.maxElementId = w.maxElementId + 1154 return w.maxElementId155}156func (w *WorldApp) CloneG3nDetailedElement(g3nElement *g3nmash.G3nDetailedElement, elementStates *[]interface{}) *g3nmash.G3nDetailedElement {157 return w.indexG3nDetailedElement(g3nmash.CloneG3nDetailedElement(w.GetG3nDetailedElementById, w.GetG3nDetailedLibraryElementById, w.indexG3nDetailedElement, w.NewElementIdPump, g3nElement, elementStates))158}159func (w *WorldApp) NewG3nDetailedElement(detailedElement *mashupsdk.MashupDetailedElement, deepCopy bool) *g3nmash.G3nDetailedElement {160 return w.indexG3nDetailedElement(g3nmash.NewG3nDetailedElement(detailedElement, deepCopy))161}162func (w *WorldApp) indexG3nDetailedElement(g3nDetailedElement *g3nmash.G3nDetailedElement) *g3nmash.G3nDetailedElement {163 if g3nDetailedElement.GetBasisId() < 0 && g3nDetailedElement.GetDisplayId() == 0 {164 w.elementLibraryDictionary[g3nDetailedElement.GetBasisId()] = g3nDetailedElement165 } else {166 w.ConcreteElements[g3nDetailedElement.GetDisplayId()] = g3nDetailedElement167 w.elementLoaderIndex[g3nDetailedElement.GetDisplayName()] = g3nDetailedElement.GetDisplayId()168 if g3nDetailedElement.IsBackground() {169 w.backgroundG3n = g3nDetailedElement170 }171 }172 return g3nDetailedElement173}174func (w *WorldApp) GetG3nDetailedFilteredElements(renderer string, abstract bool) ([]*g3nmash.G3nDetailedElement, error) {175 filteredElements := []*g3nmash.G3nDetailedElement{}176 if renderer == "" {177 log.Printf("No filter provided. No filtered elements found.\n")178 return nil, errors.New("no filter provided - no filtered elements found")179 }180 for _, element := range w.ConcreteElements {181 if element.GetDetailedElement().Renderer == renderer {182 if abstract {183 if element.IsAbstract() {184 filteredElements = append(filteredElements, element)185 }186 } else {187 filteredElements = append(filteredElements, element)188 }189 }190 }191 return filteredElements, nil192}193func (w *WorldApp) GetG3nDetailedChildElements(g3n *g3nmash.G3nDetailedElement) ([]*g3nmash.G3nDetailedElement, error) {194 filteredElements := []*g3nmash.G3nDetailedElement{}195 if g3n == nil {196 log.Printf("No filter provided. No filtered elements found.\n")197 return nil, errors.New("no filter provided - no filtered elements found")198 }199 for _, childId := range g3n.GetChildElementIds() {200 if tc, tErr := worldApp.GetG3nDetailedElementById(childId); tErr == nil {201 filteredElements = append(filteredElements, tc)202 } else {203 log.Printf("Skipping non-concrete abstract element: %d\n", childId)204 continue205 }206 }207 return filteredElements, nil208}209func (w *WorldApp) GetG3nDetailedGenreFilteredElements(genre string) ([]*g3nmash.G3nDetailedElement, error) {210 filteredElements := []*g3nmash.G3nDetailedElement{}211 for _, element := range w.ConcreteElements {212 if element.GetDetailedElement().GetGenre() == genre {213 filteredElements = append(filteredElements, element)214 }215 }216 return filteredElements, nil217}218func (w *WorldApp) AddToScene(node core.INode) *core.Node {219 if node == nil {220 return nil221 }222 if w.scene.FindLoaderID(node.GetNode().LoaderID()) == nil {223 log.Printf("Item added %s: %v", node.GetNode().LoaderID(), w.scene.Add(node))224 return w.scene.Add(node)225 } else {226 return nil227 }228}229func (w *WorldApp) UpsertToScene(node core.INode) *core.Node {230 if node == nil {231 return nil232 }233 if w.scene.FindLoaderID(node.GetNode().LoaderID()) == nil {234 return w.scene.Add(node)235 }236 return nil237}238func (w *WorldApp) RemoveFromScene(node core.INode) bool {239 return w.scene.Remove(node)240}241func (w *WorldApp) GetG3nDetailedElementById(eid int64) (*g3nmash.G3nDetailedElement, error) {242 if g3nElement, g3nElementOk := w.ConcreteElements[eid]; g3nElementOk {243 return g3nElement, nil244 }245 return nil, fmt.Errorf("element does not exist: %d", eid)246}247func (w *WorldApp) GetG3nDetailedChildElementsByGenre(g3n *g3nmash.G3nDetailedElement, genre string) []*g3nmash.G3nDetailedElement {248 results := []*g3nmash.G3nDetailedElement{}249 for _, childId := range g3n.GetChildElementIds() {250 if g3nChild, err := w.GetG3nDetailedElementById(childId); err == nil {251 if g3nChild.HasGenre(genre) {252 results = append(results, g3nChild)253 }254 }255 }256 return results257}258func (w *WorldApp) GetG3nDetailedLibraryElementById(eid int64) (*g3nmash.G3nDetailedElement, error) {259 if g3nElement, g3nElementOk := w.elementLibraryDictionary[eid]; g3nElementOk {260 return g3nElement, nil261 }262 return nil, fmt.Errorf("element does not exist: %d", eid)263}264func (w *WorldApp) GetParentElements(g3nDetailedElement *g3nmash.G3nDetailedElement) []*g3nmash.G3nDetailedElement {265 parentIds := g3nDetailedElement.GetParentElementIds()266 g3nParentDetailedElements := []*g3nmash.G3nDetailedElement{}267 for _, parentId := range parentIds {268 if g3parent, gpErr := w.GetG3nDetailedElementById(parentId); gpErr == nil {269 g3nParentDetailedElements = append(g3nParentDetailedElements, g3parent)270 }271 }272 return g3nParentDetailedElements273}274func (w *WorldApp) GetSiblingElements(g3nDetailedElement *g3nmash.G3nDetailedElement) []*g3nmash.G3nDetailedElement {275 parentIds := g3nDetailedElement.GetParentElementIds()276 g3nParentDetailedElements := []*g3nmash.G3nDetailedElement{}277 for _, parentId := range parentIds {278 if g3parent, gpErr := w.GetG3nDetailedElementById(parentId); gpErr == nil {279 g3nParentDetailedElements = append(g3nParentDetailedElements, g3parent)280 }281 }282 g3nSiblingDetailedElements := []*g3nmash.G3nDetailedElement{}283 for _, g3nParentDetailedElement := range g3nParentDetailedElements {284 for _, childId := range g3nParentDetailedElement.GetChildElementIds() {285 if g3nSibling, gsErr := w.GetG3nDetailedElementById(childId); gsErr == nil {286 g3nSiblingDetailedElements = append(g3nSiblingDetailedElements, g3nSibling)287 }288 }289 }290 return g3nSiblingDetailedElements291}292func (w *WorldApp) Cast(inode core.INode, caster *collision.Raycaster) (core.INode, []collision.Intersect) {293 // Ignore invisible nodes and their descendants294 if !inode.Visible() {295 return nil, nil296 }297 if _, ok := inode.(gui.IPanel); ok {298 // TODO: Do we care about these types at all?299 } else if igr, ok := inode.(graphic.IGraphic); ok {300 if igr.Renderable() {301 if _, meshOk := inode.(*graphic.Mesh); meshOk {302 return inode, caster.IntersectObject(inode, false)303 }304 }305 // Ignore everything else.306 }307 if inode.Children() != nil {308 for _, ichild := range inode.Children() {309 if n, intersections := w.Cast(ichild, caster); n != nil && len(intersections) > 0 {310 return n, intersections311 }312 }313 }314 return nil, nil315}316func (w *WorldApp) InitServer(callerCreds string, insecure bool) {317 if callerCreds != "" {318 server.InitServer(callerCreds, insecure, w.MSdkApiHandler, w.wClientInitHandler)319 } else {320 go func() {321 w.displaySetupChan <- &mashupsdk.MashupDisplayHint{Xpos: 0, Ypos: 0, Width: 400, Height: 800}322 }()323 }324}325func (w *WorldApp) Transform() []*mashupsdk.MashupElementState {326 changedElements := []*mashupsdk.MashupElementState{}327 attitudeVisitedNodes := map[int64]bool{}328 // Notify renderers about to enter render loop.329 worldApp.IG3nRenderer.InitRenderLoop(w)330 for _, g3nDetailedElement := range w.ConcreteElements {331 if g3nDetailedElement.IsAbstract() {332 continue333 }334 changed := worldApp.IG3nRenderer.RenderElement(w, g3nDetailedElement)335 if !g3nDetailedElement.IsStateSet(mashupsdk.Hidden) && !g3nDetailedElement.IsBackground() {336 if g3nDetailedElement.IsStateSet(mashupsdk.Clicked) {337 if g3nDetailedElement.HasAttitudeAdjustment() {338 log.Printf("G3n Has parents\n")339 parentIds := g3nDetailedElement.GetParentElementIds()340 g3nParentDetailedElements := []*g3nmash.G3nDetailedElement{}341 for _, parentId := range parentIds {342 if g3parent, gpErr := w.GetG3nDetailedElementById(parentId); gpErr == nil {343 g3nParentDetailedElements = append(g3nParentDetailedElements, g3parent)344 }345 attitudeVisitedNodes[parentId] = true346 }347 log.Printf("G3n adjusting for parents: %d\n", len(g3nParentDetailedElements))348 g3nDetailedElement.AdjustAttitude(g3nParentDetailedElements)349 } else {350 if _, vOk := attitudeVisitedNodes[g3nDetailedElement.GetDisplayId()]; !vOk {351 g3nDetailedElement.AdjustAttitude([]*g3nmash.G3nDetailedElement{g3nDetailedElement})352 attitudeVisitedNodes[g3nDetailedElement.GetDisplayId()] = true353 }354 }355 } else {356 if _, vOk := attitudeVisitedNodes[g3nDetailedElement.GetDisplayId()]; !vOk {357 g3nDetailedElement.AdjustAttitude([]*g3nmash.G3nDetailedElement{g3nDetailedElement})358 attitudeVisitedNodes[g3nDetailedElement.GetDisplayId()] = true359 }360 }361 }362 if changed {363 changedElements = append(changedElements, g3nDetailedElement.GetMashupElementState())364 }365 }366 return changedElements367}368func (w *WorldApp) InitMainWindow() {369 log.Printf("Initializing mainWin.")370 initHandler := func(a *app.Application) {371 log.Printf("InitHandler.")372 if w.mainWin == nil {373 log.Printf("Main app handle initialized.")374 w.mainWin = a375 }376 log.Printf("Frame rater setup.")377 w.frameRater = util.NewFrameRater(10)378 log.Printf("Frame rater setup complete.")379 displayHint := <-w.displaySetupChan380 log.Printf("Initializing app.")381 app.AppCustom(a, "Hello world G3n", int(displayHint.Width), int(displayHint.Height), int(displayHint.Xpos), int(displayHint.Ypos+displayHint.Height))382 log.Printf("Initializing scene.")383 w.scene = core.NewNode()384 // Set the scene to be managed by the gui manager385 gui.Manager().Set(w.scene)386 // Create perspective camera387 w.cam = camera.New(1)388 w.cam.SetPosition(0, 0, 3)389 w.scene.Add(w.cam)390 // Set up orbit control for the camera391 w.oc = camera.NewOrbitControl(w.cam)392 w.oc.Zoom(60.0)393 log.Printf("Finished Orbit Control setup.")394 // Set up callback to update viewport and camera aspect ratio when the window is resized395 onResize := func(evname string, ev interface{}) {396 // Get framebuffer size and update viewport accordingly397 width, height := a.GetSize()398 a.Gls().Viewport(0, 0, int32(width), int32(height))399 // Update the camera's aspect ratio400 w.cam.SetAspect(float32(width) / float32(height))401 xpos, ypos := (*w.mainWin).IWindow.(*window.GlfwWindow).Window.GetPos()402 if w.MashupContext != nil {403 w.MashupContext.Client.OnResize(w.MashupContext,404 &mashupsdk.MashupDisplayBundle{405 AuthToken: worldApp.GetAuthToken(),406 MashupDisplayHint: &mashupsdk.MashupDisplayHint{407 Xpos: int64(xpos),408 Ypos: int64(ypos),409 Width: int64(width),410 Height: int64(height),411 },412 })413 }414 }415 a.Subscribe(window.OnWindowSize, onResize)416 onResize("", nil)417 w.mainWin.Subscribe(gui.OnFocus, w.G3nOnFocus)418 (*w.mainWin).IWindow.(*window.GlfwWindow).Window.SetAttrib(glfw.Floating, 1)419 (*w.mainWin).IWindow.(*window.GlfwWindow).Window.SetAttrib(glfw.FocusOnShow, 1)420 (*w.mainWin).IWindow.(*window.GlfwWindow).Window.SetCloseCallback(func(glfwWindow *glfw.Window) {421 if w.MashupContext != nil {422 w.MashupContext.Client.Shutdown(w.MashupContext, &mashupsdk.MashupEmpty{AuthToken: worldApp.GetAuthToken()})423 }424 os.Exit(0)425 })426 w.mainWin.Subscribe(gui.OnKeyDown, func(name string, ev interface{}) {427 kev := ev.(*window.KeyEvent)428 if kev.Key == window.KeyLeftControl {429 w.Sticky = true430 }431 })432 w.mainWin.Subscribe(gui.OnKeyUp, func(name string, ev interface{}) {433 kev := ev.(*window.KeyEvent)434 if kev.Key == window.KeyLeftControl {435 w.Sticky = false436 }437 })438 w.mainWin.Subscribe(window.OnWindowFocus, func(name string, ev interface{}) {439 wev := ev.(*window.FocusEvent)440 w.Focused = wev.Focused441 // Tell fyne not to try to regain focus.442 if w.MashupContext != nil && wev.Focused {443 w.MashupContext.Client.OnResize(w.MashupContext,444 &mashupsdk.MashupDisplayBundle{445 AuthToken: worldApp.GetAuthToken(),446 MashupDisplayHint: &mashupsdk.MashupDisplayHint{447 Focused: wev.Focused,448 },449 })450 }451 })452 w.mainWin.Subscribe(gui.OnMouseUp, func(name string, ev interface{}) {453 mev := ev.(*window.MouseEvent)454 if mev.Mods == window.ModControl {455 w.Sticky = true456 } else {457 w.Sticky = false458 }459 g3Width, g3Height := w.mainWin.GetSize()460 xPosNdc := 2*(mev.Xpos/float32(g3Width)) - 1461 yPosNdc := -2*(mev.Ypos/float32(g3Height)) + 1462 caster := collision.NewRaycaster(&math32.Vector3{}, &math32.Vector3{})463 caster.SetFromCamera(w.cam, xPosNdc, yPosNdc)464 if w.scene.Visible() {465 itemClicked, _ := w.Cast(w.scene, caster)466 itemMatched := false467 if itemClicked != nil {468 if g3nDetailedIndex, ok := w.elementLoaderIndex[itemClicked.GetNode().LoaderID()]; ok {469 if g3nDetailedElement, ok := w.ConcreteElements[g3nDetailedIndex]; ok {470 g3nDetailedElement.ApplyState(mashupsdk.Clicked, true)471 fmt.Printf("matched: %s\n", g3nDetailedElement.GetDisplayName())472 itemMatched = true473 for _, clickedElement := range w.ClickedElements {474 if clickedElement.GetDisplayId() != g3nDetailedElement.GetDisplayId() {475 clickedElement.ApplyState(mashupsdk.Clicked, false)476 }477 }478 if !w.Sticky {479 w.ClickedElements = w.ClickedElements[:0]480 }481 w.ClickedElements = append(w.ClickedElements, g3nDetailedElement)482 }483 }484 }485 if !itemMatched {486 w.backgroundG3n.ApplyState(mashupsdk.Clicked, true)487 for _, clickedElement := range w.ClickedElements {488 if clickedElement.GetDisplayId() != w.backgroundG3n.GetDisplayId() {489 clickedElement.ApplyState(mashupsdk.Clicked, false)490 }491 }492 if !w.Sticky {493 w.ClickedElements = w.ClickedElements[:0]494 }495 w.ClickedElements = append(w.ClickedElements, w.backgroundG3n)496 } else {497 w.backgroundG3n.ApplyState(mashupsdk.Clicked, false)498 }499 changedElements := w.Transform()500 if !itemMatched {501 changedElements = append(changedElements, w.backgroundG3n.GetMashupElementState())502 }503 elementStateBundle := mashupsdk.MashupElementStateBundle{504 AuthToken: worldApp.GetAuthToken(),505 ElementStates: changedElements,506 }507 if !w.headless {508 w.MashupContext.Client.UpsertMashupElementsState(w.MashupContext, &elementStateBundle)509 }510 }511 })512 // Create and add lights to the scene513 w.scene.Add(light.NewAmbient(g3ndpalette.WHITE, 0.8))514 pointLight := light.NewPoint(g3ndpalette.WHITE, 5.0)515 pointLight.SetPosition(1, 0, 2)516 w.scene.Add(pointLight)517 // Create and add an axis helper to the scene518 w.scene.Add(helper.NewAxes(0.5))519 w.frameRater.Start()520 // Set background color to gray521 if w.backgroundG3n != nil {522 w.IG3nRenderer.RenderElement(w, w.backgroundG3n)523 g3ndpalette.RefreshBackgroundColor(w.mainWin.Gls(), w.backgroundG3n.GetColor(), 1.0)524 }525 go func() {526 log.Println("Watching position events.")527 for displayHint := range w.displayPositionChan {528 log.Printf("G3n applying xpos: %d ypos: %d width: %d height: %d ytranslate: %d\n", int(displayHint.Xpos), int(displayHint.Ypos), int(displayHint.Width), int(displayHint.Height), int(displayHint.Ypos+displayHint.Height))529 if !w.headless {530 if (w.mainWin != nil) && (w.mainWin.IWindow != nil) && ((*w.mainWin).IWindow.(*window.GlfwWindow).Window != nil) {531 if worldApp.IG3nDisplayRenderer != nil {532 displayHint = worldApp.IG3nDisplayRenderer.Render((*w.mainWin).IWindow.(*window.GlfwWindow), displayHint)533 } else {534 if !w.custos {535 (*w.mainWin).IWindow.(*window.GlfwWindow).Window.SetAttrib(glfw.Decorated, 0)536 }537 if x, y := (*w.mainWin).IWindow.(*window.GlfwWindow).Window.GetPos(); x != int(displayHint.Xpos) || y != int(displayHint.Ypos+displayHint.Height) {538 (*w.mainWin).IWindow.(*window.GlfwWindow).Window.SetPos(int(displayHint.Xpos), int(displayHint.Ypos+displayHint.Height))539 (*w.mainWin).IWindow.(*window.GlfwWindow).Window.SetSize(int(displayHint.Width), int(displayHint.Height))540 }541 if !w.Focused && displayHint.Focused {542 log.Printf("G3n setting focus.")543 (*w.mainWin).IWindow.(*window.GlfwWindow).Window.Hide()544 (*w.mainWin).IWindow.(*window.GlfwWindow).Window.Show()545 displayHint.Focused = false546 w.Focused = true547 }548 }549 }550 }551 }552 log.Println("Exiting disply chan.")553 }()554 log.Printf("InitHandler complete.")555 }556 runtimeHandler := func(renderer *renderer.Renderer, deltaTime time.Duration) {557 w.frameRater.Start()558 if w.backgroundG3n != nil && w.backgroundG3n.GetColor() != nil {559 g3ndpalette.RefreshBackgroundColor(w.mainWin.Gls(), w.backgroundG3n.GetColor(), 1.0)560 }561 w.mainWin.Gls().Clear(gls.DEPTH_BUFFER_BIT | gls.STENCIL_BUFFER_BIT | gls.COLOR_BUFFER_BIT)562 renderer.Render(w.scene, w.cam)563 if !w.isInit {564 w.G3nOnFocus("", InitEvent{})565 w.isInit = true566 }567 w.frameRater.Wait()568 }569 guiboot.InitMainWindow(guiboot.G3n, initHandler, runtimeHandler)570}571func (w *worldClientInitHandler) RegisterContext(context *mashupsdk.MashupContext) {572 worldApp.MashupContext = context573}574// Sets all elements to a "Rest state."575func (w *mashupSdkApiHandler) ResetG3NDetailedElementStates() {576 log.Printf("G3n Received ResetG3NDetailedElementStates\n")577 for _, wes := range worldApp.ConcreteElements {578 wes.SetElementState(mashupsdk.Init)579 }580 log.Printf("G3n finished ResetG3NDetailedElementStates handle.\n")581}582func (mSdk *mashupSdkApiHandler) OnResize(displayHint *mashupsdk.MashupDisplayHint) {583 if worldApp.mainWin != nil && (*worldApp.mainWin).IWindow != nil {584 log.Printf("G3n Received onResize xpos: %d ypos: %d width: %d height: %d ytranslate: %d\n", int(displayHint.Xpos), int(displayHint.Ypos), int(displayHint.Width), int(displayHint.Height), int(displayHint.Ypos+displayHint.Height))585 worldApp.displayPositionChan <- displayHint586 } else {587 if displayHint.Width != 0 && displayHint.Height != 0 {588 log.Printf("G3n initializing with: %d ypos: %d width: %d height: %d ytranslate: %d\n", int(displayHint.Xpos), int(displayHint.Ypos), int(displayHint.Width), int(displayHint.Height), int(displayHint.Ypos+displayHint.Height))589 worldApp.displaySetupChan <- displayHint590 worldApp.displayPositionChan <- displayHint591 } else {592 log.Printf("G3n Could not apply xpos: %d ypos: %d width: %d height: %d ytranslate: %d\n", int(displayHint.Xpos), int(displayHint.Ypos), int(displayHint.Width), int(displayHint.Height), int(displayHint.Ypos+displayHint.Height))593 }594 log.Printf("G3n finished onResize handle.")595 }596}597func (w *mashupSdkApiHandler) GetMashupElements() (*mashupsdk.MashupDetailedElementBundle, error) {598 log.Printf("G3n Received GetMashupElements\n")599 log.Printf("G3n finished GetMashupElements handle.\n")600 return nil, nil601}602func (mSdk *mashupSdkApiHandler) UpsertMashupElements(detailedElementBundle *mashupsdk.MashupDetailedElementBundle) (*mashupsdk.MashupDetailedElementBundle, error) {603 log.Printf("G3n Received UpsertMashupElements\n")604 result := &mashupsdk.MashupDetailedElementBundle{DetailedElements: []*mashupsdk.MashupDetailedElement{}}605 incompleteG3nElements := []*g3nmash.G3nDetailedElement{}606 for _, detailedElement := range detailedElementBundle.DetailedElements {607 g3nDetailedElement := worldApp.NewG3nDetailedElement(detailedElement, false)608 if g3nDetailedElement.IsLibraryElement() {609 continue610 }611 if detailedElement.State.Id != int64(mashupsdk.Immutable) {612 g3nDetailedElement.ApplyState(mashupsdk.Clicked, false)613 }614 for _, childId := range g3nDetailedElement.GetChildElementIds() {615 if childId < 0 {616 incompleteG3nElements = append(incompleteG3nElements, g3nDetailedElement)617 break618 }619 }620 if worldApp.maxElementId < g3nDetailedElement.GetDisplayId() {621 worldApp.maxElementId = g3nDetailedElement.GetDisplayId()622 }623 // Add to resulting element states.624 result.DetailedElements = append(result.DetailedElements, detailedElement)625 }626 if len(incompleteG3nElements) > 0 {627 // Fill out incomplete g3n elements628 generatedElements := []interface{}{}629 for _, incompleteG3nElement := range incompleteG3nElements {630 newChildIds := []int64{}631 for _, childId := range incompleteG3nElement.GetChildElementIds() {632 if childId < 0 {633 if libElement, err := worldApp.GetG3nDetailedLibraryElementById(childId); err == nil {634 clonedChild := worldApp.CloneG3nDetailedElement(libElement, &generatedElements)635 newChildIds = append(newChildIds, clonedChild.GetDisplayId())636 } else {637 log.Printf("Missing child from library: %d\n", childId)638 }639 } else {640 // Deal with concrete element.641 if concreteElement, err := worldApp.GetG3nDetailedElementById(childId); err == nil {642 newChildIds = append(newChildIds, concreteElement.GetDisplayId())643 }644 }645 }646 if len(newChildIds) > 0 {647 incompleteG3nElement.SetChildElements(newChildIds)648 }649 }650 for _, generatedElement := range generatedElements {651 result.DetailedElements = append(result.DetailedElements, generatedElement.(*mashupsdk.MashupDetailedElement))652 }653 }654 log.Printf("G3n UpsertMashupElements updated\n")655 return result, nil656}657func (mSdk *mashupSdkApiHandler) applyStateHelper(g3nId int64, x mashupsdk.DisplayElementState, isset bool) {658 child := worldApp.ConcreteElements[g3nId]659 child.ApplyState(mashupsdk.DisplayElementState(x), isset)660 if len(child.GetDetailedElement().Childids) > 0 {661 for _, cId := range child.GetDetailedElement().Childids {662 mSdk.applyStateHelper(cId, x, isset)663 }664 }665}666func (mSdk *mashupSdkApiHandler) setStateHelper(g3nId int64, x mashupsdk.DisplayElementState) {667 child := worldApp.ConcreteElements[g3nId]668 if child.GetDetailedElement().Genre != "Attitude" {669 child.SetElementState(mashupsdk.DisplayElementState(x))670 }671 if len(child.GetDetailedElement().Childids) > 0 {672 for _, cId := range child.GetDetailedElement().Childids {673 mSdk.setStateHelper(cId, x)674 }675 }676}677func (mSdk *mashupSdkApiHandler) UpsertMashupElementsState(elementStateBundle *mashupsdk.MashupElementStateBundle) (*mashupsdk.MashupElementStateBundle, error) {678 log.Printf("G3n UpsertMashupElementsState called\n")679 ClickedElements := map[int64]*g3nmash.G3nDetailedElement{}680 recursiveElements := map[int64]*g3nmash.G3nDetailedElement{}681 for _, es := range elementStateBundle.ElementStates {682 if g3nDetailedElement, ok := worldApp.ConcreteElements[es.GetId()]; ok {683 g3nDetailedElement.SetElementState(mashupsdk.DisplayElementState(es.State))684 if g3nDetailedElement.IsStateSet(mashupsdk.Recursive) {685 recursiveElements[es.GetId()] = g3nDetailedElement686 }687 log.Printf("Display fields set to: %d", g3nDetailedElement.GetMashupElementState())688 if (mashupsdk.DisplayElementState(es.State) & mashupsdk.Clicked) == mashupsdk.Clicked {689 ClickedElements[es.GetId()] = g3nDetailedElement690 }691 }692 }693 if len(ClickedElements) > 0 {694 // Remove existing clicks.695 for _, clickedElement := range worldApp.ClickedElements {696 if _, ok := ClickedElements[clickedElement.GetDisplayId()]; !ok {697 clickedElement.ApplyState(mashupsdk.Clicked, false)698 }699 }700 worldApp.ClickedElements = worldApp.ClickedElements[:0]701 // Impossible to determine ordering of clicks from upsert at this time.702 for _, g3nDetailedElement := range ClickedElements {703 worldApp.ClickedElements = append(worldApp.ClickedElements, g3nDetailedElement)704 }705 }706 if len(recursiveElements) > 0 {707 for _, recursiveElement := range recursiveElements {708 stateBits := recursiveElement.GetDetailedElement().State.State709 // Unset recursive for child elements710 stateBits &= ^int64(mashupsdk.Recursive)711 // Apply this state change to all child elements.712 mSdk.setStateHelper(recursiveElement.GetDisplayId(), mashupsdk.DisplayElementState(stateBits))713 }714 }715 log.Printf("G3n dispatching focus\n")716 // TODO: Feedback from Custos is broken... Disable for now.717 if !worldApp.custos && worldApp.mainWin != nil {718 worldApp.mainWin.Dispatch(gui.OnFocus, nil)719 }720 log.Printf("G3n End UpsertMashupElementsState called\n")721 return &mashupsdk.MashupElementStateBundle{}, nil722}...

Full Screen

Full Screen

controller.go

Source:controller.go Github

copy

Full Screen

...478 TargetCells: c.model.LastModifiedCells(),479 },480 },481 }482 hint := c.Grid().Hint(options, fakeLastFillSteps)483 if hint == nil || len(hint.CompoundSteps) == 0 {484 c.SetConsoleMessage("No hint to give.", true)485 return486 }487 c.SetConsoleMessage("{Hint}\n"+strings.Join(hint.Description(), "\n")+"\n\n"+"{ENTER} to accept, {ESC} to ignore", false)488 //This hast to be after setting console message, since SetConsoleMessage clears the last hint.489 c.lastShownHint = hint490 lastStep := hint.CompoundSteps[0].FillStep491 c.SetSelected(lastStep.TargetCells[0].Cell(c.Grid()))492}493func (c *mainController) EnterHint() {494 if c.lastShownHint == nil {495 return496 }497 lastStep := c.lastShownHint.CompoundSteps[0].FillStep498 cell := lastStep.TargetCells[0]499 num := lastStep.TargetNums[0]500 c.SetSelected(cell.Cell(c.Grid()))501 c.SetSelectedNumber(num)502 c.ClearConsole()503}504func (c *mainController) Selected() sudoku.Cell {...

Full Screen

Full Screen

common.go

Source:common.go Github

copy

Full Screen

1package mashupsdk2type DisplayElementState int643const (4 Immutable DisplayElementState = 0 // For libraries5 Mutable DisplayElementState = 1 // For6 Init DisplayElementState = 27 Clicked DisplayElementState = 48 Moved DisplayElementState = 89 Hidden DisplayElementState = 16 // Hidden objects are not clickable10 Recursive DisplayElementState = 32 // Apply attributes recursively11)12type MashupDisplayState int13const (14 Configured MashupDisplayState = 115 Position MashupDisplayState = 216 Frame MashupDisplayState = 417 AppInitted MashupDisplayState = 818 DisplaySettled MashupDisplayState = 3119)20type MashupDisplayContext struct {21 MainWinDisplay *MashupDisplayHint22 yOffset int23 settled MashupDisplayState24}25func (m *MashupDisplayContext) GetYoffset() int {26 return m.yOffset27}28func (m *MashupDisplayContext) SetYoffset(a int) int {29 m.yOffset = a30 return m.yOffset31}32func (m *MashupDisplayContext) GetSettled() MashupDisplayState {33 return m.settled34}35func (m *MashupDisplayContext) ApplySettled(s MashupDisplayState, override bool) MashupDisplayState {36 if override {37 m.settled = s38 } else {39 m.settled |= s40 }41 return m.settled42}43func (m *MashupDisplayContext) OnResize(displayHint *MashupDisplayHint) bool {44 resize := false45 if m.MainWinDisplay == nil {46 resize = true47 m.MainWinDisplay = &MashupDisplayHint{}48 }49 if displayHint == nil {50 return false51 }52 if displayHint.Xpos != 0 && (*m.MainWinDisplay).Xpos != displayHint.Xpos {53 m.MainWinDisplay.Xpos = displayHint.Xpos54 resize = true55 }56 if displayHint.Ypos != 0 && (*m.MainWinDisplay).Ypos != displayHint.Ypos {57 m.MainWinDisplay.Ypos = displayHint.Ypos + int64(m.yOffset)58 resize = true59 }60 if displayHint.Width != 0 && (*m.MainWinDisplay).Width != displayHint.Width {61 m.MainWinDisplay.Width = displayHint.Width62 resize = true63 }64 if displayHint.Height != 0 && (*m.MainWinDisplay).Height != displayHint.Height+int64(m.yOffset) {65 m.MainWinDisplay.Height = displayHint.Height66 resize = true67 }68 if displayHint.Focused {69 resize = true70 }71 if m.settled < (Configured | Position | Frame | AppInitted) {72 return false73 } else if m.settled == (Configured | Position | Frame | AppInitted) {74 resize = true75 m.settled = DisplaySettled76 }77 return resize78}79// MashupApiHandler -- mashups implement this to handle all events sent from80// other mashups.81type MashupApiHandler interface {82 OnResize(displayHint *MashupDisplayHint)83 GetMashupElements() (*MashupDetailedElementBundle, error)84 UpsertMashupElements(detailedElementBundle *MashupDetailedElementBundle) (*MashupDetailedElementBundle, error)85 UpsertMashupElementsState(elementStateBundle *MashupElementStateBundle) (*MashupElementStateBundle, error)86 ResetG3NDetailedElementStates()87}88type MashupContextInitHandler interface {89 RegisterContext(*MashupContext)90}...

Full Screen

Full Screen

hint

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4}5import (6func main() {7 fmt.Println("Hello World")8}9import (10func main() {11 fmt.Println("Hello World")12}13import (14func main() {15 fmt.Println("Hello World")16}17import (18func main() {19 fmt.Println("Hello World")20}21import (22func main() {23 fmt.Println("Hello World")24}25import (26func main() {27 fmt.Println("Hello World")28}29import (30func main() {31 fmt.Println("Hello World")32}33import (34func main() {35 fmt.Println("Hello World")36}37import (38func main() {39 fmt.Println("Hello World")40}41import (42func main() {43 fmt.Println("Hello World")44}45import (46func main() {47 fmt.Println("Hello World")48}49import (50func main() {51 fmt.Println("Hello World")52}53import (54func main() {55 fmt.Println("Hello

Full Screen

Full Screen

hint

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("hello world")4}5import "fmt"6func main() {7 fmt.Println("hello world")8}9import "fmt"10func main() {11 fmt.Println("hello world")12}13import "fmt"14func main() {15 fmt.Println("hello world")16}17import "fmt"18func main() {19 fmt.Println("hello world")20}21import "fmt"22func main() {23 fmt.Println("hello world")24}25import "fmt"26func main() {27 fmt.Println("hello world")28}29import "fmt"30func main() {31 fmt.Println("hello world")32}33import "fmt"34func main() {35 fmt.Println("hello world")36}37import "fmt"38func main() {39 fmt.Println("hello world")40}41import "fmt"42func main() {43 fmt.Println("hello world")44}45import "fmt"46func main() {47 fmt.Println("hello world")48}49import "fmt"50func main() {51 fmt.Println("hello world")52}53import "fmt"54func main() {55 fmt.Println("hello world")56}57import "fmt"

Full Screen

Full Screen

hint

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, World!")4}5import (6func main() {7 fmt.Println("Hello, World!")8}9import (10func main() {11 fmt.Println("Hello, World!")12}13import (14func main() {15 fmt.Println("Hello, World!")16}17import (18func main() {19 fmt.Println("Hello, World!")20}21import (22func main() {23 fmt.Println("Hello, World!")24}25import (26func main() {27 fmt.Println("Hello, World!")28}29import (30func main() {31 fmt.Println("Hello, World!")32}33import (34func main() {35 fmt.Println("Hello, World!")36}37import (38func main() {39 fmt.Println("Hello, World!")40}41import (42func main() {43 fmt.Println("Hello, World!")44}45import (46func main() {47 fmt.Println("Hello, World!")48}49import (50func main() {51 fmt.Println("Hello, World!")52}53import (54func main() {55 fmt.Println("Hello, World!")56}57import (

Full Screen

Full Screen

hint

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter a number")4 reader := bufio.NewReader(os.Stdin)5 input, _ := reader.ReadString('6 input = strings.TrimRight(input, "7 fmt.Sscanf(input, "%d", &number)8 if number%2 == 0 {9 fmt.Println("The number is even")10 } else {11 fmt.Println("The number is odd")12 }13}14import (15func main() {16 fmt.Println("Enter a number")17 reader := bufio.NewReader(os.Stdin)18 input, _ := reader.ReadString('19 input = strings.TrimRight(input, "20 fmt.Sscanf(input, "%d", &number)21 if number%2 == 0 {22 fmt.Println("The number is even")23 } else {24 fmt.Println("The number is odd")25 }26}27import (28func main() {29 fmt.Println("Enter a number")30 reader := bufio.NewReader(os.Stdin)31 input, _ := reader.ReadString('32 input = strings.TrimRight(input, "33 fmt.Sscanf(input, "%d", &number)34 if number%2 == 0 {35 fmt.Println("The number is even")36 } else {37 fmt.Println("The number is odd")38 }39}40import (41func main() {42 fmt.Println("Enter a number")43 reader := bufio.NewReader(os.Stdin)44 input, _ := reader.ReadString('45 input = strings.TrimRight(input, "46 fmt.Sscanf(input, "%d", &number)47 if number%2 == 0 {48 fmt.Println("The number is even")49 } else {

Full Screen

Full Screen

hint

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, World!")4}5import (6func main() {7 fmt.Println("Hello, World!")8}9import (10func main() {11 fmt.Println("Hello, World!")12}13import (14func main() {15 fmt.Println("Hello, World!")16}17import (18func main() {19 fmt.Println("Hello, World!")20}21import (22func main() {23 fmt.Println("Hello, World!")24}25import (26func main() {27 fmt.Println("Hello, World!")28}29import (30func main() {31 fmt.Println("Hello, World!")32}33import (34func main() {35 fmt.Println("Hello, World!")36}37import (38func main() {39 fmt.Println("Hello, World!")40}41import (

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful