Serialize, Deserialize D11&MX2004

From Director Online Wiki
Jump to: navigation, search

Director Members

The objects are inspected by the use of a simple loop that parses all the movie castlib and within them, all the members are checked.

The correct type is then checked by:

  member(membernum, castlibnum).type

There is an huge quantity of diferent types of members, and the most basic/usual ones are covered here. Feel free to add new ones.

Common properties for all cast members:

  • scripttext
  • scriptsyntax
  • name
  • type

#empty

Castmembers with this type are, as the name implies... empty. Nothing to check here.

#transition

Castmembers with #transition type have the following properties:

  • transitiontype
  • duration
  • chunksize
  • changearea

There are also transitions that are from an special xtra, but those are not covered here at the moment.

To create a member of type transition with lingo:

  themember = puppetTransition( thetype, theduration, thechunk, thearea )

To add a transtion to the score, while in a record score sequence:

  _movie.frametransition = themember

#script

This are all the scripts on the castlibs. They have the following properties:

  • scripttext
  • scripttype
  • scriptsyntax

#text

This is one of the most complex members, and the source of many issues. Nevertheless, they have the following properties:

  • font
  • fontsize
  • fontstyle
  • color
  • charspacing
  • alignment
  • bgcolor
  • antialias
  • kerning
  • kerningthreshold
  • scrolltop
  • rect
  • displaymode
  • boxtype
  • text

And possibly many more properties.

#shape

The shape properties are:

  • color
  • rect
  • shapetype
  • linesize
  • filled
  • pattern

#bitmap

This kind of members have reasonable "Bitmap Object" help entry. However, either it's outdated, or something is amiss on it. Several properties shown there, simply returned VOID.

This is the ones that work correctly from the list:

  • alphathreshold
  • type
  • depth
  • dither
  • image
  • imageCompression
  • imageQuality
  • picture
  • rect
  • trimWhiteSpace
  • useAlpha

Exporting Castlibs

To be able to export the castlibs, there are some requirements:

  • Ways to export the member content (ex. for images it's possible to use sharpExport for instance);
  • Ways to save files with data (ex. to save the object properties it's possible to use FileIO or some other way);

Requirements:

on exportAll( outputdir )
  if voidp(outputdir) then
    outputdir = "temp"
  end if
 
  put "----begin"
 
  txt = ""
  n = 1
 
  scripts = []
 
  repeat with n = 1 to the number of castlibs  
 
      repeat with m = 1 to castlib(n).member.count
 
        t = member(m,n)
 
        case t.type of
          #transition:
            txt = txt & "[ 'castlibname': '" & castlib(n).name & "', 'name': '" & t.name & "', " & \
            "'transitiontype': " & t.transitiontype & ", " & \
                          "'duration': " & t.duration & ", " & \
                          "'changearea': " & t.changearea & ", " & \
                          "'chunksize': " & t.changearea & "]" & RETURN            
          #shape:
            txt = txt & "[ 'castlibname': '" & castlib(n).name & "', 'name': '" & t.name & "', " & \
                          "'color': " & t.color & ", " & \
                          "'rect': " & t.rect & ", " & \
                          "'shapetype': " & t.shapetype & ", " & \
                          "'linesize': " & t.linesize & ", " & \
                          "'filled': " & t.filled & ", " & \
                          "'pattern': " & t.pattern & "]" & RETURN   
          #script:
            scripts.add(t.scripttext)            
            txt = txt & "[ 'castlibname': '" & castlib(n).name & "', 'name': '" & t.name & "', " & \
                          "'scripttype': " & t.scripttype & ", " & \
                          "'scriptsyntax': " & t.scriptsyntax & ", " & \
            "'scriptnum': " & scripts.count() & "]" & RETURN   
          #text:
            scripts.add(t.text)                       
            txt = txt & "[ 'castlibname': '" & castlib(n).name & "', 'name': '" & t.name & "', " & \
                          "'textnum': " & scripts.count() & ", " & \
                          "'font': " & t.font & ", " & \
                          "'fontsize': " & t.fontsize & ", " & \
                          "'fontstyle': " & t.fontstyle & ", " & \
                          "'color': " & t.color & ", " & \
                          "'charspacing': " & t.charspacing & ", " & \
                          "'alignment': " & t.alignment & ", " & \
                          "'bgcolor': " & t.bgcolor & ", " & \
                          "'antialias': " & t.antialias & ", " & \
                          "'kerning': " & t.kerning & ", " & \
                          "'kerningthreshold': " & t.kerningthreshold & ", " & \
                          "'scrolltop': " & t.scrolltop & ", " & \
                          "'rect': " & t.rect & ", " & \
                          "'displaymode': " & t.displaymode & ", " & \
                          "'boxtype': " & t.boxtype & "]" & RETURN   
          #bitmap:
            thefilename = castlib(n).name & "_" & m & "_" & t.name & ".png"
 
            sharp = new (xtra "SharpExport")
            errCode = sharp.exportPNG(t,  the pathname & outputdir & "\" & thefilename )            
            sharp = VOID
 
            if errCode = 0 then              
              txt = txt & "[ 'castlibname': '" & castlib(n).name & "', 'name': '" & t.name & "', " & \
                          "'alphathreshold': " & t.alphathreshold & ", " & \
                          "'depth': " & t.depth & ", " & \
                          "'dither': " & t.dither & ", " & \
                          "'imageCompression': " & t.imageCompression & ", " & \
                          "'imageQuality': " & t.imageQuality & ", " & \
                          "'rect': " & t.rect & ", " & \
                          "'trimWhiteSpace': " & t.trimWhiteSpace & ", " & \
                          "'useAlpha': " & t.useAlpha & ", " & \
                          "'filename': " & thefilename & "]" & RETURN                 
            else
              _player.alert("error exporting image")
              halt
            end if
          #empty:
            -- nothing
          otherwise:
            put t.type
        end case
 
      end repeat    
 
  end repeat
 
  repeat with cnt = 1 to count(scripts)
    file_put_contents( the pathname & outputdir & "\script" & cnt & ".txt", scripts[cnt])
  end repeat  
 
  file_put_contents( the pathname & outputdir & "\" & "thememberslist.txt", txt)  
 
  put "----finito"
 
end on

Next is then, the exporting of the score...

Exporting the Score

The score is constituted of frames and channels. The frames are the "timeline", while the channels are the "layers".

There are special channels in Director. This channels are accessible with:

_movie.framePallete
_movie.frameSound1
_movie.frameSound2
_movie.tempo
_movie.transition
_movie.frameScript

The exporter will only try to export the framescript and the normal channels.

-- script heavily inspired by Zav scoredump/restore scripts
 
on exportScore( theframe )
 
  outputdir = "testing"
 
  if voidp(theframe) then
    thestart = 1
    theend = _movie.lastframe
  else
    thestart = theframe
    theend = theframe
  end if
 
  thescore = []
 
  -- we need a beginrecording so that we can move around the frames without executing the code under them
  beginrecording()
 
    repeat with cnt = thestart to theend
 
      go cnt
 
      flag = false
 
      theframe = [:]
 
      theframe["framenum"] = cnt      
      theframe["framescript"] = _movie.framescript
 
      if _movie.framescript <> 0 then
        -- some weird numbers appear here in the framescript_member, we will see... and pray...
        theframe["framescript_member"] = (_movie.framescript.member).number
        theframe["framescript_castlib"] = (_movie.framescript.member).castlibnum
        flag = true  
      end if
 
      theframe["sprites"] = []
 
      repeat with n = 1 to _movie.lastChannel
        if sprite(n).startframe = cnt then
          put "Frame: " & cnt & " -> " & n
 
          theframe["sprites"].add( [ #spriteNum: sprite(n).spriteNum, \
               #name: sprite(n).name, \
               #membernumber: (sprite(n).member).number, \
               #memberclasslib: (sprite(n).member).castlibnum, \
               #startFrame: sprite(n).startFrame, \
               #endFrame: sprite(n).endFrame, \
               #editable: sprite(n).editable, \
               #visible: sprite(n).visible, \
               #color: hexstring(sprite(n).color), \
               #bgColor: hexstring(sprite(n).bgcolor), \
               #blend: sprite(n).blend, \
               #ink: sprite(n).ink, \
               #locH: sprite(n).locH, \
               #locV: sprite(n).locV, \
               #width: sprite(n).width, \
               #height: sprite(n).height, \
               #scriptInstanceList: sprite(n).scriptInstanceList ] )          
          flag = true
        end if        
      end repeat
 
      if flag then
 
        file_put_contents( the pathname & outputdir & "\" & "score_" & cnt & ".txt", string(theframe) )  
 
      end if
 
    end repeat
 
  endrecording()
 
 
end