mirror of
https://git.kittycat.homes/zoe/codename-routes.git
synced 2024-08-15 03:18:26 +00:00
ive decided its fine if the state server is public
This commit is contained in:
parent
74e9d94977
commit
5b58f246a0
7 changed files with 35 additions and 29 deletions
Binary file not shown.
|
@ -14,6 +14,10 @@ config/name="routes"
|
||||||
run/main_scene="res://world/World.tscn"
|
run/main_scene="res://world/World.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
StateServer="*res://native/StateServer.tscn"
|
||||||
|
|
||||||
[importer_defaults]
|
[importer_defaults]
|
||||||
|
|
||||||
texture={
|
texture={
|
||||||
|
|
|
@ -1,28 +1,13 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
onready var server = $StateServer
|
|
||||||
|
|
||||||
export var xsize = 256
|
export var xsize = 256
|
||||||
export var ysize = 256
|
export var ysize = 256
|
||||||
export var zsize = 6
|
export var zsize = 6
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
server.generate_world(xsize, ysize, zsize)
|
StateServer.generate_world(xsize, ysize, zsize)
|
||||||
print(server.get_tile_at(0,0,0))
|
print(StateServer.get_tile_at(0,0,0))
|
||||||
|
|
||||||
func respawn_tilemaps(amount: int):
|
func respawn_tilemaps(amount: int):
|
||||||
$Tilemaps.respawn_tilemaps(amount)
|
$Tilemaps.respawn_tilemaps(amount)
|
||||||
|
|
||||||
func get_tile_at(pos: Vector3) -> String:
|
|
||||||
return server.get_tile_at(int(pos.x), int(pos.y), int(pos.z))
|
|
||||||
|
|
||||||
func update_tiles(tile_positions: PoolVector3Array):
|
|
||||||
for tile in tile_positions:
|
|
||||||
$Tilemaps.tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y),
|
|
||||||
get_tile_at(tile))
|
|
||||||
|
|
||||||
func _on_StateServer_request_init():
|
|
||||||
respawn_tilemaps(zsize - 1)
|
|
||||||
|
|
||||||
func _on_StateServer_changed_tiletypes(tile_positions: PoolVector3Array):
|
|
||||||
call_deferred("update_tiles", tile_positions)
|
|
||||||
|
|
|
@ -3,11 +3,29 @@ extends Node
|
||||||
var Tilemap = preload("res://world/Tilemap.tscn")
|
var Tilemap = preload("res://world/Tilemap.tscn")
|
||||||
var tilemaps = []
|
var tilemaps = []
|
||||||
|
|
||||||
func respawn_tilemaps(amount: int):
|
func _ready():
|
||||||
|
StateServer.connect("changed_tiletypes", self, "_on_StateServer_changed_tiletypes")
|
||||||
|
StateServer.connect("request_init", self, "_on_StateServer_request_init")
|
||||||
|
|
||||||
|
func respawn_tilemaps():
|
||||||
tilemaps = []
|
tilemaps = []
|
||||||
for i in range(0, amount + 1):
|
for i in range(0, StateServer.get_world_size().z):
|
||||||
var map = Tilemap.instance()
|
var map = Tilemap.instance()
|
||||||
map.position.y -= i * map.cell_size.y
|
map.position.y -= i * map.cell_size.y
|
||||||
map.z_index = i
|
map.z_index = i
|
||||||
add_child(map)
|
add_child(map)
|
||||||
tilemaps.push_back(map)
|
tilemaps.push_back(map)
|
||||||
|
|
||||||
|
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),
|
||||||
|
get_tile_at(tile))
|
||||||
|
|
||||||
|
func _on_StateServer_request_init():
|
||||||
|
call_deferred("respawn_tilemaps")
|
||||||
|
|
||||||
|
func _on_StateServer_changed_tiletypes(tile_positions: PoolVector3Array):
|
||||||
|
call_deferred("update_tiles", tile_positions)
|
||||||
|
|
|
@ -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://native/StateServer.tscn" type="PackedScene" 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,10 +9,5 @@ script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="Worldcam" parent="." instance=ExtResource( 2 )]
|
[node name="Worldcam" parent="." instance=ExtResource( 2 )]
|
||||||
|
|
||||||
[node name="StateServer" parent="." instance=ExtResource( 3 )]
|
|
||||||
|
|
||||||
[node name="Tilemaps" type="Node" parent="."]
|
[node name="Tilemaps" type="Node" parent="."]
|
||||||
script = ExtResource( 4 )
|
script = ExtResource( 4 )
|
||||||
|
|
||||||
[connection signal="changed_tiletypes" from="StateServer" to="." method="_on_StateServer_changed_tiletypes"]
|
|
||||||
[connection signal="request_init" from="StateServer" to="." method="_on_StateServer_request_init"]
|
|
||||||
|
|
|
@ -39,6 +39,11 @@ impl StateServer {
|
||||||
_owner.emit_signal("changed_tiletypes", &[Variant::new(&w)]);
|
_owner.emit_signal("changed_tiletypes", &[Variant::new(&w)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[export]
|
||||||
|
fn get_world_size(&self, _ownser: &Node) -> Vector3 {
|
||||||
|
Vector3::new(self.world.xsize as f32, self.world.ysize as f32, self.world.zsize as f32)
|
||||||
|
}
|
||||||
|
|
||||||
#[export]
|
#[export]
|
||||||
fn get_tile_at(&self, _owner: &Node, x: usize, y: usize, z: usize) -> u16 {
|
fn get_tile_at(&self, _owner: &Node, x: usize, y: usize, z: usize) -> u16 {
|
||||||
self.world.get_tile_at(x, y, z)
|
self.world.get_tile_at(x, y, z)
|
||||||
|
|
|
@ -3,9 +3,9 @@ use gdnative::prelude::*;
|
||||||
mod tiles;
|
mod tiles;
|
||||||
|
|
||||||
pub struct World {
|
pub struct World {
|
||||||
xsize: usize,
|
pub xsize: usize,
|
||||||
ysize: usize,
|
pub ysize: usize,
|
||||||
zsize: usize,
|
pub zsize: usize,
|
||||||
tiles: Vec<Vec<Vec<tiles::Tiletypes>>>,
|
tiles: Vec<Vec<Vec<tiles::Tiletypes>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue