Browse Source

EGSave add readonly data excute

master
jkpete 2 months ago
parent
commit
33d71a706c
  1. 133
      Example/Tween/Texture/Gobot_Model.tscn
  2. BIN
      Example/Tween/Texture/gBot_pieces.png
  3. 34
      Example/Tween/Texture/gBot_pieces.png.import
  4. 3
      Example/UsingTest/Scene/TestEGFramework.tscn
  5. 57
      Example/UsingTest/Script/EGSaveTest.cs
  6. 78
      addons/EGFramework/Module/SaveTools/EGByteSave.cs
  7. 10
      addons/EGFramework/Module/SaveTools/EGCsvSave.cs
  8. 8
      addons/EGFramework/Module/SaveTools/EGJsonSave.cs
  9. 51
      addons/EGFramework/Module/SaveTools/EGSave.cs
  10. 21
      addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs
  11. 54
      addons/Tools/ItemImporter/ToolItemImporter.cs
  12. 37
      addons/Tools/ItemImporter/ToolItemImporter.tscn
  13. 7
      addons/Tools/ItemImporter/plugin.cfg
  14. 5
      project.godot

133
Example/Tween/Texture/Gobot_Model.tscn

@ -0,0 +1,133 @@ @@ -0,0 +1,133 @@
[gd_scene load_steps=2 format=3 uid="uid://bonekg2q1lxx4"]
[ext_resource type="Texture2D" uid="uid://cbq4j4svebp45" path="res://Example/Tween/Texture/gBot_pieces.png" id="1_vmu55"]
[node name="Node2D" type="Node2D"]
[node name="Gobot" type="Node2D" parent="."]
position = Vector2(157, 138)
[node name="arm_left" type="Polygon2D" parent="Gobot"]
position = Vector2(77, 210)
texture = ExtResource("1_vmu55")
skeleton = NodePath("../../Skeleton2D")
polygon = PackedVector2Array(188, 36, 225, 22, 276, 47, 266, 129, 248, 188, 275, 275, 298, 302, 275, 348, 220, 360, 194, 313, 176, 246, 187, 199, 184, 102, 176, 48, 224, 96, 216, 192, 240, 304, 216, 208)
uv = PackedVector2Array(188, 36, 225, 22, 276, 47, 266, 129, 248, 188, 275, 275, 298, 302, 275, 348, 220, 360, 194, 313, 176, 246, 187, 199, 184, 102, 174, 44, 216, 96, 216, 192, 240, 304, 216, 200)
polygons = [PackedInt32Array(14, 1, 0, 13, 12), PackedInt32Array(1, 2, 3, 14), PackedInt32Array(14, 15, 4, 3), PackedInt32Array(14, 12, 11, 15), PackedInt32Array(5, 6, 7, 16), PackedInt32Array(16, 9, 8, 7), PackedInt32Array(11, 17, 15), PackedInt32Array(15, 17, 4), PackedInt32Array(17, 16, 9, 10, 11), PackedInt32Array(4, 17, 16, 5)]
bones = ["hip", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/head", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/head/jaw", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/arm_right", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/arm_right/hand_right", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/arm_left", PackedFloat32Array(1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0), "hip/chest/arm_left/hand_left", PackedFloat32Array(0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1), "hip/leg_left", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/leg_left/calf_left", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/leg_left/calf_left/foot_left", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/leg_right", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/leg_right/leg_right2", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/leg_right/leg_right2/leg_right3", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)]
internal_vertex_count = 4
[node name="leg_left" type="Polygon2D" parent="Gobot"]
position = Vector2(-46, 56)
texture = ExtResource("1_vmu55")
skeleton = NodePath("../../Skeleton2D")
polygon = PackedVector2Array(285.231, 396.984, 311.252, 384.229, 343.905, 401.066, 341.354, 431.678, 333.701, 442.392, 327.578, 478.617, 337.782, 475.556, 340.843, 504.637, 326.047, 538.821, 327.578, 569.433, 349.517, 602.086, 382.17, 608.719, 391.354, 649.535, 403.088, 657.698, 406.66, 688.821, 397.476, 693.413, 250.027, 690.352, 247.476, 660.25, 252.068, 657.188, 247.986, 629.127, 254.619, 613.821, 254.619, 509.229, 281.66, 471.474, 290.992, 521.359, 297.01, 631.544, 294.695, 615.34, 297.473, 498.674)
uv = PackedVector2Array(285.231, 396.984, 311.252, 384.229, 343.905, 401.066, 341.354, 431.678, 333.701, 442.392, 327.578, 478.617, 337.782, 475.556, 340.843, 504.637, 326.047, 538.821, 327.578, 569.433, 349.517, 602.086, 382.17, 608.719, 391.354, 649.535, 403.088, 657.698, 406.66, 688.821, 397.476, 693.413, 250.027, 690.352, 247.476, 660.25, 252.068, 657.188, 247.986, 629.127, 254.619, 613.821, 254.619, 509.229, 281.66, 471.474, 290.992, 521.359, 297.01, 631.544, 294.695, 615.34, 297.473, 498.674)
polygons = [PackedInt32Array(23, 21, 20, 25, 9, 8), PackedInt32Array(25, 24, 10, 9), PackedInt32Array(20, 25, 24, 19), PackedInt32Array(26, 23, 8, 7), PackedInt32Array(22, 26, 23, 21), PackedInt32Array(7, 6, 5, 4, 3, 2, 1, 0, 22, 26), PackedInt32Array(19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 24)]
bones = ["hip", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/head", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/head/jaw", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/arm_right", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/arm_right/hand_right", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/arm_left", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/chest/arm_left/hand_left", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/leg_left", PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1), "hip/leg_left/calf_left", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1), "hip/leg_left/calf_left/foot_left", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0), "hip/leg_right", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/leg_right/leg_right2", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "hip/leg_right/leg_right2/leg_right3", PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)]
internal_vertex_count = 4
[node name="Body" type="Polygon2D" parent="Gobot"]
position = Vector2(-213, 183)
texture = ExtResource("1_vmu55")
polygon = PackedVector2Array(454, 19, 483, 39, 487, 82, 521, 157, 524, 194, 509.272, 215.601, 494, 238, 475, 250, 476, 260, 493, 276, 488, 312, 462, 339, 422, 348, 367, 331, 346, 297, 349, 262, 375, 251, 372, 236, 350, 205, 340, 135, 357, 85, 384, 78, 393, 37, 427, 18)
uv = PackedVector2Array(454, 19, 483, 39, 487, 82, 521, 157, 524, 194, 494, 238, 475, 250, 476, 260, 493, 276, 488, 312, 462, 339, 422, 348, 367, 331, 346, 297, 349, 262, 375, 251, 372, 236, 350, 205, 340, 135, 357, 85, 384, 78, 393, 37, 427, 18)
[node name="leg_right" type="Polygon2D" parent="Gobot"]
position = Vector2(59, 63)
texture = ExtResource("1_vmu55")
polygon = PackedVector2Array(89.832, 385.034, 117.043, 400.68, 119.084, 426.531, 108.88, 441.497, 108.88, 463.265, 103.437, 476.871, 115.002, 472.789, 119.084, 508.843, 104.798, 537.415, 105.478, 559.864, 125.886, 593.197, 155.818, 602.041, 166.022, 617.007, 168.063, 643.537, 182.349, 653.061, 183.029, 676.19, 174.186, 685.714, 29.2878, 683.673, 19.7639, 674.83, 25.8864, 653.061, 30.6483, 604.762, 32.6891, 510.884, 61.2605, 470.068, 63.3014, 399.32)
uv = PackedVector2Array(89.832, 385.034, 117.043, 400.68, 119.084, 426.531, 108.88, 441.497, 108.88, 463.265, 103.437, 476.871, 115.002, 472.789, 119.084, 508.843, 104.798, 537.415, 105.478, 559.864, 125.886, 593.197, 155.818, 602.041, 166.022, 617.007, 168.063, 643.537, 182.349, 653.061, 183.029, 676.19, 174.186, 685.714, 29.2878, 683.673, 19.7639, 674.83, 25.8864, 653.061, 30.6483, 604.762, 32.6891, 510.884, 61.2605, 470.068, 63.3014, 399.32)
[node name="arm_right" type="Polygon2D" parent="Gobot"]
position = Vector2(53, 227)
texture = ExtResource("1_vmu55")
polygon = PackedVector2Array(80, 13, 141, 46, 98, 181, 139, 320, 122, 354, 62, 365, 26, 311, 14, 229, 32, 192, 21, 120, 34, 25)
uv = PackedVector2Array(80, 13, 141, 46, 98, 181, 139, 320, 122, 354, 62, 365, 26, 311, 14, 229, 32, 192, 21, 120, 34, 25)
[node name="head" type="Polygon2D" parent="Gobot"]
position = Vector2(-427, -344)
texture = ExtResource("1_vmu55")
polygon = PackedVector2Array(481.482, 378.14, 484.033, 449.058, 495.767, 494.466, 537.094, 496.507, 544.747, 525.079, 667.196, 533.242, 677.91, 506.711, 713.624, 511.303, 721.278, 521.507, 765.155, 517.426, 772.808, 505.181, 800.869, 503.65, 807.502, 489.364, 809.033, 380.691, 801.89, 361.303, 813.624, 340.895, 784.033, 294.466, 761.073, 297.017, 763.114, 272.528, 711.073, 252.119, 663.624, 255.691, 659.543, 269.977, 643.216, 249.568, 620.767, 247.017, 554.441, 282.221, 565.155, 316.405, 546.788, 327.119, 510.053, 328.14)
uv = PackedVector2Array(481.482, 378.14, 484.033, 449.058, 495.767, 494.466, 537.094, 496.507, 544.747, 525.079, 667.196, 533.242, 677.91, 506.711, 713.624, 511.303, 721.278, 521.507, 765.155, 517.426, 772.808, 505.181, 800.869, 503.65, 807.502, 489.364, 809.033, 380.691, 801.89, 361.303, 813.624, 340.895, 784.033, 294.466, 761.073, 297.017, 763.114, 272.528, 711.073, 252.119, 663.624, 255.691, 659.543, 269.977, 643.216, 249.568, 620.767, 247.017, 554.441, 282.221, 565.155, 316.405, 546.788, 327.119, 510.053, 328.14)
[node name="jaw" type="Polygon2D" parent="Gobot"]
position = Vector2(-423, -438)
texture = ExtResource("1_vmu55")
polygon = PackedVector2Array(488.089, 572.317, 541.793, 575.404, 544.879, 600.712, 548.583, 574.169, 616.484, 574.169, 620.805, 585.898, 635.003, 585.898, 644.879, 571.083, 716.484, 572.317, 723.891, 582.194, 738.706, 582.811, 744.262, 571.083, 819.57, 561.823, 815.867, 613.058, 788.089, 657.503, 754.756, 674.169, 654.138, 688.984, 547.965, 680.959, 498.583, 643.922, 481.916, 605.651)
uv = PackedVector2Array(488.089, 572.317, 541.793, 575.404, 544.879, 600.712, 548.583, 574.169, 616.484, 574.169, 620.805, 585.898, 635.003, 585.898, 644.879, 571.083, 716.484, 572.317, 723.891, 582.194, 738.706, 582.811, 744.262, 571.083, 819.57, 561.823, 815.867, 613.058, 788.089, 657.503, 754.756, 674.169, 654.138, 688.984, 547.965, 680.959, 498.583, 643.922, 481.916, 605.651)
[node name="Skeleton2D" type="Skeleton2D" parent="."]
position = Vector2(157, 138)
[node name="hip" type="Bone2D" parent="Skeleton2D"]
position = Vector2(218, 493)
rest = Transform2D(1, 0, 0, 1, 218, 493)
[node name="chest" type="Bone2D" parent="Skeleton2D/hip"]
position = Vector2(1, -45)
rest = Transform2D(1, 0, 0, 1, 1, -45)
[node name="head" type="Bone2D" parent="Skeleton2D/hip/chest"]
position = Vector2(5, -185)
rest = Transform2D(1, 0, 0, 1, 5, -185)
[node name="jaw" type="Bone2D" parent="Skeleton2D/hip/chest/head"]
position = Vector2(-95, -64)
rest = Transform2D(1, 0, 0, 1, -95, -64)
auto_calculate_length_and_angle = false
length = 150.0
bone_angle = 0.0
[node name="arm_right" type="Bone2D" parent="Skeleton2D/hip/chest"]
position = Vector2(-95, -132)
rest = Transform2D(1, 0, 0, 1, -95, -132)
[node name="hand_right" type="Bone2D" parent="Skeleton2D/hip/chest/arm_right"]
position = Vector2(-5, 101)
rotation = 1.39626
rest = Transform2D(0.173648, 0.984808, -0.984808, 0.173648, -5, 101)
auto_calculate_length_and_angle = false
length = 120.0
bone_angle = 0.0
[node name="arm_left" type="Bone2D" parent="Skeleton2D/hip/chest"]
position = Vector2(78, -142)
rest = Transform2D(1, 0, 0, 1, 78, -142)
[node name="hand_left" type="Bone2D" parent="Skeleton2D/hip/chest/arm_left"]
position = Vector2(1, 99)
rest = Transform2D(1, 0, 0, 1, 1, 99)
auto_calculate_length_and_angle = false
length = 120.0
bone_angle = 70.0
[node name="leg_left" type="Bone2D" parent="Skeleton2D/hip"]
position = Vector2(55, -21)
rest = Transform2D(1, 0, 0, 1, 55, -21)
[node name="calf_left" type="Bone2D" parent="Skeleton2D/hip/leg_left"]
position = Vector2(-29, 98)
rest = Transform2D(1, 0, 0, 1, -29, 98)
[node name="foot_left" type="Bone2D" parent="Skeleton2D/hip/leg_left/calf_left"]
position = Vector2(20, 135)
rest = Transform2D(1, 0, 0, 1, 20, 135)
auto_calculate_length_and_angle = false
length = 60.0
bone_angle = 0.0
[node name="leg_right" type="Bone2D" parent="Skeleton2D/hip"]
position = Vector2(-69, -16)
rest = Transform2D(1, 0, 0, 1, -69, -16)
[node name="leg_right2" type="Bone2D" parent="Skeleton2D/hip/leg_right"]
position = Vector2(-20, 98)
rest = Transform2D(1, 0, 0, 1, -20, 98)
[node name="leg_right3" type="Bone2D" parent="Skeleton2D/hip/leg_right/leg_right2"]
position = Vector2(13, 133)
rest = Transform2D(1, 0, 0, 1, 13, 133)
auto_calculate_length_and_angle = false
length = 60.0
bone_angle = 0.0

BIN
Example/Tween/Texture/gBot_pieces.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 KiB

34
Example/Tween/Texture/gBot_pieces.png.import

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cbq4j4svebp45"
path="res://.godot/imported/gBot_pieces.png-1c5266364ba54cfdb5b194e098160c14.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Example/Tween/Texture/gBot_pieces.png"
dest_files=["res://.godot/imported/gBot_pieces.png-1c5266364ba54cfdb5b194e098160c14.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

3
Example/UsingTest/Scene/TestEGFramework.tscn

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://Example/UsingTest/Script/EGSaveTest.cs" id="1_eij2h"]
[node name="TestEgFramework" type="Control"]
[node name="Test" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@ -20,6 +20,7 @@ offset_right = 361.0 @@ -20,6 +20,7 @@ offset_right = 361.0
offset_bottom = 164.0
[node name="Button1" type="Button" parent="."]
visible = false
layout_mode = 0
offset_right = 50.0
offset_bottom = 50.0

57
Example/UsingTest/Script/EGSaveTest.cs

@ -1,7 +1,5 @@ @@ -1,7 +1,5 @@
using Godot;
using LiteDB;
using System;
using System.IO;
namespace EGFramework.Examples.Test{
public partial class EGSaveTest : Node,IEGFramework
@ -9,6 +7,21 @@ namespace EGFramework.Examples.Test{ @@ -9,6 +7,21 @@ namespace EGFramework.Examples.Test{
public override void _Ready()
{
base._Ready();
TestCode();
}
public void TestSqlite(){
// string result = this.EGSqlite().CreateTable<SqliteBackpackItem>();
this.EGSqlite().SaveData(new SqliteBackpackItem{
ItemID = 10,
ItemCount = 1,
BackpackID = 1,
});
GD.Print(this.EGSqlite().ExceptionMsg);
// var properties = typeof(SqliteBackpackItem).GetFields();
// Godot.GD.Print(properties.Count() + " Readed ");
}
public void TestCode(){
// this.EGSave().OpenUserPath();
// GD.Print(ProjectSettings.GlobalizePath("res://SaveData/Default.json"));
// GD.Print(ProjectSettings.GlobalizePath("user://SaveData/Default.json"));
@ -16,13 +29,23 @@ namespace EGFramework.Examples.Test{ @@ -16,13 +29,23 @@ namespace EGFramework.Examples.Test{
// TestLiteDB();
// string CardPath1 = "SaveData/CardData1.json".GetGodotResPath();
// this.EGSave().LoadObjectFile<EGJsonSave>(CardPath1);
// // this.EGSave().SetObject(CardPath1,"Customer1",new Customer() { Name = "Andy" });
// // this.EGSave().SetObject(CardPath1,"Customer3",new Customer() { Name = "Terry" });
string CardPath1 = "Card1";
// FileAccess fileAccess = FileAccess.Open("res://SaveData/TestCsv.csv", FileAccess.ModeFlags.Read);
// GD.Print(fileAccess.GetAsText());
// FileAccess testFile = FileAccess.Open("res://SaveData/CardData1.json", FileAccess.ModeFlags.Read);
// this.EGSave().ReadObject<EGJsonSave>(CardPath1,testFile.GetAsText());
// Customer customer = this.EGSave().GetObject<Customer>(CardPath1,"Customer3");
// GD.Print("ReadName is "+customer.Name);
EGCsvSave csvSave = new EGCsvSave();
csvSave.InitSaveFile("SaveData/TestCsv.csv");
// FileAccess testCSV = FileAccess.Open("res://SaveData/TestCSV.json", FileAccess.ModeFlags.Read);
// EGCsvSave csvSave = new EGCsvSave();
// csvSave.InitSaveFile("SaveData/TestCsv.csv");
// Customer testData = csvSave.GetData<Customer>("",1);
// GD.Print("Name = "+testData.Name +" || ID = "+testData.Id);
// Customer testData = new Customer(){
@ -31,12 +54,13 @@ namespace EGFramework.Examples.Test{ @@ -31,12 +54,13 @@ namespace EGFramework.Examples.Test{
// IsActive = true
// };
// csvSave.SetData("",testData,2)
// IEnumerable<Customer> allResult = csvSave.GetAll<Customer>("");
// GD.Print("Get result " + allResult.Count());
// foreach(Customer customer in allResult){
// GD.Print(customer.Id +"|" + customer.Name);
// }
FileAccess testCsv = FileAccess.Open("res://SaveData/TestCsv.csv", FileAccess.ModeFlags.Read);
this.EGSave().ReadData<EGCsvSave>(CardPath1,testCsv.GetAsText());
IEnumerable<Customer> allResult = this.EGSave().GetAllData<Customer>(CardPath1,"");
GD.Print("Get result " + allResult.Count());
foreach(Customer customer in allResult){
GD.Print(customer.Id +"|" + customer.Name);
}
// System.Linq.Expressions.Expression<Func<Customer, bool>> expr = i => i.Name == "Creature";
// IEnumerable<Customer> linqResult = csvSave.FindData<Customer>("",expr);
@ -58,19 +82,6 @@ namespace EGFramework.Examples.Test{ @@ -58,19 +82,6 @@ namespace EGFramework.Examples.Test{
// GD.Print(property.Name);
// }
}
public void TestSqlite(){
// string result = this.EGSqlite().CreateTable<SqliteBackpackItem>();
this.EGSqlite().SaveData(new SqliteBackpackItem{
ItemID = 10,
ItemCount = 1,
BackpackID = 1,
});
GD.Print(this.EGSqlite().ExceptionMsg);
// var properties = typeof(SqliteBackpackItem).GetFields();
// Godot.GD.Print(properties.Count() + " Readed ");
}
}
public struct SqliteBackpackItem{
public int Id { get; set; }

78
addons/EGFramework/Module/SaveTools/EGByteSave.cs

@ -3,43 +3,91 @@ using System.Collections.Generic; @@ -3,43 +3,91 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Runtime.Serialization.Formatters.Binary;
using Godot;
using System.IO;
namespace EGFramework
{
public class EGByteSave : IEGSave,IEGSaveObject
{
public Encoding StringEncoding { set; get; } = Encoding.ASCII;
private string DefaultPath { set; get; }
private byte[] Data { get; set; }
public void SaveToFile(string content)
public void ReadDataBlock(string path){
DefaultPath = path;
try
{
using var file = FileAccess.Open("user://save_game.dat", FileAccess.ModeFlags.Write);
Variant hp = 10;
file.StoreVar(hp);
Variant pos = new Vector2(100,100);
file.StoreVar(pos);
FileStream fileStream = new FileStream(path,FileMode.Open);
byte[] buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, (int)fileStream.Length);
fileStream.Close();
fileStream.Dispose();
Data = buffer;
}
public Variant LoadFromFile()
catch (System.Exception e)
{
Godot.GD.Print("e:" + e);
throw;
}
}
public void WriteDataBlock(string path){
try
{
FileStream fileStream = File.Create(path);
fileStream.Write(Data,0,Data.Length);
fileStream.Close();
fileStream.Dispose();
}
catch (System.Exception e)
{
using var file = FileAccess.Open("user://save_game.dat", FileAccess.ModeFlags.Read);
Variant content = file.GetVar();
Variant pos = file.GetVar();
return pos;
Godot.GD.Print("e:" + e);
throw;
}
}
public void InitSaveFile(string path)
{
//throw new NotImplementedException();
ReadDataBlock(path);
}
public void SetObject<TObject>(string objectKey , TObject obj)
{
throw new NotImplementedException();
// throw new NotImplementedException();
}
public TObject GetObject<TObject>(string objectKey) where TObject : new()
{
throw new NotImplementedException();
}
public int GetDataLength(Type type){
switch(type){
default: return 0 ;
}
}
}
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class ByteParamAttribute: Attribute{
public int _pointer { set; get; }
public int _length { set; get; }
public ByteParamAttribute(int pointer,int length = 0){
this._pointer = pointer;
this._length = length;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
public class ByteClassAttribute:Attribute{
public int _length { set; get; }
public ByteClassAttribute(int length){
this._length = length;
}
}
public interface IEGByteInit{
void Init(byte[] data);
}
}

10
addons/EGFramework/Module/SaveTools/EGCsvSave.cs

@ -9,7 +9,7 @@ using System.Threading.Tasks; @@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace EGFramework
{
public class EGCsvSave : IEGSaveData, IEGSave
public class EGCsvSave : IEGSaveData, IEGSave, IEGSaveReadOnly
{
public Encoding StringEncoding { set; get; } = Encoding.UTF8;
private string DefaultPath { set; get; }
@ -24,6 +24,14 @@ namespace EGFramework @@ -24,6 +24,14 @@ namespace EGFramework
ReadDataBlock(path);
}
public void InitReadOnly(string data)
{
ReadText = data;
if(ReadText != null || ReadText != ""){
CsvDataBlock = GetCSVDataBlockFromText(ReadText,out CsvDataHeader);
}
}
public void ReadDataBlock(string path){
DefaultPath = path;
try

8
addons/EGFramework/Module/SaveTools/EGJsonSave.cs

@ -8,7 +8,7 @@ using Newtonsoft.Json.Linq; @@ -8,7 +8,7 @@ using Newtonsoft.Json.Linq;
namespace EGFramework
{
public class EGJsonSave : IEGSave,IEGSaveObject
public class EGJsonSave : IEGSave,IEGSaveReadOnly,IEGSaveObject
{
private string DefaultPath { set; get; }
private JObject _SaveObject;
@ -42,6 +42,11 @@ namespace EGFramework @@ -42,6 +42,11 @@ namespace EGFramework
}
}
public void InitReadOnly(string data)
{
_SaveObject = JObject.Parse(data);
}
public void SetObject<TObject>(string objectKey,TObject obj)
{
if(SaveObject.ContainsKey(objectKey)){
@ -63,5 +68,6 @@ namespace EGFramework @@ -63,5 +68,6 @@ namespace EGFramework
TObject data = SaveObject[objectKey].ToObject<TObject>();
return data;
}
}
}

51
addons/EGFramework/Module/SaveTools/EGSave.cs

@ -27,6 +27,9 @@ namespace EGFramework @@ -27,6 +27,9 @@ namespace EGFramework
private Dictionary<string,IEGSaveData> DataBaseFiles = new Dictionary<string,IEGSaveData>();
private Dictionary<string,IEGSaveObject> ObjectFiles = new Dictionary<string,IEGSaveObject>();
private Dictionary<string,IEGSaveDataReadOnly> DataBaseReadOnly = new Dictionary<string, IEGSaveDataReadOnly>();
private Dictionary<string,IEGSaveObjectReadOnly> ObjectReadOnly = new Dictionary<string,IEGSaveObjectReadOnly>();
public EGSave() {}
public override void Init()
{
@ -39,25 +42,69 @@ namespace EGFramework @@ -39,25 +42,69 @@ namespace EGFramework
DataBaseFiles.Add(path,saveData);
}
public void ReadData<TReadOnlyData>(string key,string data)where TReadOnlyData:IEGSaveDataReadOnly,IEGSaveReadOnly,new(){
TReadOnlyData readOnlyData = new TReadOnlyData();
readOnlyData.InitReadOnly(data);
DataBaseReadOnly.Add(key,readOnlyData);
}
public void LoadObjectFile<TSaveObject>(string path) where TSaveObject:IEGSaveObject,IEGSave,new(){
TSaveObject saveObject = new TSaveObject();
saveObject.InitSaveFile(path);
ObjectFiles.Add(path, saveObject);
}
public void ReadObject<TReadOnlyObject>(string key,string data)where TReadOnlyObject:IEGSaveObjectReadOnly,IEGSaveReadOnly,new(){
TReadOnlyObject readOnlyObject = new TReadOnlyObject();
readOnlyObject.InitReadOnly(data);
ObjectReadOnly.Add(key,readOnlyObject);
}
public void SetObject<TObject>(string path,string objectKey,TObject obj){
if(ObjectFiles.ContainsKey(path)){
ObjectFiles[path].SetObject(objectKey,obj);
}else{
throw new Exception("File not loaded, you should use LoadObjectFile(key) first.");
}
}
public TObject GetObject<TObject>(string path,string key) where TObject : new(){
if(ObjectFiles.ContainsKey(path)){
return ObjectFiles[path].GetObject<TObject>(key);
}else if(ObjectReadOnly.ContainsKey(path)){
return ObjectReadOnly[path].GetObject<TObject>(key);
}else{
throw new Exception("File not loaded, you should use LoadObjectFile(key) or ReadObject(key) first.");
}
}
public void SetData<TData>(string path,string dataKey,TData data,int id){
if(DataBaseFiles.ContainsKey(path)){
DataBaseFiles[path].SetData(dataKey,data,id);
}else{
throw new Exception("File not loaded, you should use LoadDataFile(path) first.");
}
}
public void GetData<TData>(string path,string key,int id) where TData : new(){
DataBaseFiles[path].GetData<TData>(key,id);
public TData GetData<TData>(string path,string key,int id) where TData : new(){
if(DataBaseFiles.ContainsKey(path)){
return DataBaseFiles[path].GetData<TData>(key,id);
}else if(DataBaseReadOnly.ContainsKey(path)){
return DataBaseReadOnly[path].GetData<TData>(key,id);
}else{
throw new Exception("File not loaded, you should use LoadDataFile(key) or ReadData(key,data) first.");
}
}
public IEnumerable<TData> GetAllData<TData>(string path,string key) where TData : new(){
if(DataBaseFiles.ContainsKey(path)){
return DataBaseFiles[path].GetAll<TData>(key);
}else if(DataBaseReadOnly.ContainsKey(path)){
return DataBaseReadOnly[path].GetAll<TData>(key);
}else{
throw new Exception("File not loaded, you should use LoadDataFile(key) or ReadData(key,data) first.");
}
}
//------------------------------------------------------------------------------//

21
addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs

@ -10,16 +10,25 @@ namespace EGFramework @@ -10,16 +10,25 @@ namespace EGFramework
void InitSaveFile(string path);
}
public interface IEGSaveObject{
void SetObject<TObject>(string objectKey,TObject obj);
TObject GetObject<TObject>(string objectKey) where TObject : new();
public interface IEGSaveReadOnly{
void InitReadOnly(string data);
}
//
public interface IEGSaveData{
void SetData<TData>(string dataKey,TData data,object id);
public interface IEGSaveObjectReadOnly{
TObject GetObject<TObject>(string objectKey) where TObject : new();
}
public interface IEGSaveDataReadOnly{
TData GetData<TData>(string dataKey,object id) where TData : new();
IEnumerable<TData> GetAll<TData>(string dataKey) where TData : new();
IEnumerable<TData> FindData<TData>(string dataKey,Expression<Func<TData, bool>> expression) where TData : new();
}
public interface IEGSaveObject : IEGSaveObjectReadOnly{
void SetObject<TObject>(string objectKey,TObject obj);
}
//
public interface IEGSaveData : IEGSaveDataReadOnly{
void SetData<TData>(string dataKey,TData data,object id);
}
}

54
addons/Tools/ItemImporter/ToolItemImporter.cs

@ -1,54 +0,0 @@ @@ -1,54 +0,0 @@
#if TOOLS
using Godot;
using System;
namespace EGFramework.Example.SystemExamples.PlayerStorage
{
[Tool]
public partial class ToolItemImporter : EditorPlugin
{
PackedScene MainPanel = ResourceLoader.Load<PackedScene>("res://addons/Tools/ItemImporter/ToolItemImporter.tscn");
Control MainPanelInstance;
public override void _EnterTree()
{
// Initialization of the plugin goes here.
MainPanelInstance = (Control)MainPanel.Instantiate();
// Add the main panel to the editor's main viewport.
EditorInterface.Singleton.GetEditorMainScreen().AddChild(MainPanelInstance);
// Hide the main panel. Very much required.
_MakeVisible(false);
}
public override void _ExitTree()
{
// Clean-up of the plugin goes here.
if (MainPanelInstance != null)
{
MainPanelInstance.QueueFree();
}
}
public override bool _HasMainScreen()
{
return true;
}
public override void _MakeVisible(bool visible)
{
if (MainPanelInstance != null)
{
MainPanelInstance.Visible = visible;
}
}
public override string _GetPluginName()
{
return "Tool Item Importer";
}
public override Texture2D _GetPluginIcon()
{
return EditorInterface.Singleton.GetEditorTheme().GetIcon("Node", "EditorIcons");
}
}
}
#endif

37
addons/Tools/ItemImporter/ToolItemImporter.tscn

@ -1,37 +0,0 @@ @@ -1,37 +0,0 @@
[gd_scene format=3 uid="uid://bglw1yht7w1kt"]
[node name="ToolItemImporter" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Button" type="Button" parent="."]
layout_mode = 1
offset_right = 69.0
offset_bottom = 31.0
text = "导入CSV"
[node name="Button2" type="Button" parent="."]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -72.0
offset_bottom = 31.0
grow_horizontal = 0
text = "重新载入"
[node name="Button3" type="Button" parent="."]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -71.0
offset_top = 36.0
offset_right = 1.0
offset_bottom = 67.0
grow_horizontal = 0
text = "重新载入"

7
addons/Tools/ItemImporter/plugin.cfg

@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
[plugin]
name="ItemImporter"
description="a csv ItemImporter"
author="jkpete"
version=""
script="ToolItemImporter.cs"

5
project.godot

@ -16,6 +16,11 @@ run/main_scene="res://Example/UsingTest/Scene/TestEGFramework.tscn" @@ -16,6 +16,11 @@ run/main_scene="res://Example/UsingTest/Scene/TestEGFramework.tscn"
config/features=PackedStringArray("4.2", "C#", "GL Compatibility")
config/icon="res://icon.svg"
[display]
window/size/viewport_width=1920
window/size/viewport_height=1080
[dotnet]
project/assembly_name="EGFramework"

Loading…
Cancel
Save