-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Content Loading #12
Conversation
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 }); |
There was a problem hiding this comment.
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 = ''; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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."
Allow for content to be loaded from the file system.