Exemplo n.º 1
0
func loadGameStateRaw(gp *GamePanel, state string) {
	var viewer gui.Widget
	if gp.game != nil {
		viewer = gp.game.viewer
	}
	err := base.FromBase64FromGob(&gp.game, state)
	if err != nil {
		base.Error().Printf("Error decoding game state: %v", err)
		return
	}
	gp.AnchorBox.RemoveChild(viewer)
	for _, child := range gp.AnchorBox.GetChildren() {
		if o, ok := child.(*Overlay); ok {
			gp.AnchorBox.RemoveChild(o)
			break
		}
	}
	gp.AnchorBox.AddChild(gp.game.viewer, gui.Anchor{0.5, 0.5, 0.5, 0.5})
	gp.AnchorBox.AddChild(MakeOverlay(gp.game), gui.Anchor{0.5, 0.5, 0.5, 0.5})
}
Exemplo n.º 2
0
func doExec(gp *GamePanel) lua.GoFunction {
	return func(L *lua.State) int {
		if !LuaCheckParamsOk(L, "DoExec", LuaTable) {
			return 0
		}
		L.PushString("__encoded")
		L.GetTable(-2)
		str := L.ToString(-1)
		L.Pop(1)
		var execs []ActionExec
		base.Log().Printf("Decoding from: '%s'", str)
		err := base.FromBase64FromGob(&execs, str)
		if err != nil {
			base.Error().Printf("Error decoding exec: %v", err)
			return 0
		}
		if len(execs) != 1 {
			base.Error().Printf("Error decoding exec: Found %d execs instead of exactly 1.", len(execs))
			return 0
		}
		base.Log().Printf("ScriptComm: Exec: %v", execs[0])
		gp.game.comm.script_to_game <- execs[0]
		base.Log().Printf("ScriptComm: Sent exec")
		<-gp.game.comm.game_to_script
		base.Log().Printf("ScriptComm: exec done")
		done := make(chan bool)
		gp.script.syncStart()
		go func() {
			for i := range gp.game.Ents {
				gp.game.Ents[i].Sprite().Wait([]string{"ready", "killed"})
			}
			done <- true
		}()
		gp.script.syncEnd()
		<-done
		return 0
	}
}