I (and other people I've seen on this forum) have several things I'd like to be able to import into my games/toys and not copy-paste whole-cloth each time. Lines of JavaScript, lists of useful Squiffy attributes, that sort of thing.
Here's one solution I thought of. It has major problems.
@set
style attributes nor Javascript. It can only get {@attribute}
style attributes.
$.get ( 'textFileToImport.txt' ).done( //Do I really need the entire URL?
function (data, status, xhr) {
squiffy.ui.processText(data);
squiffy.story.go("section_name")
}
).fail(
function (data, status, xhr) {
squiffy.set("data", status);
}
);
I'd really rather there was an @import
solution. This is the only meager success I've had.
Ok, this works.
HOWever,
This still does not get JavaScript or @set Attributes. It only gets {@Attributes}.
In the console version of Squiffy, it does of course support @import
- and when I use Squiffy I do tend to use the console version. Of course, that doesn't help people using the editor...
I have looked into supporting @import
in the Squiffy Editor (at least the local version, rather than the web version) and it should be possible, but honestly my current changes to the editor for a potential new version are somewhat of a mess.
For the web version, having @import
support using a full URL might work, but then we get into XSS issues and I definitely do not want to potentially open up any security holes.
I would however like it to be able to support importing other Squiffy scripts you have saved in your account when online, and accessing them directly. I don't know how I would go about attempting to do that though.
Thanks for taking a stab at it, CrisisSDX!
Chat GPT provided this code, which allows Squiffy to process Javascript. It doesn't understand Squiffy enough to make it do both in the same $.get() function.
$.get("file:///C:/Users/mwvog/OneDrive/Desktop/Squiffy/Squiffy%20Attribute%20API/TextFileToImport.txt")
.done(function (data, status, xhr) {
try {
// Evaluate the text file as JavaScript code
eval(data);
} catch (e) {
console.error("Error evaluating JavaScript code from file:", e);
}
// Process the text content as usual
squiffy.story.go("test");
})
.fail(function (data, status, xhr) {
squiffy.set("data", status);
});
For the web version, having
@import
support using a full URL might work, but then we get into XSS issues and I definitely do not want to potentially open up any security holes.
Am I endangering textadventures.co.uk by using $.get
?
I would however like it to be able to support importing other Squiffy scripts you have saved in your account when online, and accessing them directly. I don't know how I would go about attempting to do that though.
To be intuitively consistent, you could have it import a saved .sq/.squiffy file from the same zipped folder.
@import Title.sq [[section_name]]: [passage_name]