GodotComponentTest/scenes/WorldChunk.cs

86 lines
2.4 KiB
C#
Raw Normal View History

using Godot;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
public class WorldChunk : Spatial
{
// ui elements
// scene nodes
private MeshInstance PlaneRectMesh;
// resources
// exports
[Export] public Texture TileTypeMap;
[Export] public Texture NavigationMap;
[Export] public Texture HeightMap;
[Export] public readonly int size = 32;
[Export] public Vector2 ChunkAddress;
// [Export] public Vector2 Size = new Vector2(1, 1);
// signals
// delegate void OnCoordClicked(Vector2 world_pos);
// other members
public Rect2 PlaneRect;
public Color DebugColor = Colors.White;
public WorldChunk()
{
}
public WorldChunk(int size)
{
}
// other members
public void SaveToFile(String chunkName)
{
Image image = new Image();
image.CreateFromData(size, size, false, Image.Format.Rgba8, TileTypeMap.GetData().GetData());
image.SavePng(chunkName + "_tileType.png");
image.CreateFromData(size, size, false, Image.Format.Rgba8, NavigationMap.GetData().GetData());
image.SavePng(chunkName + "_navigationMap.png");
image.CreateFromData(size, size, false, Image.Format.Rgba8, HeightMap.GetData().GetData());
image.SavePng(chunkName + "_heightMap.png");
}
public void LoadFromFile(String chunkName)
{
}
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
PlaneRectMesh = (MeshInstance) FindNode("PlaneRectMesh");
Debug.Assert(PlaneRectMesh != null);
Transform planeRectTransform = Transform.Identity;
planeRectTransform = planeRectTransform.Scaled(new Vector3(PlaneRect.Size.x * 0.5f, 1, PlaneRect.Size.y * 0.5f));
planeRectTransform.origin.x = PlaneRect.GetCenter().x;
planeRectTransform.origin.z = PlaneRect.GetCenter().y;
PlaneRectMesh.Transform = planeRectTransform;
PlaneRectMesh.MaterialOverride = new SpatialMaterial();
((SpatialMaterial)PlaneRectMesh.MaterialOverride).AlbedoColor = DebugColor;
((SpatialMaterial)PlaneRectMesh.MaterialOverride).FlagsTransparent = true;
}
// // Called every frame. 'delta' is the elapsed time since the previous frame.
// public override void _Process(float delta)
// {
//
// }
}