-- <<<- ------------------------------------------------------------------------ -- This script uses the DTK to read in a Director file describing puppet -- parts, and writes out a ScriptX file containing the puppet part -- data structures, which can be imported later without using the DTK. ------------------------------------------------------------------------ in module Scratch global theDirToDo if (not (isDefined theDirToDo)) do ( theDirToDo := theScriptDir ) ------------------------------------------------------------------------ ( print "loading puppet importer" fileIn theScriptDir name: "pupimp.sx" local dir := theDirToDo local fileName := getLast (dir as Sequence) local dirFileName := fileName + ".dir" local filePath := dir as Array append filePath dirFileName print #("importing director file", filePath) local parts := importMedia theImportExportEngine \ filePath \ @Metaphor @Director @PuppetParts local outputFileName := fileName + ".sx" if (isFile dir outputFileName) do ( print #("deleting old output file", outputFileName) delete dir outputFileName ) print #("creating output file", outputFileName) outputFileName := createFile dir outputFileName @text local out := getStream dir outputFileName @writable -- parts ::= #(sequenceName: frameSequence, ...) -- sequenceName ::= from score frame label -- frameSequence ::= #(frame, ...) -- frame ::= #(bm, firstChannel, lastChannel, hotName, joints, sound, -- hotSpot, soundName) -- bm ::= bitmap composit of all bitmaps in frame -- firstChannel ::= first channel with bitmap -- lastChannel ::= last channel with bitmap -- hotName ::= name of first joint (hot spot), used as origin of bm -- joints ::= #(jointName: joint, ...) -- jointName ::= from rect cast member name -- joint ::= #(jointPoint, jointChannel, jointRect) -- jointPoint ::= registration point at center of rectangle, -- relative to bm origin 0,0 -- jointChannel ::= channel number of rectangle in score -- jointRect ::= bounding box of rectangle in score -- sound ::= AudioStream or undefined -- hotSpot ::= point, hot spot location in score -- soundName ::= fileName or undefined local lastSequence := getLast parts print #("writing parts") format out " -- Begin output of dir2sx.sx custom director importer. #( -- begin parts %1\r" \ #(outputFileName) forEachBinding parts (sequenceName frameSequence xxx -> print #("writing frame sequence", sequenceName) format out " %1: #( -- begin sequence %1\r" \ #(sequenceName) local lastFrame := getLast frameSequence forEach frameSequence (frame xxx -> local bm := frame[1] local firstChannel := frame[2] local lastChannel := frame[3] local hotName := frame[4] local joints := frame[5] local sound := frame[6] local hotSpot := frame[7] local frameNumber := frame[8] local soundName := frame[9] writeString out " #( -- begin frame\r" local bmNumber := frameNumber as String repeat while ((size bmNumber) < 4) do ( prepend bmNumber "0"[1] ) local shortFileName := getRange fileName 1 4 local bmName := shortFileName + bmNumber format out " (importImage %1 whiteColor %2 %3), -- bitmap\r" \ #(bmName, hotSpot.x, hotSpot.y) format out " %1, %2, -- firstChannel lastChannel\r" \ #(firstChannel, lastChannel) format out " %1, -- hotName\r" \ #(hotName) if ((size joints) == 0) then ( writestring out " #(:), -- no joints\r" ) else ( writeString out " #( -- begin joints\r" local lastJoint := getLast joints forEachBinding joints (jointName joint xxx -> local jointPoint := joint[1] local jointChannel := joint[2] local jointRect := joint[3] format out " %1: #( -- begin joint\r" \ #(jointName) format out " new Point x: %1 y: %2, -- jointPoint\r" \ #(jointPoint.x, jointPoint.y) format out " %1, -- jointChannel\r" \ #(jointChannel) format out " new Rect x1: %1 y1: %2 x2: %3 y2: %4 -- jointRect\r" \ #(jointRect.x1, jointRect.x2, jointRect.y1, jointRect.y2) format out " )%1 -- end joint\r" \ #(if (joint == lastJoint) then "" else ",") \ #(@unadorned) ) ok writeString out " ), -- end joints\r" ) if ((sound != undefined) and (soundName != undefined)) then ( format out " (importSound %1), -- sound\r" \ #(soundName) ) else ( writeString out " undefined, -- sound\r" ) format out " new Point x: %1 y: %2, -- hotSpot\r" \ #(hotSpot.x, hotSpot.y) format out " %1, -- frameNumber\r" \ #(frameNumber) format out " %1 -- soundName\r" \ #(soundName) format out " )%1 -- end frame\r" \ #(if (frame == lastFrame) then "" else ",") \ #(@unadorned) ) ok format out " )%1 -- end sequence %2\r" \ #(if (frameSequence == lastSequence) then "" else ",", sequenceName) \ #(@unadorned, @normal) ) ok format out " ) -- end parts %1 -- End output of dir2sx.sx custom director importer. " \ #(outputFileName) plug out print "done!" ok ) ------------------------------------------------------------------------ -- >>>