-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1103 from nokotan/v6_develop_add_tests
テストコードの追加
- Loading branch information
Showing
81 changed files
with
3,706 additions
and
2,151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
mergeInto(LibraryManager.library, { | ||
siv3dDecodeAudioFromFileAsync: function(filePath, callback, arg) { | ||
const path = UTF8ToString(filePath, 1024); | ||
const fileBytes = FS.readFile(path); | ||
|
||
const onSuccess = function(decoded) { | ||
const leftDataBuffer = Module["_malloc"](decoded.length * 4); | ||
HEAPF32.set(decoded.getChannelData(0), leftDataBuffer>>2); | ||
|
||
let rightDataBuffer; | ||
|
||
if (decoded.numberOfChannels >= 2) { | ||
rightDataBuffer = Module["_malloc"](decoded.length * 4); | ||
HEAPF32.set(decoded.getChannelData(1), rightDataBuffer>>2); | ||
} else { | ||
rightDataBuffer = leftDataBuffer; | ||
} | ||
|
||
HEAP32[(arg>>2)+0] = leftDataBuffer; | ||
HEAP32[(arg>>2)+1] = rightDataBuffer; | ||
HEAPU32[(arg>>2)+2] = decoded.sampleRate; | ||
HEAPU32[(arg>>2)+3] = decoded.length; | ||
|
||
{{{ makeDynCall('vi', 'callback') }}}(arg); | ||
_siv3dMaybeAwake(); | ||
}; | ||
|
||
const onFailure = function() { | ||
HEAP32[(arg>>2)+0] = 0; | ||
HEAP32[(arg>>2)+1] = 0; | ||
HEAPU32[(arg>>2)+2] = 0; | ||
HEAPU32[(arg>>2)+3] = 0; | ||
|
||
{{{ makeDynCall('vi', 'callback') }}}(arg); | ||
_siv3dMaybeAwake(); | ||
} | ||
|
||
Module["SDL2"].audioContext.decodeAudioData(fileBytes.buffer, onSuccess, onFailure); | ||
}, | ||
siv3dDecodeAudioFromFileAsync__sig: "viii", | ||
siv3dDecodeAudioFromFileAsync__deps: [ "$AL", "$FS", "siv3dMaybeAwake" ], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
mergeInto(LibraryManager.library, { | ||
siv3dSetClipboardText: function(ctext) { | ||
const text = UTF8ToString(ctext); | ||
|
||
siv3dRegisterUserAction(function () { | ||
navigator.clipboard.writeText(text); | ||
}); | ||
}, | ||
siv3dSetClipboardText__sig: "vi", | ||
siv3dSetClipboardText__proxy: "sync", | ||
siv3dSetClipboardText__deps: [ "$siv3dRegisterUserAction" ], | ||
|
||
$siv3dGetClipboardTextImpl: function(wakeUp) { | ||
if (!navigator.clipboard.readText) { | ||
err("Reading clipboard is not allowed in this browser."); | ||
wakeUp(0); | ||
return; | ||
} | ||
|
||
siv3dRegisterUserAction(function () { | ||
navigator.clipboard.readText() | ||
.then(function(str) { | ||
const strPtr = allocate(intArrayFromString(str), ALLOC_NORMAL); | ||
wakeUp(strPtr); | ||
}) | ||
.catch(function(_) { | ||
wakeUp(0); | ||
}); | ||
}); | ||
}, | ||
$siv3dGetClipboardTextImpl__deps: [ "$siv3dRegisterUserAction" ], | ||
|
||
#if ASYNCIFY | ||
siv3dGetClipboardText: function() { | ||
return Asyncify.handleSleep(siv3dGetClipboardTextImpl); | ||
}, | ||
siv3dGetClipboardText__sig: "iv", | ||
siv3dGetClipboardText__deps: [ "$siv3dGetClipboardTextImpl", "$Asyncify" ], | ||
#elif PROXY_TO_PTHREAD | ||
siv3dGetClipboardText: function(ctx) { | ||
siv3dGetClipboardTextImpl(function () { | ||
Module["_emscripten_proxy_finish"](ctx); | ||
}); | ||
}, | ||
siv3dGetClipboardText__sig: "ii", | ||
siv3dGetClipboardText__deps: [ "$siv3dGetClipboardTextImpl" ], | ||
#else | ||
siv3dGetClipboardText: function() { | ||
return 0; | ||
}, | ||
siv3dGetClipboardText__sig: "iv", | ||
#endif | ||
|
||
siv3dGetClipboardTextAsync: function(callback, promise) { | ||
siv3dRegisterUserAction(function () { | ||
if (!navigator.clipboard.readText) { | ||
err("Reading clipboard is not allowed in this browser."); | ||
{{{ makeDynCall('vii', 'callback') }}}(0, promise); | ||
return; | ||
} | ||
|
||
navigator.clipboard.readText() | ||
.then(function(str) { | ||
const strPtr = allocate(intArrayFromString(str), ALLOC_NORMAL); | ||
{{{ makeDynCall('vii', 'callback') }}}(strPtr, promise); | ||
Module["_free"](strPtr); | ||
}) | ||
.catch(function (e) { | ||
{{{ makeDynCall('vii', 'callback') }}}(0, promise); | ||
}); | ||
}); | ||
}, | ||
siv3dGetClipboardTextAsync__sig: "vii", | ||
siv3dGetClipboardTextAsync__deps: [ "$siv3dRegisterUserAction" ], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
mergeInto(LibraryManager.library, { | ||
$siv3dInputElement: null, | ||
$siv3dDialogFileReader: null, | ||
$siv3dDownloadLink: null, | ||
|
||
siv3dInitDialog: function() { | ||
siv3dInputElement = document.createElement("input"); | ||
siv3dInputElement.type = "file"; | ||
|
||
siv3dDialogFileReader = new FileReader(); | ||
siv3dDownloadLink = document.createElement("a"); | ||
}, | ||
siv3dInitDialog__sig: "v", | ||
siv3dInitDialog__deps: [ "$siv3dInputElement", "$siv3dDialogFileReader", "$siv3dDownloadLink" ], | ||
|
||
$siv3dOpenDialogAsync: function(filter, callback, futurePtr, acceptMuilitple) { | ||
siv3dInputElement.accept = filter; | ||
siv3dInputElement.multiple = acceptMuilitple; | ||
|
||
function cancelHandler(e) { | ||
{{{ makeDynCall('viii', 'callback') }}}(0, 0, futurePtr); | ||
_siv3dMaybeAwake(); | ||
} | ||
|
||
// Using addEventListener works in Firefox | ||
// Set 'once' to automatically delete the handler when the event fires | ||
siv3dInputElement.addEventListener('cancel', cancelHandler, { once: true }); | ||
|
||
siv3dInputElement.oninput = async function(e) { | ||
// Delete event handler if cancel event is not fired | ||
siv3dInputElement.removeEventListener('cancel', cancelHandler); | ||
|
||
// Workaround for event firing | ||
const files = [...e.target.files]; | ||
e.target.value = ''; | ||
|
||
if (files.length < 1) { | ||
callback(0, 0, futurePtr); | ||
_siv3dMaybeAwake(); | ||
return; | ||
} | ||
|
||
let filePathes = []; | ||
const sp = stackSave(); | ||
|
||
for (let file of files) { | ||
await new Promise((resolve) => { | ||
const filePath = "/tmp/" + file.name; | ||
|
||
siv3dDialogFileReader.addEventListener("load", function onLoaded() { | ||
FS.writeFile(filePath, new Uint8Array(siv3dDialogFileReader.result)); | ||
|
||
const namePtr = allocate(intArrayFromString(filePath), ALLOC_STACK); | ||
filePathes.push(namePtr); | ||
|
||
siv3dDialogFileReader.removeEventListener("load", onLoaded); | ||
resolve(); | ||
}); | ||
|
||
siv3dDialogFileReader.readAsArrayBuffer(file); | ||
}); | ||
} | ||
|
||
const filePathesPtr = stackAlloc(filePathes.length * {{{ POINTER_SIZE }}}); | ||
|
||
for (let i = 0; i < filePathes.length; i++) { | ||
setValue(filePathesPtr + i * {{{ POINTER_SIZE }}}, filePathes[i], "i32"); | ||
} | ||
|
||
callback(filePathesPtr, filePathes.length, futurePtr); | ||
|
||
stackRestore(sp); | ||
_siv3dMaybeAwake(); | ||
}; | ||
|
||
siv3dRegisterUserAction(function() { | ||
siv3dInputElement.click(); | ||
}); | ||
}, | ||
$siv3dOpenDialogAsync__deps: [ "$siv3dInputElement", "$siv3dDialogFileReader", "$siv3dRegisterUserAction", "$FS", "siv3dMaybeAwake" ], | ||
siv3dOpenDialogAsync: function(filterStr, callback, futurePtr, acceptMuilitple) { | ||
const filter = UTF8ToString(filterStr); | ||
const callbackFn = {{{ makeDynCall('viii', 'callback') }}}; | ||
siv3dOpenDialogAsync(filter, callbackFn, futurePtr, !!acceptMuilitple); | ||
}, | ||
siv3dOpenDialogAsync__sig: "vii", | ||
siv3dOpenDialogAsync__deps: [ "$siv3dOpenDialogAsync" ], | ||
|
||
$siv3dSaveFileBuffer: null, | ||
$siv3dSaveFileBufferWritePos: 0, | ||
$siv3dDefaultSaveFileName: null, | ||
|
||
siv3dDownloadFile: function(filePathPtr, fileNamePtr, mimeTypePtr) { | ||
const filePath = UTF8ToString(filePathPtr); | ||
const fileName = UTF8ToString(fileNamePtr); | ||
const mimeType = mimeTypePtr ? UTF8ToString(mimeTypePtr) : "application/octet-stream"; | ||
const fileData = FS.readFile(filePath); | ||
|
||
const blob = new Blob([ fileData ], { type: mimeType }); | ||
|
||
siv3dDownloadLink.href = URL.createObjectURL(blob); | ||
siv3dDownloadLink.download = fileName; | ||
|
||
siv3dRegisterUserAction(function() { | ||
siv3dDownloadLink.click(); | ||
}); | ||
}, | ||
siv3dDownloadFile__sig: "viii", | ||
siv3dDownloadFile__deps: [ "$siv3dRegisterUserAction" ], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
mergeInto(LibraryManager.library, { | ||
$siv3dRegisterDragEnter: function(callback) { | ||
Module["canvas"]["ondragenter"] = function (e) { | ||
e.preventDefault(); | ||
|
||
const types = e.dataTransfer.types; | ||
|
||
if (types.length > 0) { | ||
const adusted = siv3dAdjustPoint(e.pageX, e.pageY); | ||
callback(types[0] === 'Files' ? 1 : 0, adusted.x, adusted.y); | ||
} | ||
}; | ||
}, | ||
siv3dRegisterDragEnter: function(ptr) { | ||
siv3dRegisterDragEnter({{{ makeDynCall('viii', 'ptr') }}}); | ||
}, | ||
siv3dRegisterDragEnter__deps: [ "$siv3dRegisterDragEnter" ], | ||
siv3dRegisterDragEnter__sig: "vi", | ||
|
||
$siv3dRegisterDragUpdate: function(callback) { | ||
Module["canvas"]["ondragover"] = function (e) { | ||
e.preventDefault(); | ||
const adusted = siv3dAdjustPoint(e.pageX, e.pageY); | ||
callback(adusted.x, adusted.y); | ||
}; | ||
}, | ||
siv3dRegisterDragUpdate: function(ptr) { | ||
siv3dRegisterDragUpdate({{{ makeDynCall('vii', 'ptr') }}}); | ||
}, | ||
siv3dRegisterDragUpdate__sig: "vi", | ||
siv3dRegisterDragUpdate__deps: [ "$siv3dRegisterDragUpdate", "$siv3dAdjustPoint" ], | ||
|
||
$siv3dRegisterDragExit: function(callback) { | ||
Module["canvas"]["ondragexit"] = function (e) { | ||
e.preventDefault(); | ||
callback(); | ||
}; | ||
}, | ||
siv3dRegisterDragExit: function(ptr) { | ||
siv3dRegisterDragExit({{{ makeDynCall('v', 'ptr') }}}); | ||
}, | ||
siv3dRegisterDragExit__deps: [ "$siv3dRegisterDragExit" ], | ||
siv3dRegisterDragExit__sig: "vi", | ||
|
||
$siv3dDragDropFileReader: null, | ||
$siv3dRegisterDragDrop: function(callback) { | ||
Module["canvas"]["ondrop"] = function (e) { | ||
e.preventDefault(); | ||
|
||
const items = e.dataTransfer.items; | ||
const adusted = siv3dAdjustPoint(e.pageX, e.pageY); | ||
|
||
if (items.length == 0) { | ||
return; | ||
} | ||
|
||
if (items[0].kind === 'string') { | ||
items[0].getAsString(function(str) { | ||
const strPtr = allocate(intArrayFromString(str), ALLOC_NORMAL); | ||
callback(strPtr, adusted.x, adusted.y); | ||
Module["_free"](strPtr); | ||
}) | ||
} else if (items[0].kind === 'file') { | ||
const file = items[0].getAsFile(); | ||
|
||
if (!siv3dDragDropFileReader) { | ||
siv3dDragDropFileReader = new FileReader(); | ||
} | ||
|
||
const filePath = "/tmp/" + file.name; | ||
|
||
siv3dDragDropFileReader.addEventListener("load", function onLoaded() { | ||
FS.writeFile(filePath, new Uint8Array(siv3dDragDropFileReader.result)); | ||
|
||
const namePtr = allocate(intArrayFromString(filePath), ALLOC_NORMAL); | ||
callback(namePtr, adusted.x, adusted.y); | ||
|
||
siv3dDragDropFileReader.removeEventListener("load", onLoaded); | ||
}); | ||
|
||
siv3dDragDropFileReader.readAsArrayBuffer(file); | ||
} | ||
}; | ||
}, | ||
siv3dRegisterDragDrop: function(ptr) { | ||
siv3dRegisterDragDrop({{{ makeDynCall('viii', 'ptr') }}}); | ||
}, | ||
siv3dRegisterDragDrop__sig: "vi", | ||
siv3dRegisterDragDrop__deps: [ "$siv3dRegisterDragDrop", "$siv3dDragDropFileReader", "$FS" ], | ||
}); |
Oops, something went wrong.