mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-04-05 09:56:53 +00:00
added help and function for get pods name
This commit is contained in:
@@ -30,6 +30,18 @@ key_trigger {
|
||||
input: KEY_N
|
||||
action: "namespace"
|
||||
}
|
||||
key_trigger {
|
||||
input: KEY_I
|
||||
action: "infopod"
|
||||
}
|
||||
key_trigger {
|
||||
input: KEY_H
|
||||
action: "help"
|
||||
}
|
||||
key_trigger {
|
||||
input: KEY_Q
|
||||
action: "quit_help"
|
||||
}
|
||||
mouse_trigger {
|
||||
input: MOUSE_BUTTON_1
|
||||
action: "click"
|
||||
|
||||
@@ -22,7 +22,7 @@ function on_message(self, message_id, message, sender)
|
||||
if value["color"] == "white" and value["id"] == message["other_id"] then
|
||||
old_pos = go.get_position(value["id"])
|
||||
print ("on_message] position of pod to be deleted is " .. old_pos)
|
||||
current_pods[i] = { id = value["id"] , color = "red", collision = true, old_position = old_pos}
|
||||
current_pods[i] = { id = value["id"] , color = "red", collision = true, old_position = old_pos, pod_name = value["pod_name"] }
|
||||
go.delete(value["id"])
|
||||
end
|
||||
end
|
||||
|
||||
189
main/gui.gui
189
main/gui.gui
@@ -335,6 +335,195 @@ nodes {
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: ""
|
||||
font: "info"
|
||||
id: "pod_name"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
outline {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: false
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
template_node_child: false
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: -161.0
|
||||
y: 782.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 800.0
|
||||
y: 900.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "Special Keys:\n"
|
||||
"i: Show pod\'s name. Move the ship towards an alien\n"
|
||||
"n: Jump between namespaces. Read REAME.md for configuring TARGET_NAMESPACE\n"
|
||||
"q: Hide this special keys list"
|
||||
font: "info"
|
||||
id: "inputs"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_W
|
||||
outline {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: true
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
template_node_child: false
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 1110.0
|
||||
y: 688.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "Press \'h\' for special keys list"
|
||||
font: "info"
|
||||
id: "text"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
outline {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: false
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
template_node_child: false
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
material: "/builtins/materials/gui.material"
|
||||
adjust_reference: ADJUST_REFERENCE_PARENT
|
||||
max_nodes: 512
|
||||
|
||||
@@ -22,7 +22,26 @@ function on_message(self, message_id, message, sender)
|
||||
elseif message_id == hash("error") then
|
||||
gui.set_text(gui.get_node("error"), message.errormessage)
|
||||
elseif message_id == hash("mode") then
|
||||
gui.set_text(gui.get_node("mode"), message.mode)
|
||||
gui.set_text(gui.get_node("mode"), message.mode)
|
||||
elseif message_id == hash("help") then
|
||||
gui.set_position(gui.get_node("inputs"), message.position)
|
||||
elseif message_id == hash("quit_help") then
|
||||
gui.set_position(gui.get_node("inputs"), message.position)
|
||||
|
||||
elseif message_id == hash("pod_name") then
|
||||
if message.pod_name == false or message.pod_name == nil then
|
||||
fake_position = message.position
|
||||
fake_position.x = 0
|
||||
fake_position.y = 0
|
||||
gui.set_text(gui.get_node("pod_name"),'')
|
||||
gui.set_position(gui.get_node("pod_name"), fake_position)
|
||||
else
|
||||
gui.set_text(gui.get_node("pod_name"), message.pod_name)
|
||||
print(message.position_of_pod)
|
||||
new_position = message.position
|
||||
new_position.y = message.position.y - 25
|
||||
gui.set_position(gui.get_node("pod_name"), new_position)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -180,6 +180,60 @@ embedded_instances {
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"embedded_components {\n"
|
||||
" id: \"label\"\n"
|
||||
" type: \"label\"\n"
|
||||
" data: \"size {\\n"
|
||||
" x: 128.0\\n"
|
||||
" y: 32.0\\n"
|
||||
" z: 0.0\\n"
|
||||
" w: 0.0\\n"
|
||||
"}\\n"
|
||||
"scale {\\n"
|
||||
" x: 1.0\\n"
|
||||
" y: 1.0\\n"
|
||||
" z: 1.0\\n"
|
||||
" w: 0.0\\n"
|
||||
"}\\n"
|
||||
"color {\\n"
|
||||
" x: 1.0\\n"
|
||||
" y: 1.0\\n"
|
||||
" z: 1.0\\n"
|
||||
" w: 1.0\\n"
|
||||
"}\\n"
|
||||
"outline {\\n"
|
||||
" x: 0.0\\n"
|
||||
" y: 0.0\\n"
|
||||
" z: 0.0\\n"
|
||||
" w: 1.0\\n"
|
||||
"}\\n"
|
||||
"shadow {\\n"
|
||||
" x: 0.0\\n"
|
||||
" y: 0.0\\n"
|
||||
" z: 0.0\\n"
|
||||
" w: 1.0\\n"
|
||||
"}\\n"
|
||||
"leading: 1.0\\n"
|
||||
"tracking: 0.0\\n"
|
||||
"pivot: PIVOT_CENTER\\n"
|
||||
"blend_mode: BLEND_MODE_ALPHA\\n"
|
||||
"line_break: false\\n"
|
||||
"text: \\\"Label\\\"\\n"
|
||||
"font: \\\"/builtins/fonts/system_font.font\\\"\\n"
|
||||
"material: \\\"/builtins/fonts/label.material\\\"\\n"
|
||||
"\"\n"
|
||||
" position {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" }\n"
|
||||
" rotation {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
""
|
||||
position {
|
||||
x: 0.0
|
||||
|
||||
@@ -10,6 +10,13 @@ automatic = false
|
||||
last_namespace_change = false
|
||||
local timer = require ("main.timer")
|
||||
|
||||
function get_help()
|
||||
msg.post("ui#gui","help",{ position = vmath.vector3(24, 680, 0) })
|
||||
end
|
||||
|
||||
function quit_help()
|
||||
msg.post("ui#gui","quit_help",{ position = vmath.vector3(-160, 800, 0) })
|
||||
end
|
||||
function reverse(tbl)
|
||||
for i=1, math.floor(#tbl / 2) do
|
||||
local tmp = tbl[i]
|
||||
@@ -18,6 +25,25 @@ function reverse(tbl)
|
||||
end
|
||||
end
|
||||
|
||||
function print_pod_name()
|
||||
pos = go.get_position()
|
||||
message_pod_name = {}
|
||||
pod_name = ""
|
||||
for i,value in ipairs(current_pods) do
|
||||
position_of_pod = go.get_position(value["id"])
|
||||
if (pos.x > position_of_pod.x and pos.x - position_of_pod.x < 25) or (position_of_pod.x > pos.x and position_of_pod.x - pos.x < 25) then
|
||||
pod_name = pod_name .. " " .. value["pod_name"]
|
||||
last_pod_position = position_of_pod
|
||||
end
|
||||
end
|
||||
if pod_name ~= "" then
|
||||
if pod_name:match("[%a%d%p_]%s[%a%d%p_]") ~= nil then
|
||||
pod_name = pod_name:gsub(" ", "\n")
|
||||
end
|
||||
msg.post("ui#gui","pod_name",{ pod_name = pod_name, position = last_pod_position })
|
||||
end
|
||||
end
|
||||
|
||||
function swap_pod(items)
|
||||
|
||||
for i,value in ipairs(current_pods) do
|
||||
@@ -25,7 +51,8 @@ function swap_pod(items)
|
||||
current_pods[i]["id"] = factory.create("/pod_not_running#podfactory", value["old_position"])
|
||||
current_pods[i]["color"] = "red"
|
||||
current_pods[i]["collision"] = false
|
||||
delete_request_pod()
|
||||
--delete_request_pod()
|
||||
delete_pod(value["pod_name"])
|
||||
return
|
||||
end
|
||||
end
|
||||
@@ -35,8 +62,8 @@ function swap_pod(items)
|
||||
|
||||
kubernetes_pod_not_running = 0 -- Pods not running in Kubernetes
|
||||
kubernetes_pod_running = 0 -- Pods running in Kubernetes
|
||||
global_kubernetes_pod_size = table.getn(items) -- All pods in Kubernetes
|
||||
global_kubeinvaders_pod_size = table.getn(current_pods) -- All pods in Kubeinvaders
|
||||
global_kubernetes_pod_size = table.getn(items) -- All pods in Kubernetes
|
||||
global_kubeinvaders_pod_size = table.getn(current_pods) -- All pods in Kubeinvaders
|
||||
|
||||
for i,value in ipairs(items) do
|
||||
if value['status']['phase'] ~= "Running" or value['metadata']['deletionTimestamp'] ~= nil then
|
||||
@@ -168,7 +195,7 @@ function update_pod()
|
||||
end
|
||||
|
||||
function delete_pod(pod_name)
|
||||
print "[delete_pod] delete pods of Kubernetes"
|
||||
print ("[delete_pod] delete pods " .. pod_name .. " in Kubernetes")
|
||||
http.request(endpoint .. "/api/v1/namespaces/" .. namespace .. "/pods/" .. pod_name, "DELETE", http_pod_delete_result,headers)
|
||||
end
|
||||
|
||||
@@ -251,11 +278,11 @@ function http_pod_result(self, _, response)
|
||||
pos.y = y_pos
|
||||
if phase == "Running" and this_pod['metadata']['deletionTimestamp'] == nil then
|
||||
local pod = factory.create("/pod#podfactory", pos)
|
||||
table.insert(current_pods, { id = pod , color = "white" })
|
||||
table.insert(current_pods, { id = pod , color = "white", pod_name = this_pod['metadata']['name'] })
|
||||
check_current_pods = true
|
||||
else
|
||||
local pod = factory.create("/pod_not_running#podfactory", pos)
|
||||
table.insert(current_pods, { id = pod , color = "red" })
|
||||
table.insert(current_pods, { id = pod , color = "red", pod_name = this_pod['metadata']['name'] })
|
||||
check_current_pods = true
|
||||
end
|
||||
end
|
||||
@@ -314,6 +341,9 @@ function init(self)
|
||||
}
|
||||
timer.repeat_seconds(0.3, function()
|
||||
update_pod()
|
||||
end)
|
||||
timer.repeat_seconds(1, function()
|
||||
msg.post("ui#gui","pod_name",{ pod_name = false, position = go.get_position()})
|
||||
end)
|
||||
timer.repeat_seconds(1, function()
|
||||
ai()
|
||||
@@ -322,8 +352,6 @@ function init(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function update(self, dt)
|
||||
timer.update(dt)
|
||||
end
|
||||
@@ -345,15 +373,20 @@ function on_input(self, action_id, action)
|
||||
local p = go.get_position()
|
||||
p.x = p.x + 4
|
||||
go.set_position(p)
|
||||
elseif action_id == hash("infopod") then
|
||||
print_pod_name()
|
||||
elseif action_id == hash("help") then
|
||||
print "help!"
|
||||
get_help()
|
||||
elseif action_id == hash("quit_help") then
|
||||
quit_help()
|
||||
elseif action_id == hash("automatic") then
|
||||
automatic = true
|
||||
msg.post("ui#gui", "mode",{ mode = "You are using the automatic mode. Press \"m\" to use switch to manual"})
|
||||
|
||||
elseif action_id == hash("manual") then
|
||||
print ("[change_mode] manual")
|
||||
automatic = false
|
||||
msg.post("ui#gui", "mode",{ mode = "You are using the manual mode. Press \"a\" to use switch to automatic"})
|
||||
|
||||
elseif action_id == hash("namespace") then
|
||||
print ("[change_namespace] change namespaces requested by user")
|
||||
msg.post("ui#gui", "error",{ errormessage = "changing namespace!" })
|
||||
|
||||
Reference in New Issue
Block a user