placing tiles kinda works now
This commit is contained in:
parent
25acc57024
commit
c65f7a994c
Binary file not shown.
|
@ -20,9 +20,12 @@ StateServer="*res://native/StateServer.tscn"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/size/width=1920
|
|
||||||
window/size/height=1080
|
|
||||||
window/dpi/allow_hidpi=true
|
window/dpi/allow_hidpi=true
|
||||||
|
window/stretch/aspect="expand"
|
||||||
|
|
||||||
|
[global]
|
||||||
|
|
||||||
|
window=false
|
||||||
|
|
||||||
[importer_defaults]
|
[importer_defaults]
|
||||||
|
|
||||||
|
@ -72,14 +75,39 @@ camera_down={
|
||||||
}
|
}
|
||||||
zoom_in={
|
zoom_in={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":61,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":61,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
zoom_out={
|
zoom_out={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"pressed":false,"doubleclick":false,"script":null)
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":45,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":45,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
]
|
||||||
|
}
|
||||||
|
tool_1={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":49,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":49,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
tool_2={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":50,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":50,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
use_tool={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
height_up={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":82,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
height_down={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":70,"unicode":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ process_priority = 124
|
||||||
mode = 1
|
mode = 1
|
||||||
tile_set = ExtResource( 1 )
|
tile_set = ExtResource( 1 )
|
||||||
cell_size = Vector2( 32, 16 )
|
cell_size = Vector2( 32, 16 )
|
||||||
centered_textures = true
|
cell_tile_origin = 1
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
collision_mask = 0
|
collision_mask = 0
|
||||||
format = 1
|
format = 1
|
||||||
|
|
|
@ -1,12 +1,33 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
enum TOOLS {PLACE}
|
||||||
|
|
||||||
|
var active_tool = TOOLS.PLACE
|
||||||
|
var active_height: int = 0
|
||||||
var Tilemap = preload("res://world/Tilemap.tscn")
|
var Tilemap = preload("res://world/Tilemap.tscn")
|
||||||
var tilemaps = []
|
var tilemaps: Array = []
|
||||||
|
|
||||||
|
func _process(_delta):
|
||||||
|
if Input.is_action_just_pressed("use_tool"):
|
||||||
|
use_tool_on_active_tile()
|
||||||
|
if Input.is_action_just_pressed("tool_1"):
|
||||||
|
switch_to_action(TOOLS.PLACE)
|
||||||
|
if Input.is_action_just_pressed("height_down"):
|
||||||
|
change_height(-1)
|
||||||
|
elif Input.is_action_just_pressed("height_up"):
|
||||||
|
change_height(1)
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
StateServer.connect("changed_tiletypes", self, "_on_StateServer_changed_tiletypes")
|
StateServer.connect("changed_tiletypes", self, "_on_StateServer_changed_tiletypes")
|
||||||
StateServer.connect("request_init", self, "_on_StateServer_request_init")
|
StateServer.connect("request_init", self, "_on_StateServer_request_init")
|
||||||
|
|
||||||
|
func change_height(v: int):
|
||||||
|
active_height = int(clamp(active_height + v, 0, tilemaps.size() - 1))
|
||||||
|
for i in range(0, tilemaps.size()):
|
||||||
|
if i > active_height:
|
||||||
|
tilemaps[i].modulate.a = 0.12
|
||||||
|
else: tilemaps[i].modulate.a = 1
|
||||||
|
|
||||||
func respawn_tilemaps():
|
func respawn_tilemaps():
|
||||||
tilemaps = []
|
tilemaps = []
|
||||||
for i in range(0, StateServer.get_world_size().z):
|
for i in range(0, StateServer.get_world_size().z):
|
||||||
|
@ -15,6 +36,7 @@ func respawn_tilemaps():
|
||||||
map.z_index = i
|
map.z_index = i
|
||||||
add_child(map)
|
add_child(map)
|
||||||
tilemaps.push_back(map)
|
tilemaps.push_back(map)
|
||||||
|
change_height(0)
|
||||||
|
|
||||||
func get_tile_at(pos: Vector3) -> String:
|
func get_tile_at(pos: Vector3) -> String:
|
||||||
return StateServer.get_tile_at(int(pos.x), int(pos.y), int(pos.z))
|
return StateServer.get_tile_at(int(pos.x), int(pos.y), int(pos.z))
|
||||||
|
@ -26,8 +48,22 @@ func update_tiles(tile_positions: PoolVector3Array):
|
||||||
for map in tilemaps:
|
for map in tilemaps:
|
||||||
map.update_dirty_quadrants()
|
map.update_dirty_quadrants()
|
||||||
|
|
||||||
|
func switch_to_action(action):
|
||||||
|
if action == TOOLS.PLACE:
|
||||||
|
active_tool = TOOLS.PLACE
|
||||||
|
print(action)
|
||||||
|
|
||||||
|
func get_mouseover_tile() -> Vector2:
|
||||||
|
var mouse_pos = tilemaps[active_height].get_local_mouse_position()
|
||||||
|
return tilemaps[active_height].world_to_map(mouse_pos)
|
||||||
|
|
||||||
|
func use_tool_on_active_tile():
|
||||||
|
var tile = get_mouseover_tile()
|
||||||
|
StateServer.put_tile_at(int(tile.x), int(tile.y), active_height, 1)
|
||||||
|
|
||||||
func _on_StateServer_request_init():
|
func _on_StateServer_request_init():
|
||||||
call_deferred("respawn_tilemaps")
|
call_deferred("respawn_tilemaps")
|
||||||
|
|
||||||
func _on_StateServer_changed_tiletypes(tile_positions: PoolVector3Array):
|
func _on_StateServer_changed_tiletypes(tile_positions: PoolVector3Array):
|
||||||
call_deferred("update_tiles", tile_positions)
|
call_deferred("update_tiles", tile_positions)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,2 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
enum ACTIVE {PLACE}
|
|
||||||
|
|
||||||
func _process(_delta):
|
|
||||||
pass
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://world/StateApi.gd" type="Script" id=1]
|
[ext_resource path="res://world/StateApi.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://world/Cam.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://world/Cam.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://world/Tools.gd" type="Script" id=3]
|
|
||||||
[ext_resource path="res://world/Tilemaps.gd" type="Script" id=4]
|
[ext_resource path="res://world/Tilemaps.gd" type="Script" id=4]
|
||||||
|
|
||||||
[node name="World" type="Node"]
|
[node name="World" type="Node"]
|
||||||
|
@ -10,8 +9,5 @@ script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="Worldcam" parent="." instance=ExtResource( 2 )]
|
[node name="Worldcam" parent="." instance=ExtResource( 2 )]
|
||||||
|
|
||||||
[node name="Tilemaps" type="Node" parent="."]
|
[node name="Tilemaps" type="Node2D" parent="."]
|
||||||
script = ExtResource( 4 )
|
script = ExtResource( 4 )
|
||||||
|
|
||||||
[node name="Tools" type="Node2D" parent="Tilemaps"]
|
|
||||||
script = ExtResource( 3 )
|
|
||||||
|
|
|
@ -59,9 +59,9 @@ impl StateServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[export]
|
||||||
fn put_tile_at(&mut self, _owner: &Node, x: usize, y: usize, z: usize, id: usize) -> bool{
|
fn put_tile_at(&mut self, _owner: &Node, x: usize, y: usize, z: usize, id: usize) {
|
||||||
let success = self.world.put_tile_at(x, y, z, id);
|
let changed = self.world.put_tile_at(x, y, z, id);
|
||||||
success
|
_owner.emit_signal("changed_tiletypes", &[Variant::new(&changed)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,12 +90,17 @@ impl World {
|
||||||
positions
|
positions
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put_tile_at(&mut self, x: usize, y: usize, z: usize, id: usize) -> bool{
|
pub fn put_tile_at(&mut self, x: usize, y: usize, z: usize, id: usize) -> Vector3Array {
|
||||||
|
let mut changed = Vector3Array::new();
|
||||||
|
|
||||||
if !self.can_put_tile_at(x, y, z, id) {
|
if !self.can_put_tile_at(x, y, z, id) {
|
||||||
return false;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.tiles[x][y][z] = tiles::Tiletypes::from_repr(id as u8).unwrap();
|
self.tiles[x][y][z] = tiles::Tiletypes::from_repr(id as u8).unwrap();
|
||||||
true
|
changed.push(Vector3::new(x as f32, y as f32, z as f32));
|
||||||
|
|
||||||
|
changed
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn can_put_tile_at(&self, x: usize, y: usize, z: usize, id: usize) -> bool {
|
pub fn can_put_tile_at(&self, x: usize, y: usize, z: usize, id: usize) -> bool {
|
||||||
|
@ -105,7 +110,6 @@ impl World {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn new(xsize: usize, ysize: usize, zsize: usize) -> World {
|
pub fn new(xsize: usize, ysize: usize, zsize: usize) -> World {
|
||||||
World {
|
World {
|
||||||
xsize,
|
xsize,
|
||||||
|
|
Loading…
Reference in New Issue