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

Content Loading #12

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Content Loading #12

wants to merge 1 commit into from

Conversation

telrikk
Copy link
Collaborator

@telrikk telrikk commented Aug 22, 2024

Allow for content to be loaded from the file system.

import Activity from '../content-types/activity';
import Article from '../content-types/article';
const loadedActivities = import.meta.glob('../content/activities/*', { eager: true });
const loadedArticles = import.meta.glob('../content/articles/*', { eager: true });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since even a small game can have 100+ assets, I didn't want to specify each one individually. I also didn't want a single file per content type, since some content types might be large.

This pattern is what I came up with to allow for dynamic discovery and loading of files, although as a result I had to cheat a bit on the types.

this.apply = applyFunction;
}
// for deserialization purposes
scriptPath: string = '';
Copy link
Collaborator Author

@telrikk telrikk Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I'm thinking of to attach scripts. There are some pros and cons to this approach, but it lets us take advantage of TypeScript. It's a fairly common approach in engines, although we'll have fewer bells and whistles than say, Godot.

articles: Map<string, Article> = new Map<string, Article>();
activities: Map<string, Activity> = new Map<string, Activity>();

getArticle(id: string) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are for testing purposes (although they might also be useful in general.) I imagine this interface will grow a bit larger, e.g. getAllActivities().

@@ -0,0 +1,7 @@
{
"id": "test-article",
Copy link
Collaborator Author

@telrikk telrikk Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files are under /src, which is probably not ideal.

I tried /content with no success. I could also see /static/content, though I'm not sure what ramifications that has.

This feels like an "I don't know which config to change, and haven't figured it out yet."

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

Successfully merging this pull request may close these issues.

1 participant