Exemplo n.º 1
0
        public override void DrawEditor(double delta)
        {
            foreach (var entity in _selectedEntities.GetEntities())
            {
                if (entity.Has <VoxelSpace>())
                {
                    ImGui.Text($"Entity {entity}");
                    ImGui.SameLine();
                    if (ImGui.Button("Save"))
                    {
                        FilePicker.FilePicker.Open("save-voxel-space");
                    }

                    if (FilePicker.FilePicker.Window("save-voxel-space", ref _fileLocation, new[] { ".cvx" }))
                    {
                        if (!Directory.Exists(_fileLocation))
                        {
                            ref var space          = ref entity.Get <VoxelSpace>();
                            var     voxelSpaceData = new VoxelSpaceData()
                            {
                                VoxelSize = space.VoxelSize,
                                GridSize  = space.GridSize,
                                Grids     = space.Select(kvp => (kvp.Key, kvp.Value.Get <VoxelGrid>().Voxels)).ToArray()
                            };
                            VoxelSpaceDataSerializer.Serialize(voxelSpaceData, File.OpenWrite(_fileLocation));
                        }
                    }

                    ImGui.Separator();
                }
            }

            if (ImGui.Button("Load File"))
            {
                FilePicker.FilePicker.Open("load-voxel-space");
            }

            if (FilePicker.FilePicker.Window("load-voxel-space", ref _fileLocation, new[] { ".cvx" }))
            {
                if (File.Exists(_fileLocation))
                {
                    var voxelSpaceData = VoxelSpaceDataSerializer.Deserialize(File.OpenRead(_fileLocation));
                    LoadAsDynamic(voxelSpaceData);
                }
            }

            if (ImGui.Button("Load Empty"))
            {
                var voxels = new Voxel[8 * 8 * 8];
                voxels[0] = new Voxel()
                {
                    Exists = true
                };
                LoadAsDynamic(new VoxelSpaceData()
                {
                    VoxelSize = 1,
                    GridSize  = 8,
                    Grids     = new[]
Exemplo n.º 2
0
        public override void DrawEditor(double delta)
        {
            foreach (var entity in _selectedEntities.GetEntities())
            {
                if (entity.Has <VoxelSpace>())
                {
                    ImGui.Text($"Entity {entity}");
                    ImGui.SameLine();
                    if (ImGui.Button("Save"))
                    {
                        FilePicker.Open("save-voxel-space");
                    }

                    if (FilePicker.Window("save-voxel-space", ref _fileLocation, new[] { ".cvx" }))
                    {
                        if (!Directory.Exists(_fileLocation))
                        {
                            ref var space          = ref entity.Get <VoxelSpace>();
                            var     voxelSpaceData = new VoxelSpaceData()
                            {
                                VoxelSize = space.VoxelSize,
                                GridSize  = space.GridSize,
                                Grids     = space.Select(kvp => (kvp.Key, kvp.Value.Get <VoxelGrid>().Voxels)).ToArray()
                            };
                            VoxelSpaceDataSerializer.Serialize(voxelSpaceData, File.OpenWrite(_fileLocation));
                        }
                    }

                    ImGui.Separator();
                }
            }

            if (ImGui.Button("Load File"))
            {
                FilePicker.Open("load-voxel-space");
            }

            if (FilePicker.Window("load-voxel-space", ref _fileLocation, new[] { ".cvx" }))
            {
                if (File.Exists(_fileLocation))
                {
                    var name           = Path.GetFileNameWithoutExtension(_fileLocation);
                    var voxelSpaceData = VoxelSpaceDataSerializer.Deserialize(File.OpenRead(_fileLocation));
                    _serverChannel.AddBuffered <VoxelSpaceLoadReciever, VoxelSpaceLoadMessage>(new VoxelSpaceLoadMessage()
                    {
                        VoxelSpaceData = voxelSpaceData,
                        Position       = CameraTransform.WorldPosition,
                        Name           = name
                    });
                }
            }

            if (ImGui.Button("Load Empty"))
            {
                var voxels = new Voxel[8 * 8 * 8];
                voxels[0] = new Voxel()
                {
                    Exists = true
                };
                var voxelSpaceData = new VoxelSpaceData()
                {
                    VoxelSize = 1,
                    GridSize  = 8,
                    Grids     = new[]