Esempio n. 1
0
func GeneratorsTab(c dom.Element) {
	go func() {
		xjs.RemoveChildren(c)
		gs, err := RPC.Generators()
		if err != nil {
			xjs.Alert("Error getting generator list: %s", err)
			return
		}
		ng := xdom.Button()
		xjs.SetInnerText(ng, "New Generator")
		ng.AddEventListener("click", false, func(dom.Event) {
			d := xdom.Div()
			o := overlay.New(d)
			o.OnClose(func() {
				GeneratorsTab(c)
			})
			d.AppendChild(transferFile("Map", "Upload/Download", 3, o))
			xjs.Body().AppendChild(o)
		})
		table := xjs.AppendChildren(xdom.Table(), xjs.AppendChildren(xdom.Tr(), xjs.SetInnerText(xdom.Th(), "Generator")))
		if len(gs) == 0 {
			table.AppendChild(xjs.AppendChildren(xdom.Tr(), xjs.SetInnerText(xdom.Td(), "No Generators")))
		} else {
			for _, g := range gs {
				td := xdom.Td()
				td.AddEventListener("click", false, func(g data.Generator) func(dom.Event) {
					return func(dom.Event) {
						d := xdom.Div()
						o := overlay.New(d)
						o.OnClose(func() {
							GeneratorsTab(c)
						})
						d.AppendChild(tabs.New([]tabs.Tab{
							{"Profile", generatorProfile(g.ID)},
							{"Misc", misc("generator", g.ID, o, RPC.RemoveGenerator)},
						}))
						xjs.Body().AppendChild(o)
					}
				}(g))
				table.AppendChild(xjs.AppendChildren(xdom.Tr(), xjs.SetInnerText(td, g.Name)))
			}
		}
		xjs.AppendChildren(c,
			xjs.SetInnerText(xdom.H2(), "Generators"),
			ng,
			table,
		)
	}()
}
Esempio n. 2
0
func generatorProfile(id int) func(dom.Element) {
	var d dom.Node
	return func(c dom.Element) {
		if d == nil {
			g, err := RPC.Generator(id)
			if err != nil {
				xjs.Alert("Error while getting generator settings: %s", err)
				return
			}
			tTable := xjs.AppendChildren(xdom.Table(), xjs.AppendChildren(xdom.Thead(), xjs.AppendChildren(xdom.Tr(),
				xjs.SetInnerText(xdom.Th(), "Colour"),
				xjs.SetInnerText(xdom.Th(), "Colour Code"),
				xjs.SetInnerText(xdom.Th(), "Name"),
			)))
			for _, t := range g.Terrain {
				colour := xdom.Td()
				cc := fmt.Sprintf("rgb(%d, %d, %d)", t.Colour.R, t.Colour.G, t.Colour.B)
				colour.Style().SetProperty("background-color", cc, "")
				colour.Style().SetProperty("border", "1px solid #000", "")
				tTable.AppendChild(xjs.AppendChildren(xdom.Tr(),
					colour,
					xjs.SetInnerText(xdom.Td(), cc),
					xjs.SetInnerText(xdom.Td(), t.Name),
				))
			}
			bTable := xjs.AppendChildren(xdom.Table(), xjs.AppendChildren(xdom.Thead(), xjs.AppendChildren(xdom.Tr(),
				xjs.SetInnerText(xdom.Th(), "Colour"),
				xjs.SetInnerText(xdom.Th(), "Colour Code"),
				xjs.SetInnerText(xdom.Th(), "Name"),
			)))
			for _, b := range g.Biomes {
				colour := xdom.Td()
				cc := fmt.Sprintf("rgb(%d, %d, %d)", b.Colour.R, b.Colour.G, b.Colour.B)
				colour.Style().SetProperty("background-color", cc, "")
				colour.Style().SetProperty("border", "1px solid #000", "")
				bTable.AppendChild(xjs.AppendChildren(xdom.Tr(),
					colour,
					xjs.SetInnerText(xdom.Td(), cc),
					xjs.SetInnerText(xdom.Td(), b.Name),
				))
			}
			pTable := xjs.AppendChildren(xdom.Table(), xjs.AppendChildren(xdom.Thead(), xjs.AppendChildren(xdom.Tr(),
				xjs.SetInnerText(xdom.Th(), "Colour"),
				xjs.SetInnerText(xdom.Th(), "Colour Code"),
				xjs.SetInnerText(xdom.Th(), "Name"),
			)))
			for _, p := range g.Plants {
				colour := xdom.Td()
				cc := fmt.Sprintf("rgb(%d, %d, %d)", p.Colour.R, p.Colour.G, p.Colour.B)
				colour.Style().SetProperty("background-color", cc, "")
				colour.Style().SetProperty("border", "1px solid #000", "")
				pTable.AppendChild(xjs.AppendChildren(xdom.Tr(),
					colour,
					xjs.SetInnerText(xdom.Td(), cc),
					xjs.SetInnerText(xdom.Td(), p.Name),
				))
			}
			d = xjs.AppendChildren(xdom.Div(),
				xjs.SetInnerText(xdom.H2(), "Terrain"),
				tTable,
				xjs.SetInnerText(xdom.H2(), "Biomes"),
				bTable,
				xjs.SetInnerText(xdom.H2(), "Plants"),
				pTable,
			)
		}
		c.AppendChild(d)
	}
}
Esempio n. 3
0
func ServersTab() func(dom.Element) {
	forceUpdate := make(chan struct{})
	ns := xdom.Button()
	ns.AddEventListener("click", false, func(dom.Event) {
		d := xdom.Div()
		o := overlay.New(d)
		d.AppendChild(transferFile("Server", "Upload/Download", 0, o))
		o.OnClose(func() {
			go func() {
				forceUpdate <- struct{}{}
			}()
		})
		xjs.Body().AppendChild(o)
	})
	noneTd := xdom.Td()
	noneTd.ColSpan = 3
	none := xjs.AppendChildren(xdom.Tr(), xjs.SetInnerText(noneTd, "No Servers Found"))
	serverList := xjs.AppendChildren(xdom.Table(),
		xjs.AppendChildren(xdom.Thead(), xjs.AppendChildren(xdom.Tr(),
			xjs.SetInnerText(xdom.Th(), "Server Name"),
			xjs.SetInnerText(xdom.Th(), "Status"),
			xjs.SetInnerText(xdom.Th(), "Controls"),
		)),
		none,
	)
	nodes := xjs.AppendChildren(xdom.Div(),
		xjs.SetInnerText(xdom.H2(), "Servers"),
		xjs.SetInnerText(ns, "New Server"),
		serverList,
	)
	servers := make(map[int]*Server)

	return func(c dom.Element) {
		c.AppendChild(nodes)
		updateStop := make(chan struct{})
		registerUpdateStopper(c, updateStop)
		for {
			servs, err := RPC.ServerList()
			if err != nil {
				xjs.Alert("Error getting server list: %s", err)
				return
			}

			if none.ParentNode() != nil {
				serverList.RemoveChild(none)
			}

			for _, s := range servers {
				s.ID = -1
			}

			for _, s := range servs {
				os, ok := servers[s.ID]
				if ok {
					os.Server = s
				} else {
					name := xdom.Td()
					status := xdom.Td()
					startStop := xdom.Button()
					os = &Server{
						Server: s,
						row: xjs.AppendChildren(xdom.Tr(),
							name,
							status,
							xjs.AppendChildren(xdom.Td(), startStop),
						),
						name:   name,
						status: status,
						button: startStop,
					}
					servers[s.ID] = os
					serverList.AppendChild(os.row)
					name.Class().SetString("serverName")
					name.AddEventListener("click", false, func() func(dom.Event) {
						s := os
						return func(dom.Event) {
							go func() {
								d, err := RPC.ServerEULA(s.ID)
								if err != nil {
									d = ""
								}
								t := []tabs.Tab{
									{"General", serverGeneral(s.Server)},
									{"Properties", serverProperties(s.Server)},
									{"Console", serverConsole(s.Server)},
								}
								if d != "" {
									t = append(t, tabs.Tab{"EULA", serverEULA(s.Server, d)})
								}
								div := xdom.Div()
								o := overlay.New(div)
								t = append(t, tabs.Tab{"Misc.", misc("server", s.Server.ID, o, RPC.RemoveServer)})
								div.AppendChild(tabs.New(t))
								o.OnClose(func() {
									go func() {
										forceUpdate <- struct{}{}
									}()
								})
								xjs.Body().AppendChild(o)
							}()

						}
					}())
					startStop.AddEventListener("click", false, func() func(dom.Event) {
						b := startStop
						s := os
						return func(dom.Event) {
							go func() {
								b.Disabled = true
								switch s.State {
								case data.StateStopped:
									err := RPC.StartServer(s.ID)
									if err != nil {
										xjs.Alert("Error starting server: %s", err)
										return
									}
								case data.StateRunning:
									err := RPC.StopServer(s.ID)
									if err != nil {
										xjs.Alert("Error stopping server: %s", err)
										return
									}
								default:
									return
								}
								go func() {
									forceUpdate <- struct{}{}
								}()
							}()
						}
					}())
				}
				if os.Map >= 0 {
					xjs.SetInnerText(os.status, os.State.String())
					switch os.State {
					case data.StateStopped:
						xjs.SetInnerText(os.button, "Start")
						os.button.Disabled = false
					case data.StateRunning:
						xjs.SetInnerText(os.button, "Stop")
						os.button.Disabled = false
					default:
						xjs.SetInnerText(os.button, "N/A")
						os.button.Disabled = true
					}
				} else {
					xjs.SetInnerText(os.status, "No Map")
					os.button.Disabled = true
					xjs.SetInnerText(os.button, "N/A")
				}
				xjs.SetInnerText(os.name, os.Name)
			}

			for id, s := range servers {
				if s.ID == -1 {
					delete(servers, id)
					serverList.RemoveChild(s.row)
				}
			}

			if len(servers) == 0 {
				serverList.AppendChild(none)
			}

			// Sleep until update
			if !updateSleep(forceUpdate, updateStop) {
				return
			}
		}
	}
}
Esempio n. 4
0
func MapsTab() func(dom.Element) {
	forceUpdate := make(chan struct{})
	nm := xdom.Button()
	nm.AddEventListener("click", false, func(dom.Event) {
		d := xdom.Div()
		o := overlay.New(d)
		o.OnClose(func() {
			go func() {
				forceUpdate <- struct{}{}
			}()
		})
		xjs.AppendChildren(d,
			xjs.SetInnerText(xdom.H1(), "New Map"),
			tabs.New([]tabs.Tab{
				{"Create", createMap(o)},
				{"Upload/Download", func(c dom.Element) {
					c.AppendChild(transferFile("Map", "Upload/Download", 1, o))
				}},
				{"Generate", func(c dom.Element) {
					c.AppendChild(transferFile("Map", "Generate", 2, o))
				}},
			}),
		)
		xjs.Body().AppendChild(o)
	})
	noneTd := xdom.Td()
	noneTd.ColSpan = 2
	none := xjs.AppendChildren(xdom.Tr(), xjs.SetInnerText(noneTd, "No Maps Found"))
	mapList := xjs.AppendChildren(xdom.Table(),
		xjs.AppendChildren(xdom.Thead(), xjs.AppendChildren(xdom.Tr(),
			xjs.SetInnerText(xdom.Th(), "Map Name"),
			xjs.SetInnerText(xdom.Th(), "Status"),
		)),
		none,
	)
	nodes := xjs.AppendChildren(xdom.Div(),
		xjs.SetInnerText(xdom.H2(), "Maps"),
		xjs.SetInnerText(nm, "New Map"),
		mapList,
	)

	maps := make(map[int]*Map)
	return func(c dom.Element) {
		c.AppendChild(nodes)
		updateStop := make(chan struct{})
		registerUpdateStopper(c, updateStop)
		for {
			mps, err := RPC.MapList()
			if err != nil {
				xjs.Alert("Error getting map list: %s", err)
				return
			}

			if none.ParentNode() != nil {
				mapList.RemoveChild(none)
			}

			for _, m := range maps {
				m.ID = -1
			}

			for _, m := range mps {
				om, ok := maps[m.ID]
				if ok {
					om.Map = m
				} else {
					name := xdom.Td()
					status := xdom.Td()
					om = &Map{
						Map: m,
						row: xjs.AppendChildren(xdom.Tr(),
							name,
							status,
						),
						name:   name,
						status: status,
					}
					maps[m.ID] = om
					mapList.AppendChild(om.row)
					name.Class().SetString("mapName")
					name.AddEventListener("click", false, func() func(dom.Event) {
						m := om
						return func(dom.Event) {
							div := xdom.Div()
							o := overlay.New(div)
							div.AppendChild(tabs.New([]tabs.Tab{
								{"General", mapGeneral(m.Map)},
								{"Properties", mapProperties(m.Map)},
								{"Misc.", misc("map", m.Map.ID, o, RPC.RemoveMap)},
							}))
							o.OnClose(func() {
								go func() {
									forceUpdate <- struct{}{}
								}()
							})
							xjs.Body().AppendChild(o)
						}
					}())
				}
				switch om.Server {
				case -2:
					xjs.SetInnerText(om.status, "Busy")
					om.status.Style().SetProperty("color", "#f00", "")
				case -1:
					xjs.SetInnerText(om.status, "Unassigned")
					om.status.Style().SetProperty("color", "#00f", "")
				default:
					serv, err := RPC.Server(om.Server)
					if err == nil {
						xjs.SetInnerText(om.status, "Assigned")
					} else {
						xjs.SetInnerText(om.status, "Assigned - "+serv.Name)
					}
					om.status.Style().SetProperty("color", "#000", "")
				}
				xjs.SetInnerText(om.name, om.Name)
			}

			for id, m := range maps {
				if m.ID == -1 {
					delete(maps, id)
					mapList.RemoveChild(m.row)
				}
			}

			if len(maps) == 0 {
				mapList.AppendChild(none)
			}

			// Sleep until update
			if !updateSleep(forceUpdate, updateStop) {
				return
			}
		}
	}
}