Exemplo n.º 1
0
 public static extern NrtResult Nrt_BasicFillRect_setActive([NativeTypeName("NrtBasicFillRectHandle")] IntPtr rect, NrtBool inputBool);
Exemplo n.º 2
0
        public static int Main(string[] args)
        {
            res  = NRT_SUCCESS;
            rand = new Random();

            // Creating NovelRunner
            IntPtr runner = Nrt_NovelRunner_create(0);

            // Starting LoggingService
            fixed(byte *customTitle = Encoding.UTF8.GetBytes("Interop"))
            {
                console = Nrt_LoggingService_createCustomTitle((sbyte *)customTitle);
            }

            // Getting a constant to the Resources folder
            sbyte *execPath = Nrt_getExecutableDirPath();
            sbyte *error    = Nrt_getLastError();

            if (error != null)
            {
                Nrt_LoggingService_logErrorLine(console, error);
                return(-1);
            }

            sbyte *path;

            fixed(byte *pathPart = Encoding.UTF8.GetBytes("Resources"))
            {
                var pathParts = stackalloc sbyte *[2] {
                    execPath, (sbyte *)pathPart
                };

                path = Nrt_appendFilePath(2, pathParts);
            }

            // Getting & Initialising AudioService
            fixed(IntPtr *pAudio = &audio)
            {
                res = (NrtResult)Nrt_NovelRunner_getAudioService(runner, pAudio);
            }

            if (res != NRT_SUCCESS)
            {
                fixed(byte *text = Encoding.UTF8.GetBytes("Error getting AudioService: "))
                {
                    var textParts = stackalloc sbyte *[2] {
                        (sbyte *)text, Nrt_getLastError()
                    };
                    sbyte *errMsg = Nrt_appendText(2, textParts);

                    Nrt_LoggingService_logErrorLine(console, errMsg);
                }

                return(-1);
            }
            else
            {
                booleanResult = (NrtBool)Nrt_AudioService_initialiseAudio(audio);

                if (booleanResult != NRT_TRUE)
                {
                    fixed(byte *text = Encoding.UTF8.GetBytes("Error initialising AudioService: "))
                    {
                        var textParts = stackalloc sbyte *[2] {
                            (sbyte *)text, Nrt_getLastError()
                        };
                        sbyte *errMsg = Nrt_appendText(2, textParts);

                        Nrt_LoggingService_logErrorLine(console, errMsg);
                    }

                    return(-1);
                }
            }

            // Getting InteractionService
            fixed(IntPtr *pInput = &input)
            {
                res = (NrtResult)Nrt_NovelRunner_getInteractionService(runner, pInput);
            }

            if (res == NRT_SUCCESS)
            {
                fixed(byte *info = Encoding.UTF8.GetBytes("Received InteractionService from C via C#!"))
                {
                    Nrt_LoggingService_logInfoLine(console, (sbyte *)info);
                }
            }
            else
            {
                fixed(byte *text = Encoding.UTF8.GetBytes("Error getting InteractionService: "))
                {
                    var textParts = stackalloc sbyte *[2] {
                        (sbyte *)text, Nrt_getLastError()
                    };
                    sbyte *errMsg = Nrt_appendText(2, textParts);

                    Nrt_LoggingService_logErrorLine(console, errMsg);
                }

                return(-1);
            }

            // Getting & Initialising RuntimeService / InkService
            fixed(IntPtr *pDotnet = &dotnet)
            {
                res = (NrtResult)Nrt_NovelRunner_getRuntimeService(runner, pDotnet);
            }

            if (res != NRT_SUCCESS)
            {
                fixed(byte *text = Encoding.UTF8.GetBytes("Error getting RuntimeService: "))
                {
                    var textParts = stackalloc sbyte *[2] {
                        (sbyte *)text, Nrt_getLastError()
                    };
                    sbyte *errMsg = Nrt_appendText(2, textParts);

                    Nrt_LoggingService_logErrorLine(console, errMsg);
                }

                return(-1);
            }
            else
            {
                fixed(byte *info = Encoding.UTF8.GetBytes("Received .NET RuntimeService from C API via C#!"))
                {
                    Nrt_LoggingService_logInfoLine(console, (sbyte *)info);
                }

                res = (NrtResult)Nrt_RuntimeService_initialise(dotnet);

                if (res == NRT_SUCCESS)
                {
                    fixed(IntPtr *pInk = &ink)
                    {
                        res = (NrtResult)Nrt_RuntimeService_getInkService(dotnet, pInk);
                    }

                    if (res == NRT_SUCCESS)
                    {
                        fixed(byte *info = Encoding.UTF8.GetBytes("Received Ink Service from C API via C#!"))
                        {
                            Nrt_LoggingService_logInfoLine(console, (sbyte *)info);
                        }

                        inkServiceProvided = NRT_TRUE;
                        Nrt_InkService_initialise(ink);
                    }
                    else
                    {
                        fixed(byte *info = Encoding.UTF8.GetBytes("Failed to receive Ink Service!"))
                        {
                            Nrt_LoggingService_logErrorLine(console, (sbyte *)info);
                        }
                    }
                }
            }

            // Changing Background Colour
            fixed(IntPtr *pRenderer = &renderer)
            {
                res = (NrtResult)Nrt_NovelRunner_getRenderer(runner, pRenderer);
            }

            if (res != NRT_SUCCESS)
            {
                fixed(byte *text = Encoding.UTF8.GetBytes("Error getting RenderingService: "))
                {
                    var textParts = stackalloc sbyte *[2] {
                        (sbyte *)text, Nrt_getLastError()
                    };
                    sbyte *errMsg = Nrt_appendText(2, textParts);

                    Nrt_LoggingService_logErrorLine(console, errMsg);
                }

                return(-1);
            }

            colourChange = Nrt_RGBAConfig_Create(0, 0, 0, 255);

            IntPtr background = Nrt_RGBAConfig_Create(0, 0, 0, 0);

            Nrt_RenderingService_setBackgroundColour(renderer, background);

            // Creating ImageRect
            NrtGeoVector2F nChanPosition = new NrtGeoVector2F {
                x = 1920 / 2, y = 1080 / 2
            };
            NrtGeoVector2F nChanSize = new NrtGeoVector2F {
                x = 762, y = 881
            };
            NrtTransform nChanTransform = new NrtTransform {
                position = nChanPosition, scale = nChanSize, rotation = 0
            };
            IntPtr nChanColours = Nrt_RGBAConfig_Create(255, 255, 255, 255);

            sbyte *nChanFileLocation;

            fixed(byte *filePathPart1 = Encoding.UTF8.GetBytes("Images"))
            fixed(byte *filePathPart2 = Encoding.UTF8.GetBytes("novel-chan.png"))
            {
                var pathParts = stackalloc sbyte *[3] {
                    path, (sbyte *)filePathPart1, (sbyte *)filePathPart2
                };

                nChanFileLocation = Nrt_appendFilePath(3, pathParts);
            }

            fixed(IntPtr *pNChanRect = &nChanRect)
            {
                res = (NrtResult)Nrt_RenderingService_createImageRectWithFile(renderer, pNChanRect, nChanTransform, 3, nChanFileLocation, nChanColours);
            }

            // Creating InteractionRect
            NrtTransform interactTransform = new NrtTransform {
                position = nChanPosition, scale = nChanSize, rotation = 0
            };

            fixed(IntPtr *pInteractRect = &interactRect)
            {
                res = (NrtResult)Nrt_InteractionService_createBasicInteractionRect(input, interactTransform, 3, pInteractRect);
            }

            // Creating Ink Story
            if (inkServiceProvided == NRT_TRUE)
            {
                sbyte *storyLocation;

                fixed(byte *filePathPart1 = Encoding.UTF8.GetBytes("Scripts"))
                fixed(byte *filePathPart2 = Encoding.UTF8.GetBytes("story.json"))
                {
                    var pathParts = stackalloc sbyte *[3] {
                        path, (sbyte *)filePathPart1, (sbyte *)filePathPart2
                    };

                    storyLocation = Nrt_appendFilePath(3, pathParts);
                }

                Nrt_LoggingService_logInfoLine(console, storyLocation);
                string buffer = File.ReadAllText(Marshal.PtrToStringAnsi((IntPtr)storyLocation));

                fixed(IntPtr *pStory = &story)
                fixed(byte *pBuffer = Encoding.UTF8.GetBytes(buffer))
                {
                    res = (NrtResult)Nrt_InkService_createStory(ink, (sbyte *)pBuffer, pStory);
                }

                if (res == NRT_SUCCESS)
                {
                    Nrt_Story_resetState(story);
                }
                Nrt_Input_BasicInteractionRect_addInteraction(interactRect, &interactWithNovelChan, null);
            }

            // Setting up Scene Construction
            Nrt_NovelRunner_addSceneConstructionRequested(runner, &renderNovelChan, null);

            // Setting up Update methods
            Nrt_NovelRunner_addUpdate(runner, &moveNovelChan, null);

            // Run the novel!
            Nrt_NovelRunner_runNovel(runner);

            return(0);
        }