Add Prop At

From Director Online Wiki
Jump to: navigation, search
--/******
--* ADD PROP AT
--****
--* @Param  : 'aPropList' <Proplist>
--* @Param  : 'aPos'      <Integer>
--* @Param  : 'aProp'     <Symbol>
--* @Param  : 'aValue'    <Any>
--* @Return : 't_plNew'   <Proplist>
--* @Note   : Proplist counterpart of addAt method.
--*           return a new proplist.
--***/
on mAddPropAt( aPropList, aPos, aProp, aValue )
  --
  -- return void or throw error !
  if Not(ilk(aPropList, #Proplist)) then return( Void )
  if Not(IntegerP(aPos)) then return( Void )
  if Not(SymbolP(aProp)) then return( Void )
  --
  t_nPropsCnt = aPropList.count()
  t_lExcept   = [#list, #Image, #instance] --...add new type here if they must be duplicate !
  t_plNew     = [:]
  --
  if (aPos > t_nPropsCnt) then
    t_plNew = aPropList.duplicate()
    repeat with i = (t_nPropsCnt + 1) to aPos
      --
      if (i = aPos) then
        if (t_lExcept).getPos(ilk(aValue)) then
          t_plNew.addProp(aProp, aValue.duplicate())
        else
          t_plNew.addProp(aProp, aValue)
        end if
      else
        t_plNew.addProp(#Void, Void)
      end if
      --
    end repeat
  else
    repeat with i = 1 to t_nPropsCnt
      --
      if (i = aPos) then
        if (t_lExcept).getPos(ilk(aValue)) then
          t_plNew.addProp(aProp, aValue.duplicate())
        else
          t_plNew.addProp(aProp, aValue)
        end if
      end if
      --
      if (t_lExcept).getPos(ilk(aPropList[i])) then
        t_plNew.addProp(aPropList.getPropAt(i), aPropList[i].duplicate())
      else
        t_plNew.addProp(aPropList.getPropAt(i), aPropList[i])
      end if
      --      
    end repeat
  end if
  --
  aValue    = Void
  aPropList = Void
  t_lExcept = Void
  --
  return( t_plNew )
end