Open nb-programmer opened 2 years ago
To forgo the need for the user to explicitly set the format and player properties before calling loadBuffer
, we could maybe add an identify function to each of the format-specific player classes. Eg.
Screamtracker.prototype.identify(buffer)
which would return a boolean value depending on whether the contents of the buffer look like a S3M module - probably just by checking the file signature.
loadBuffer
could then call identify
for each format-specific class to autodetect the format contained within the buffer, and set the format and player properties accordingly.
This would probably be a more robust way for detecting the file type also for load
as currently it just makes a guess based on the provided URL. One advantage with the current method is, however, that it can be done already before the XHR.
The identify
function could be useful, but I feel relying on auto-detection for basically user-supplied data is a bad idea, as there could be false detections.
Perhaps the format argument can be made optional. If it is set, just assign the correct tracker class instance. Maybe another argument to prevent replacing the player property. If not set, we can try and guess using the identify methods
Added a function
loadBuffer(buffer)
to load Module data from an existing Buffer (useful for game engines that preload resources)Still some things pending in this PR that I can't do without asking you:
parse
function of the tracker classes require the use ofUint8Array
data, otherwise the function fails. Potential solution: Maybe a force cast can be done to the argumentloadBuffer
can be reused inload
I have also put these as TODO in the code that will need to be removed