func (a *ArchetypeInstance) SetQML(obj qml.Object) { a.QObject = obj obj.Set("simpleName", a.SimpleName) obj.Set("name", w.Archetypes[a.SimpleName].Name) qmlMoveUpdate(obj, float32(a.TP.X), float32(a.TP.Y), a.SimpleName, kinglib.MOVE_INSTANT, 0) }
func (ctrl *Control) Snapshot(request qml.Object) { if request.Int("status") != 2 { return } f, err := os.Create(os.Args[2]) if err != nil { ctrl.done <- err return } defer f.Close() img := ctrl.win.Snapshot() err = png.Encode(f, img) if err != nil { os.Remove(os.Args[2]) } ctrl.done <- err }
func (e *Entity) SetQML(obj qml.Object) { e.QObject = obj obj.Set("simpleName", e.SimpleName) obj.Set("name", w.Archetypes[e.SimpleName].Name) obj.Set("entityID", e.EntityID) qmlMoveUpdate(obj, e.FloatX, e.FloatY, e.SimpleName, kinglib.MOVE_INSTANT, 0) e.UpdateVisibility() }
func (ctrl *Control) TextReleased(text qml.Object) { x := text.Int("x") y := text.Int("y") width := text.Int("width") height := text.Int("height") ctrl.Emit(x+15, y+height/2) ctrl.Emit(x+width/2, 1.0*y+height/2) ctrl.Emit(x+width-15, 1.0*y+height/2) go func() { time.Sleep(500 * time.Millisecond) messages := []string{"Hello", "Hello", "Hacks"} ctrl.Message = messages[rand.Intn(len(messages))] + " from Go!" qml.Changed(ctrl, &ctrl.Message) }() }
func qmlMoveUpdate(obj qml.Object, x, y float32, simple_name string, move_type int, move_time int) { // Not good for now: obj.Set("simpleName", simple_name) switch move_type { case kinglib.MOVE_WALK: // fmt.Printf("Setting move_walk\n") obj.Set("dsx", int(x*32.0)) obj.Set("dsy", int(y*32.0)) obj.Set("dtime", move_time) obj.Set("moving", false) obj.Set("moving", true) default: obj.Set("x", int(x*32.0)) obj.Set("y", int(y*32.0)) } z := GetArchetypeZ(simple_name, int(y), int(x)) obj.Set("z", z) obj.Set("tx", x) obj.Set("ty", y) }
func (g *Game) DestroyMe(obj qml.Object) { obj.Destroy() }
func (g *Game) RightClick(obj qml.Object) { // Create a move: am := &kinglib.ActionMove{obj.Int("tx"), obj.Int("ty")} connection.SendGob(am) }
func (ctrl *Control) Done(emitter qml.Object) { emitter.Destroy() }