-- <<<- ------------------------------------------------------------------------ ------------------------------------------------------------------------ -- Load this build script "!mkrooms.sx" into a fresh invocation of ScriptX, -- to build all the Dream rooms in the "rooms" folder. -- For each sub-folder "rooms/", it creates a TitleContainer -- named "rooms/.sxt", holding the room description and media. ------------------------------------------------------------------------ -- Load the dream.sxl library and the DreamBuilder tool module. fileIn theScriptDir \ name: "builder.sx" \ debugInfo: false in module DreamBuilder ------------------------------------------------------------------------ -- Declare a global that may have been defined elsewhere. global theRoomsToDo ------------------------------------------------------------------------ ( local startTime := theCalendarClock.time -- Get ahold of the rooms folder. local roomsDir := spawn theScriptDir "rooms" local roomsOutDir := spawn (parentDir theScriptDir) "rooms" -- Subdue the garbage collector. setGCIncrement 30 -- If theRoomsToDo is defined, then it's a list of rooms to build. -- Otherwise build all of the rooms in the "rooms" folder. -- Each room has a "!mkroom.sx" script that loads the Dream library, -- defines theRoomsToDo to contain the name of the room folder, and -- runs this "!mkrooms.sx" script. By dragging and dropping the -- "!mkroom.sx" script from a particular room into ScriptX, you can -- build just that room. local roomNames if ((isDefined theRoomsToDo) and (theRoomsToDo != undefined)) then ( roomNames := theRoomsToDo ) else ( roomNames := getContents roomsDir ) -- Compile each of the rooms in the roomNames array. for roomName in roomNames do ( -- Only process folders, ignore other files. if (isDir roomsDir roomName) do ( -- Get ahold of the room sub-folder. local roomDir := spawn roomsDir roomName -- Get a list of the files in roomDir. local roomFiles := getContents roomDir | (str -> str as NameClass) -- You can prevent a room from being built by putting a file -- called "ignore" into its folder. if (isMember roomFiles @ignore) then ( print #("Ignoring room", roomName) ) else ( print #("Making room", roomName) -- The name of the room TitleContainer is the folder name -- with the suffix ".sxt". local theRoomFileName := (roomName + ".sxt") print #(" creating", theRoomFileName) -- Create the new room TitleContainer. local tc := new TitleContainer \ dir: roomsOutDir \ path: theRoomFileName \ targetCollection: #(:) \ mode: @create -- This is the container to store the stuff in. local cont := tc -- Make a module for the room, whose name is "DreamRoom" -- plus the room name. local modName := ("DreamRoom" + roomName) as NameClass local theRoomModule := makeDreamPluginModule modName -- Import the code and media specified in the "database.sx" file -- from the roomDir. The database is loaded in theRoomModule, -- and returns a keyed list specifying the media to be imported -- and stored in the container tc. -- The last argument is the inner startup function, compiled in -- theRoomModule, which is stored in the tc container. local database := importDreamPluginDatabase \ "database.sx" \ roomDir \ tc \ theRoomModule \ (fileIn "(tc -> importFromTitleContainer Room tc )" module: theRoomModule) -- Copy the links from the database to the title container, -- making an empty one if there isn't one in the database. local links := database[@links] if (links == empty) do (links := #(:)) tc[@links] := links -- Copy the products from the database to the title container, -- making an empty one if there isn't one in the database. local products := database[@products] if (products == empty) do (products := #(:)) tc[@products] := products -- Remember the room name. roomName := roomName as NameClass database[@name] := roomName tc[@name] := roomName -- Make a room icon from the first image (if any). local bb := new Rect x2: 64 y2: 48 local icon := new BitmapSurface \ bbox: bb \ colormap: theDefault8Colormap erase icon whiteBrush local bm := getFirst tc[@images] if (bm != empty) do ( local bmbb := bm.bbox local bmw := bmbb.width local bmh := bmbb.height local mat := new TwoDMatrix \ a: 0.1 \ d: 0.1 transfer icon (bm as BitmapSurface) icon mat ) -- Store the icon in the title container. tc[@icon] := (icon as Bitmap) print #(" icon", icon) -- Make it nice for the next person. garbageCollect() update tc close tc ) ) ) local endTime := theCalendarClock.time print #("Time for !mkrooms", endTime - startTime) ) ------------------------------------------------------------------------ ok -- >>>