| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
|---|---|
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #include "Resources/BsScriptCodeImporter.h" |
| 4 | #include "Resources/BsScriptCode.h" |
| 5 | #include "FileSystem/BsDataStream.h" |
| 6 | #include "FileSystem/BsFileSystem.h" |
| 7 | #include "Resources/BsScriptCodeImportOptions.h" |
| 8 | |
| 9 | namespace bs |
| 10 | { |
| 11 | bool ScriptCodeImporter::isExtensionSupported(const String& ext) const |
| 12 | { |
| 13 | String lowerCaseExt = ext; |
| 14 | StringUtil::toLowerCase(lowerCaseExt); |
| 15 | |
| 16 | return lowerCaseExt == u8"cs"; |
| 17 | } |
| 18 | |
| 19 | bool ScriptCodeImporter::isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const |
| 20 | { |
| 21 | return true; // Plain-text so we don't even check for magic number |
| 22 | } |
| 23 | |
| 24 | SPtr<Resource> ScriptCodeImporter::import(const Path& filePath, SPtr<const ImportOptions> importOptions) |
| 25 | { |
| 26 | WString textData; |
| 27 | { |
| 28 | Lock fileLock = FileScheduler::getLock(filePath); |
| 29 | |
| 30 | SPtr<DataStream> stream = FileSystem::openFile(filePath); |
| 31 | textData = stream->getAsWString(); |
| 32 | } |
| 33 | |
| 34 | bool editorScript = false; |
| 35 | if (importOptions != nullptr) |
| 36 | { |
| 37 | SPtr<const ScriptCodeImportOptions> scriptIO = std::static_pointer_cast<const ScriptCodeImportOptions>(importOptions); |
| 38 | editorScript = scriptIO->editorScript; |
| 39 | } |
| 40 | |
| 41 | SPtr<ScriptCode> scriptCode = ScriptCode::_createPtr(textData, editorScript); |
| 42 | |
| 43 | const String fileName = filePath.getFilename(false); |
| 44 | scriptCode->setName(fileName); |
| 45 | |
| 46 | return scriptCode; |
| 47 | } |
| 48 | |
| 49 | SPtr<ImportOptions> ScriptCodeImporter::createImportOptions() const |
| 50 | { |
| 51 | return bs_shared_ptr_new<ScriptCodeImportOptions>(); |
| 52 | } |
| 53 | } |