1+ using CathodeLib ;
2+ using System ;
3+ using System . Collections . Generic ;
4+ using System . IO ;
5+ using System . Runtime . InteropServices ;
6+ using System . Linq ;
7+
8+ #if UNITY_EDITOR || UNITY_STANDALONE_WIN
9+ using UnityEngine ;
10+ #else
11+ using System . Numerics ;
12+ #endif
13+
14+ namespace CATHODE
15+ {
16+ /// <summary>
17+ /// DATA/ENV/x/WORLD/BEHAVIOR_TREE.DB
18+ /// </summary>
19+ public class BehaviorTreeDB : CathodeFile
20+ {
21+ public List < string > Entries = new List < string > ( ) ;
22+ public static new Implementation Implementation = Implementation . LOAD | Implementation . SAVE | Implementation . CREATE ;
23+
24+ public BehaviorTreeDB ( string path ) : base ( path ) { }
25+ public BehaviorTreeDB ( MemoryStream stream , string path = "" ) : base ( stream , path ) { }
26+ public BehaviorTreeDB ( byte [ ] data , string path = "" ) : base ( data , path ) { }
27+
28+ ~ BehaviorTreeDB ( )
29+ {
30+ Entries . Clear ( ) ;
31+ }
32+
33+ #region FILE_IO
34+ override protected bool LoadInternal ( MemoryStream stream )
35+ {
36+ using ( BinaryReader reader = new BinaryReader ( stream ) )
37+ {
38+ int count = reader . ReadInt32 ( ) ;
39+ reader . BaseStream . Position += ( count * 8 ) + 4 ;
40+ for ( int i = 0 ; i < count ; i ++ )
41+ {
42+ Entries . Add ( Utilities . ReadString ( reader ) ) ;
43+ }
44+ }
45+ return true ;
46+ }
47+
48+ override protected bool SaveInternal ( )
49+ {
50+ using ( BinaryWriter writer = new BinaryWriter ( File . OpenWrite ( _filepath ) ) )
51+ {
52+ writer . BaseStream . SetLength ( 0 ) ;
53+ writer . Write ( ( Int64 ) Entries . Count ) ;
54+ writer . Write ( new byte [ 8 * Entries . Count ] ) ;
55+ List < int > offsets = new List < int > ( Entries . Count ) ;
56+ for ( int i = 0 ; i < Entries . Count ; i ++ )
57+ {
58+ offsets . Add ( ( int ) writer . BaseStream . Position ) ;
59+ Utilities . WriteString ( Entries [ i ] , writer , true ) ;
60+ }
61+ writer . BaseStream . Position = 8 ;
62+ for ( int i = 0 ; i < Entries . Count ; i ++ )
63+ {
64+ writer . Write ( ( Int64 ) offsets [ i ] ) ;
65+ }
66+ }
67+ return true ;
68+ }
69+ #endregion
70+ }
71+ }
0 commit comments