Skip to content

Commit 52f3010

Browse files
author
Marco Bakera
committed
moving map into separate scene.
1 parent 9fa0e24 commit 52f3010

File tree

5 files changed

+95
-102
lines changed

5 files changed

+95
-102
lines changed

godot_emu/Main.gd

+3-66
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,11 @@
11
extends Node2D
22

3-
var width
4-
var height
5-
var tilemap
6-
var server
7-
8-
const PORT = 10101
9-
10-
const YELLOW = 49 # ascii 1
113

124
# Called when the node enters the scene tree for the first time.
135
func _ready():
14-
tilemap = get_node("TileMap")
15-
update_width_height()
16-
clear_display()
17-
18-
print("listening on port ", PORT)
19-
server = TCP_Server.new()
20-
server.listen(PORT)
6+
pass # Replace with function body.
217

22-
func clear_display():
23-
for x in range(width):
24-
for y in range(height):
25-
tilemap.set_cell(x, y, 0)
268

279
# Called every frame. 'delta' is the elapsed time since the previous frame.
28-
func _process(delta):
29-
if server.is_connection_available():
30-
print("conn available")
31-
var conn = server.take_connection()
32-
print("bytes available ", conn.get_available_bytes())
33-
var bs = conn.get_data(conn.get_available_bytes())
34-
print("bytes ", bs, len(bs))
35-
process_bytes(bs[1])
36-
37-
38-
func process_bytes(bytes):
39-
var x = 0
40-
var y = 0
41-
42-
for b in bytes:
43-
print("byte ", b)
44-
print("xy ", x, " ", y)
45-
46-
tilemap.set_cell(x, y, b == YELLOW)
47-
48-
x += 1
49-
if x >= width:
50-
x = 0
51-
y += 1
52-
53-
func _on_Button_pressed():
54-
var cell
55-
for x in range(4):
56-
cell = tilemap.get_cell(x, 0)
57-
print("x ", x, " cell ", cell,
58-
" type ", typeof(tilemap), " invalid ", cell == TileMap.INVALID_CELL)
59-
tilemap.set_cell(x, 2, cell)
60-
61-
func _on_teWidth_text_changed():
62-
update_width_height()
63-
64-
func _on_teHeight_text_changed():
65-
update_width_height()
66-
67-
func update_width_height():
68-
print("updating width and height")
69-
var tHeight = get_node("teHeight").text
70-
height = int(tHeight)
71-
var tWidth = get_node("teWidth").text
72-
width = int(tWidth)
73-
print(width, " ", height)
74-
10+
#func _process(delta):
11+
# pass

godot_emu/Main.tscn

+2-29
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
11
[gd_scene load_steps=3 format=2]
22

33
[ext_resource path="res://Main.gd" type="Script" id=1]
4-
[ext_resource path="res://Main.tres" type="TileSet" id=2]
4+
[ext_resource path="res://Map.tscn" type="PackedScene" id=2]
55

66
[node name="Main" type="Node2D"]
77
script = ExtResource( 1 )
88

9-
[node name="Button" type="Button" parent="."]
10-
margin_left = 6.0
11-
margin_top = 547.0
12-
margin_right = 122.0
13-
margin_bottom = 592.0
14-
15-
[node name="TileMap" type="TileMap" parent="."]
16-
scale = Vector2( 2, 2 )
17-
tile_set = ExtResource( 2 )
18-
cell_size = Vector2( 20, 20 )
19-
format = 1
20-
21-
[node name="teWidth" type="TextEdit" parent="."]
22-
margin_left = 135.0
23-
margin_top = 570.0
24-
margin_right = 165.0
25-
margin_bottom = 590.0
26-
text = "28"
27-
28-
[node name="teHeight" type="TextEdit" parent="."]
29-
margin_left = 187.0
30-
margin_top = 570.0
31-
margin_right = 217.0
32-
margin_bottom = 590.0
33-
text = "13"
34-
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
35-
[connection signal="text_changed" from="teWidth" to="." method="_on_teWidth_text_changed"]
36-
[connection signal="text_changed" from="teHeight" to="." method="_on_teHeight_text_changed"]
9+
[node name="Map" parent="." instance=ExtResource( 2 )]

godot_emu/Map.gd

+66-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,74 @@
11
extends Node2D
22

3-
# Declare member variables here. Examples:
4-
# var a = 2
5-
# var b = "text"
3+
var width
4+
var height
5+
var tilemap
6+
var server
67

8+
const PORT = 10101
9+
10+
const YELLOW = 49 # ascii 1
711

812
# Called when the node enters the scene tree for the first time.
913
func _ready():
10-
pass # Replace with function body.
14+
tilemap = get_node("TileMap")
15+
update_width_height()
16+
clear_display()
17+
18+
print("listening on port ", PORT)
19+
server = TCP_Server.new()
20+
server.listen(PORT)
21+
22+
func clear_display():
23+
for x in range(width):
24+
for y in range(height):
25+
tilemap.set_cell(x, y, 0)
1126

1227
# Called every frame. 'delta' is the elapsed time since the previous frame.
13-
#func _process(delta):
14-
# pass
28+
func _process(delta):
29+
if server.is_connection_available():
30+
print("conn available")
31+
var conn = server.take_connection()
32+
print("bytes available ", conn.get_available_bytes())
33+
var bs = conn.get_data(conn.get_available_bytes())
34+
print("bytes ", bs, len(bs))
35+
process_bytes(bs[1])
36+
37+
38+
func process_bytes(bytes):
39+
var x = 0
40+
var y = 0
41+
42+
for b in bytes:
43+
print("byte ", b)
44+
print("xy ", x, " ", y)
45+
46+
tilemap.set_cell(x, y, b == YELLOW)
47+
48+
x += 1
49+
if x >= width:
50+
x = 0
51+
y += 1
52+
53+
func _on_Button_pressed():
54+
var cell
55+
for x in range(4):
56+
cell = tilemap.get_cell(x, 0)
57+
print("x ", x, " cell ", cell,
58+
" type ", typeof(tilemap), " invalid ", cell == TileMap.INVALID_CELL)
59+
tilemap.set_cell(x, 2, cell)
60+
61+
func _on_teWidth_text_changed():
62+
update_width_height()
63+
64+
func _on_teHeight_text_changed():
65+
update_width_height()
66+
67+
func update_width_height():
68+
print("updating width and height")
69+
var tHeight = get_node("teHeight").text
70+
height = int(tHeight)
71+
var tWidth = get_node("teWidth").text
72+
width = int(tWidth)
73+
print(width, " ", height)
74+
File renamed without changes.

godot_emu/Map.tscn

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
[gd_scene load_steps=3 format=2]
22

33
[ext_resource path="res://Map.gd" type="Script" id=1]
4-
[ext_resource path="res://Main.tres" type="TileSet" id=2]
4+
[ext_resource path="res://Map.tres" type="TileSet" id=2]
55

66
[node name="Map" type="Node2D"]
77
script = ExtResource( 1 )
88

9+
[node name="Button" type="Button" parent="."]
10+
margin_left = 6.0
11+
margin_top = 547.0
12+
margin_right = 122.0
13+
margin_bottom = 592.0
14+
915
[node name="TileMap" type="TileMap" parent="."]
1016
tile_set = ExtResource( 2 )
1117
cell_size = Vector2( 20, 20 )
1218
format = 1
19+
20+
[node name="teWidth" type="TextEdit" parent="."]
21+
margin_left = 135.0
22+
margin_top = 570.0
23+
margin_right = 165.0
24+
margin_bottom = 590.0
25+
text = "28"
26+
27+
[node name="teHeight" type="TextEdit" parent="."]
28+
margin_left = 187.0
29+
margin_top = 570.0
30+
margin_right = 217.0
31+
margin_bottom = 590.0
32+
text = "13"
33+
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
34+
[connection signal="text_changed" from="teWidth" to="." method="_on_teWidth_text_changed"]
35+
[connection signal="text_changed" from="teHeight" to="." method="_on_teHeight_text_changed"]

0 commit comments

Comments
 (0)