Esempio n. 1
0
        public Result OpenCustomStorageFileSystem(out IFileSystem fileSystem, CustomStorageId storageId)
        {
            fileSystem = default;

            switch (storageId)
            {
            case CustomStorageId.SdCard:
            {
                Result rc = FsCreators.SdFileSystemCreator.Create(out IFileSystem sdFs);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                string customStorageDir = CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.SdCard);
                string subDirName       = $"/{NintendoDirectoryName}/{customStorageDir}";

                rc = Util.CreateSubFileSystem(out IFileSystem subFs, sdFs, subDirName, true);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                rc = FsCreators.EncryptedFileSystemCreator.Create(out IFileSystem encryptedFs, subFs,
                                                                  EncryptedFsKeyId.CustomStorage, SdEncryptionSeed);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                fileSystem = encryptedFs;
                return(Result.Success);
            }

            case CustomStorageId.System:
            {
                Result rc = FsCreators.BuiltInStorageFileSystemCreator.Create(out IFileSystem userFs, string.Empty,
                                                                              BisPartitionId.User);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                string customStorageDir = CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System);
                string subDirName       = $"/{customStorageDir}";

                rc = Util.CreateSubFileSystem(out IFileSystem subFs, userFs, subDirName, true);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                fileSystem = subFs;
                return(Result.Success);
            }

            default:
                return(ResultFs.InvalidArgument.Log());
            }
        }
Esempio n. 2
0
    private void Start()
    {
        if (varName[0] == '$')
        {
            Debug.LogError($"{varName} is not a valid variable name for accessing defaultVariables." +
                           "Please give a variable name, unformatted for Yarn.");
        }
        storage = (CustomStorage)MainSingleton.Instance.dialogueRunner.variableStorage;

        /* Access defaultVariables with unformatted varName, e.g. 'name'
         * This is because yarn variables are stored as '$name' but defaultVariables, which
         * are a custom extension of Yarn, are stored as 'name' to be compatible with enums */
        data = storage.defaultVariables[varName];
        // set var name to be format '$name'
        varName = varName.YarnFormat();

        // set UI elements
        if (icon is Image)
        {
            ((Image)icon).sprite = data.icon;
        }
        else if (icon is SVGImage)
        {
            ((SVGImage)icon).sprite = data.icon;
        }

        Yarn.Value value = storage.GetValue(varName);
        SetPercentUI(value.AsNumber);

        storage.OnSetValue += OnYarnValueChanged;
    }
Esempio n. 3
0
    public override void OnInspectorGUI()
    {
        CustomStorage script = (CustomStorage)target;


        if (GUILayout.Button("Delete Save Data"))
        {
            script.DeleteSaveData();
        }

        DrawDefaultInspector();
    }
Esempio n. 4
0
    void Start()
    {
        storage = (CustomStorage)MainSingleton.Instance.dialogueRunner.variableStorage;
        DialogueRunner runner = MainSingleton.Instance.dialogueRunner;

        // Register a function on startup called "visited" that lets
        // Yarn scripts query to see if a node has been run before.
        runner.AddFunction("visited", delegate(string nodeName)
        {
            return(storage.visitedNodes.Contains(nodeName));
        });
        runner.onNodeComplete.AddListener(NodeComplete);
    }
Esempio n. 5
0
        public Result OpenCustomStorageFileSystem(out ReferenceCountedDisposable <IFileSystem> fileSystem,
                                                  CustomStorageId storageId)
        {
            UnsafeHelpers.SkipParamInit(out fileSystem);

            ReferenceCountedDisposable <IFileSystem> tempFs      = null;
            ReferenceCountedDisposable <IFileSystem> encryptedFs = null;

            try
            {
                Span <byte> path = stackalloc byte[0x40];

                switch (storageId)
                {
                case CustomStorageId.SdCard:
                {
                    Result rc = BaseFileSystemService.OpenSdCardProxyFileSystem(out tempFs);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    U8Span customStorageDir = CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.SdCard);
                    var    sb = new U8StringBuilder(path);
                    sb.Append((byte)'/')
                    .Append(CommonPaths.SdCardNintendoRootDirectoryName)
                    .Append((byte)'/')
                    .Append(customStorageDir);

                    rc = Utility.WrapSubDirectory(out tempFs, ref tempFs, new U8Span(path), true);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    rc = FsCreators.EncryptedFileSystemCreator.Create(out encryptedFs, tempFs,
                                                                      EncryptedFsKeyId.CustomStorage, SdEncryptionSeed);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    return(Result.Success);
                }

                case CustomStorageId.System:
                {
                    Result rc = BaseFileSystemService.OpenBisFileSystem(out tempFs, U8Span.Empty,
                                                                        BisPartitionId.User);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    U8Span customStorageDir = CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System);
                    var    sb = new U8StringBuilder(path);
                    sb.Append((byte)'/')
                    .Append(customStorageDir);

                    rc = Utility.WrapSubDirectory(out tempFs, ref tempFs, new U8Span(path), true);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    fileSystem = Shared.Move(ref tempFs);
                    return(Result.Success);
                }

                default:
                    return(ResultFs.InvalidArgument.Log());
                }
            }
            finally
            {
                tempFs?.Dispose();
                encryptedFs?.Dispose();
            }
        }