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.
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.
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.
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.
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.