/***************************************************************************************/ /* */ /* SCS editor Version 2 */ /* File : Module.pkg */ /* Version : 19 Mai 2000 */ /* Module Class struct and basic functions */ /* */ /***************************************************************************************/ /* data */ struct ModuleClass = [ MODCname : S , /* class name */ MODCfunc : S , /* class function */ MODCversion : [S r1] , /* class version */ MODCbitmapFile : S , /* main bitmap file */ MODCtreeBitmapFile : S , /* tree bitmap file */ MODCeditorNeeded : [S r1] , /* Files required by the editor */ MODCeditorScript : S , /* Script for the ditor */ MODChelpFile : S /* File which contains the help for the module */ ] mkModuleClass ;; var BLACKBOX_NAME = "BlackBox";; var BLACKBOX_FILEPATH = "data/def/blackbox.def";; fun _ExtractFilesFromScript (list) = if list==nil then nil else let list -> [first next] in if !strcmp (hd first) "_load" then let (hd tl first) -> strFile in let strlen strFile -> sl in (substr strFile 1 sl-2)::(_ExtractFilesFromScript next) else _ExtractFilesFromScript next ;; fun _ReMakeScript (l) = if l==nil then "" else let l -> [n nxt] in let strcatn "_load \""::n::"\"\n"::nil -> newpath in strcat newpath (_ReMakeScript nxt);; /*************************************************************************************** create a module Class ***************************************************************************************/ fun MODULECLASS_Extract (classL, classPath) = let getPathFile classPath "" -> [relPath _] in let switchstr classL "editorLoad" -> es in let if es==nil then _ExtractFilesFromScript strextr (getInfo classL "editorScript") else es -> editorScript in if editorScript == nil then ( ERRORS_AddError 1 41 (_locSCS "errorlabel-DMC-INVALID" classPath::nil); nil ) else let _RelativePathList relPath editorScript -> scriptFileList in let _RelativePathList relPath (getInfos classL "editorNeeded") -> neededFileList in let listcat scriptFileList neededFileList -> editorNeeded in let (getInfo classL "name") -> name in if name == nil then ( ERRORS_AddError 1 42 (_locSCS "errorlabel-DMC-INVALID" classPath::nil); nil ) else if (!strcmp name BLACKBOX_NAME) && (strcmp classPath strcat SCS_PATH BLACKBOX_FILEPATH) then nil /* do not load old black box dmc !!! */ else let (getInfos classL "version") -> version in if version == nil then ( ERRORS_AddError 1 43 (_locSCS "errorlabel-DMC-INVALID" classPath::nil); nil ) else let (getInfo classL "helpFile") -> helpfile in mkModuleClass [ name getInfo classL "func" version _RelativePath relPath getInfo classL "bitmap" _RelativePath relPath getInfo classL "tree" editorNeeded _ReMakeScript scriptFileList _RelativePath relPath helpfile ] ;; /*************************************************************************************** load a module class ***************************************************************************************/ fun MODULECLASS_Load (classPath)= let strextr _getpack _checkpack classPath -> classL in if classL == nil then { ERRORS_AddError 2 12 strcatn (_locSCS "errorlabel-12" nil)::": "::classPath::nil ; logScsError "MODULECLASS_Load" nil "Module class file not found" nil; nil } else MODULECLASS_Extract classL classPath ;; /*************************************************************************************** destroy a module class ***************************************************************************************/ fun MODULECLASS_Destroy (moduleClass) = 0 /* MAC ICI : ??? */ ;; /**************************************************************************************** * * Functions to get objects from the module class * ****************************************************************************************/ /* MAT ICI un peu crade, mais ca aide bien */ var IconesWidth = 25;; var IconesHeight = 25;; fun MODULECLASS_GetBitmap (chan, moduleClass) = if moduleClass.MODCbitmapFile == nil then nil else let BITMAP_Get moduleClass.MODCbitmapFile chan -> ic in let _GETalphaBitmapSize ic -> [w h] in if (ic==nil) || (w > IconesWidth) || (h > IconesHeight) then BITMAP_Get strcat SCS_PATH "bitmaps/defaulticon.bmp" chan else ic ;; fun MODULECLASS_GetTreeBitmap (chan, moduleClass) = /*BITMAP_Get moduleClass.MODCtreeBitmapFile chan*/ MODULECLASS_GetBitmap chan moduleClass ;; /**************************************************************************************** * * This function allow to get the editor script verifying that the needed files * are presents. If one or more of the needed files are not available, the returned * string is nil. * ****************************************************************************************/ fun MODULECLASS_GetScript (moduleClass) = let _missing_file moduleClass.MODCeditorNeeded -> missingFiles in if missingFiles==nil then moduleClass.MODCeditorScript else ( ERRORS_AddError 2 4 (_locSCS "errorlabel-MISSINGFILE" moduleClass.MODCname::missingFiles::nil); logScsError "MODULECLASS_GetScript" nil strcatn "The following files are required by the editor of the module class ":: moduleClass.MODCname::" and are not found: the editor will not be launched.":: "\n"::missingFiles::"\n"::nil nil; nil ) ;; fun MODULECLASS_GetVersionName (moduleClass) = strbuild (moduleClass.MODCname::moduleClass.MODCversion)::nil ;; fun MODULECLASS_GetName (class) = class.MODCname ;; fun MODULECLASS_GetFormatedVersion( version )= if version == nil then nil else if (tl version) != nil then (hd version)::"."::MODULECLASS_GetFormatedVersion tl version else (hd version)::nil ;; fun MODULECLASS_GetFormatedName (class)= strcatn (MODULECLASS_GetName class)::" "::MODULECLASS_GetFormatedVersion class.MODCversion ;;