Beispiel #1
0
        public void Load(GameInstance game)
        {
            Main.HBSLog?.Log($"Loading behavior variable scopes from {_dirPath}");

            // we're going to delete the instance of ScopeManager, clean it up
            // if we already have a ScopeManager
            if (IgnoreScopeLoadedCallsFrom.Contains(ScopeManager))
            {
                IgnoreScopeLoadedCallsFrom.Remove(ScopeManager);
            }

            // we want to ignore OnBehaviorVariableScopeLoaded calls
            // both during the constructor of BehaviorVariableScopeManager and
            // for calls that take place after the constructor
            IgnoreScopeLoadedCalls = true;
            ScopeManager           = new BehaviorVariableScopeManager(game);
            IgnoreScopeLoadedCalls = false;

            // load all the behavior variable scopes from directory
            var validPaths = Directory.GetFiles(_dirPath, "*.json")
                             .Where(filePath => ValidIDs.Contains(Path.GetFileNameWithoutExtension(filePath)));

            foreach (var validPath in validPaths)
            {
                var id   = Path.GetFileNameWithoutExtension(validPath);
                var json = Traverse.Create(typeof(JSONSerializationUtility))
                           .Method("StripHBSCommentsFromJSON", File.ReadAllText(validPath)).GetValue <string>();

                Main.HBSLog?.Log($"Loading scope with id {id}");
                ScopeManager.OnBehaviorVariableScopeLoaded(id, json);
            }

            // ignore future calls from datamanager
            IgnoreScopeLoadedCallsFrom.Add(ScopeManager);
        }
Beispiel #2
0
 public static bool Prefix(BehaviorVariableScopeManager __instance)
 {
     return(!BVScopeManagerWrapper.IgnoreScopeLoadedCalls &&
            !BVScopeManagerWrapper.IgnoreScopeLoadedCallsFrom.Contains(__instance));
 }