diff --git a/godot/native/libroutes_native.so b/godot/native/libroutes_native.so index 66aec21..968aee2 100755 Binary files a/godot/native/libroutes_native.so and b/godot/native/libroutes_native.so differ diff --git a/godot/project.godot b/godot/project.godot index f279bc3..6d606ff 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -20,9 +20,12 @@ StateServer="*res://native/StateServer.tscn" [display] -window/size/width=1920 -window/size/height=1080 window/dpi/allow_hidpi=true +window/stretch/aspect="expand" + +[global] + +window=false [importer_defaults] @@ -72,14 +75,39 @@ camera_down={ } zoom_in={ "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) -, 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) +"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) ] } zoom_out={ "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) -, 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) +"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) + ] +} +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) ] } diff --git a/godot/world/Tilemap.tscn b/godot/world/Tilemap.tscn index 8cfcd6a..3c368f1 100644 --- a/godot/world/Tilemap.tscn +++ b/godot/world/Tilemap.tscn @@ -8,7 +8,7 @@ process_priority = 124 mode = 1 tile_set = ExtResource( 1 ) cell_size = Vector2( 32, 16 ) -centered_textures = true +cell_tile_origin = 1 collision_layer = 0 collision_mask = 0 format = 1 diff --git a/godot/world/Tilemaps.gd b/godot/world/Tilemaps.gd index e529ea1..4bb8ab6 100644 --- a/godot/world/Tilemaps.gd +++ b/godot/world/Tilemaps.gd @@ -1,12 +1,33 @@ extends Node +enum TOOLS {PLACE} + +var active_tool = TOOLS.PLACE +var active_height: int = 0 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(): StateServer.connect("changed_tiletypes", self, "_on_StateServer_changed_tiletypes") 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(): tilemaps = [] for i in range(0, StateServer.get_world_size().z): @@ -15,10 +36,11 @@ func respawn_tilemaps(): map.z_index = i add_child(map) tilemaps.push_back(map) + change_height(0) func get_tile_at(pos: Vector3) -> String: return StateServer.get_tile_at(int(pos.x), int(pos.y), int(pos.z)) - + func update_tiles(tile_positions: PoolVector3Array): for tile in tile_positions: tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y), @@ -26,8 +48,22 @@ func update_tiles(tile_positions: PoolVector3Array): for map in tilemaps: 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(): call_deferred("respawn_tilemaps") func _on_StateServer_changed_tiletypes(tile_positions: PoolVector3Array): call_deferred("update_tiles", tile_positions) + diff --git a/godot/world/Tools.gd b/godot/world/Tools.gd index 0204956..3eb6c96 100644 --- a/godot/world/Tools.gd +++ b/godot/world/Tools.gd @@ -1,6 +1,2 @@ extends Node2D -enum ACTIVE {PLACE} - -func _process(_delta): - pass diff --git a/godot/world/World.tscn b/godot/world/World.tscn index 1e5c5c0..6d5e7b1 100644 --- a/godot/world/World.tscn +++ b/godot/world/World.tscn @@ -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/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] [node name="World" type="Node"] @@ -10,8 +9,5 @@ script = ExtResource( 1 ) [node name="Worldcam" parent="." instance=ExtResource( 2 )] -[node name="Tilemaps" type="Node" parent="."] +[node name="Tilemaps" type="Node2D" parent="."] script = ExtResource( 4 ) - -[node name="Tools" type="Node2D" parent="Tilemaps"] -script = ExtResource( 3 ) diff --git a/routes-native/src/stateserver.rs b/routes-native/src/stateserver.rs index 077a7ee..3e65bcb 100644 --- a/routes-native/src/stateserver.rs +++ b/routes-native/src/stateserver.rs @@ -59,9 +59,9 @@ impl StateServer { } #[export] - fn put_tile_at(&mut self, _owner: &Node, x: usize, y: usize, z: usize, id: usize) -> bool{ - let success = self.world.put_tile_at(x, y, z, id); - success + fn put_tile_at(&mut self, _owner: &Node, x: usize, y: usize, z: usize, id: usize) { + let changed = self.world.put_tile_at(x, y, z, id); + _owner.emit_signal("changed_tiletypes", &[Variant::new(&changed)]); } } diff --git a/routes-native/src/stateserver/world.rs b/routes-native/src/stateserver/world.rs index 6da4eb2..80a6f7a 100644 --- a/routes-native/src/stateserver/world.rs +++ b/routes-native/src/stateserver/world.rs @@ -90,22 +90,26 @@ impl World { positions } - pub fn put_tile_at(&mut self, x: usize, y: usize, z: usize, id: usize) -> bool{ - if !self.can_put_tile_at(x, y, z, id){ - return false; + 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) { + return changed; } + 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{ - if self.tiles[x][y][z] == tiles::Tiletypes::Air{ + pub fn can_put_tile_at(&self, x: usize, y: usize, z: usize, id: usize) -> bool { + if self.tiles[x][y][z] == tiles::Tiletypes::Air { return true; } false } - pub fn new(xsize: usize, ysize: usize, zsize: usize) -> World { World { xsize,