Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommended design for Integration for a Godot Engine #222

Open
fire opened this issue Aug 5, 2023 · 0 comments
Open

Recommended design for Integration for a Godot Engine #222

fire opened this issue Aug 5, 2023 · 0 comments

Comments

@fire
Copy link

fire commented Aug 5, 2023

Hi,

I was looking into integrating this into an Godot Engine project. Looking for advice for what longtail apis to call in c.

Questions:

  1. What longtail api calls should be used
  2. How do you make the web to local url transition
  3. Suggest any features I can add to this longtail repo

Some ai generated designs

Here's how you might implement a custom protocol handler for longtail://v-sekai.org/1234EAF in your V-Sekai project without markdown headers.

First, you'll need to register your custom protocol handler. This is typically done at application startup. The exact method will depend on your programming language and framework, but here's an example in JavaScript using Electron:

const { app, protocol } = require('electron')

app.on('ready', () => {
  protocol.registerHttpProtocol('longtail', (request, callback) => {
    // Implementation goes here...
  })
})

Next, you'll need to implement the protocol handler. This function will be called whenever a URL with your custom protocol is accessed. It should parse the URL and perform the appropriate action, such as fetching data from a remote server or accessing a local file path.

Here's an example of how you might implement this in Node.js:

const url = require('url')

protocol.registerHttpProtocol('longtail', (request, callback) => {
  const parsedUrl = url.parse(request.url)
  const filePath = path.normalize(`${__dirname}/${parsedUrl.hostname}${parsedUrl.pathname}`)

  callback({ path: filePath })
})

In this example, the hostname and pathname parts of the URL are combined to form a local file path. The path.normalize function is used to ensure that the path is correctly formatted for the current operating system.

Once the protocol handler is registered and implemented, you can use URLs with your custom protocol anywhere in your application. For example, you might use it to fetch game content like so:

fetch('longtail://v-sekai.org/1234EAF')
  .then(response => response.text())
  .then(content => {
    // Do something with the content...
  })

Remember, the ability to nest folders in longtail depends on how you've implemented the protocol handler. If it interprets slashes (/) in the URL as directory separators, then it should be able to handle nested folders.

As for implementing this in Godot Engine 4.0 using GDScript, unfortunately, Godot does not currently support custom protocol handlers directly in GDScript. You would likely need to create a GDExtension plugin in C++ to handle this functionality.

@fire fire changed the title Recommended design for Integration for a Godot Engine addon Recommended design for Integration for a Godot Engine Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant