Пример #1
0
bool CharacterManager::Save()
{
	moPropBagRef propBag( f_propBagName );
	propBag.NewProp();
	SaveCharacters( propBag );
	return Common::SaveBagToFile( "characters.conf", propBag );
}
Пример #2
0
bool CharacterManager::Load()
{
	f_chars.clear();
	moPropBagRef propBag( f_propBagName );
	if( !Common::LoadBagFromFile( "characters.conf", propBag ) ) return false;
	LoadCharacters( propBag );
	return true;
}
Пример #3
0
void CharacterManager::SaveCharacters( moPropBagRef& charBag )
{
	moPropArrayRef	array("CHARACTERS");
	array.NewProp();

	int array_index = 0;
	for( auto ch : f_chars )
	{
		moPropBagRef propBag( "CHARACTER" );
		propBag.NewProp();
		ch->Save( propBag );
		array.Set( array_index++, propBag );
	}

	charBag += array;
}
GUBIControl::GUBIControl(AppWindow* window,
                         AppEventListener* appListener)
   : NotCopyable()
{
   m_impl = new Impl;
   m_impl->window = window;
   m_impl->time = new gubi::TimeDefault;
   m_impl->renderBridge = new GUBIRenderBridge;
   
   m_impl->appListener = appListener;
      
   gubi::CreateDevice(gubi::DeviceFlags_Default,
                      m_impl->time,
                      m_impl->renderBridge,
                      this,
                      &m_impl->gubiDevice);
                                           
   m_impl->window->setListener(this);

   // make a test widget with an image and a view
   gubi::IView *view = NULL;
   if (m_impl->gubiDevice->CreateView(L"testView", &view)) {
         gubi::IImage *image = NULL;
         if (m_impl->renderBridge->createImage("resources/","bar_plus.png", &image)) {
            gubi::SmartPointer<gubi::PropertyBag> propBag(new gubi::PropertyBag);
            gubi::InsertProperty(propBag, L"image", image);
            if (m_impl->gubiDevice->CreateWidget(L"gubi.ui.image", propBag, &g_Widget)) {
               view->AddWidget(g_Widget, gubi::ViewSpace_Overlay);
            }
         }
   }

   gubi::SmartPointer<gubi::PropertyBag> bag(new gubi::PropertyBag);
   gubi::IEffect *effect = NULL;

   gubi::InsertProperty(bag, L"startValue", fmath::tofixed(10));
   gubi::InsertProperty(bag, L"endValue", fmath::tofixed(100));
   gubi::InsertProperty(bag, L"duration", 3000);
   gubi::InsertProperty(bag, L"period", 500);
   gubi::InsertProperty(bag, L"amplitude", fmath::tofixed(100));

   if (m_impl->gubiDevice->CreateEffect(L"wave", bag, gubi::EffectStartOption_Stopped, &effect)) {
      gubi::SignalConnect(effect, L"onUpdate", this, &GUBIControl::onEffectUpdate, NULL);
      effect->Start();
   }
   
}
Пример #5
0
void CharacterManager::LoadCharacters( moPropBagRef& charBag, Transactions::TransactionGroup::pointer_t group, const bool emit_signals )
{
	moPropArrayRef	array(f_arrayBagName);
	array.Link( charBag );
    assert(array.HasProp());

	const int count = array.CountIndexes();
	for( int idx = 0; idx < count; ++idx )
	{
		const int 		item_no  ( array.ItemNoAtIndex( idx ) );
		moPropSPtr		prop_ptr ( array.Get( item_no ) );
		moName			name	 ( prop_ptr->GetName()  );
		moPropBagRef	propBag(name);
		propBag.NewProp();
		propBag.GetProperty()->Copy( *prop_ptr );

		Combatant::Character::pointer_t ch( new Combatant::Character() );
		ch->Load( propBag );

		// Add "(copy)" in case of duplicates
		//
		Combatant::Character::pointer_t dup = FindDuplicates( ch );
		//
		while( dup )
		{
			ch->name( ch->name() + gettext(" (copy)") );
			dup = FindDuplicates( ch );
		}

		if( group )
		{
			// Add character via transaction.
			//
			Transactions::Transaction::pointer_t tr( new Transactions::AddCharacterTransaction( ch, emit_signals ) );
			tr->doit();
			group->addTransaction( tr );
		}
		else
		{
			// Add character directly
			//
			f_chars.push_back( ch );
		}
	}
}
Пример #6
0
void DuplicateRoll::DuplicateResolver::Load( moPropBagRef& mainPropBag )
{
	// Clear out everything
	//
	f_rollMap.clear();

	// Read sub-bag for the array
	//
	moPropBagRef subBag( "RESOLVER_BAG" );
	subBag.Link( mainPropBag );
	if( !subBag.HasProp() ) subBag.NewProp();

	// Read the resolver array
	//
	moPropArrayRef	array("INIT_RESOLVER");
	array.Link( subBag );
	if( !array.HasProp() )	array.NewProp();
	//
	const int count = array.CountIndexes();
	//
	for( int idx = 0; idx < count; ++idx )
	{
		const int 		item_no  ( array.ItemNoAtIndex( idx ) );
		moPropSPtr		prop_ptr ( array.Get( item_no ) );
		moName			name	 ( prop_ptr->GetName() );
		moPropBagRef	propBag(name);
		propBag.NewProp();
		propBag.GetProperty()->Copy( *prop_ptr );
		//
		moPropIntRef rollProp( "SORT_ROLL" );
		rollProp.Link( propBag );
		const int sortRoll = rollProp;
		//
		DuplicateRoll::pointer_t	dupRoll( new DuplicateRoll );
		dupRoll->Load( propBag );
		//
		f_rollMap[sortRoll] = dupRoll;
	}
}
Пример #7
0
void DuplicateRoll::DuplicateResolver::Save( moPropBagRef& mainPropBag )
{
	// Create array for resolver
	//
	moPropArrayRef	array("INIT_RESOLVER");
	array.NewProp();

	// Populate the array with the sort value and DuplicateRoll
	//
	int array_index = 0;
	for( auto rollDupPair : f_rollMap )
	{
		const int				sortRoll = rollDupPair.first;
		DuplicateRoll::pointer_t	dupRoll  = rollDupPair.second;
		//
		moPropIntRef rollProp( "SORT_ROLL" );
		rollProp.NewProp();
		rollProp = sortRoll;
		//
		moPropBagRef propBag( "DUP_ROLL" );
		propBag.NewProp();
		propBag += rollProp;
		dupRoll->Save( propBag );
		//
		array.Set( array_index, propBag );
		++array_index;
	}

	// Save array to resolver bag
	//
	moPropBagRef	subBag( "RESOLVER_BAG" );
	subBag.NewProp();
	subBag += array;

	// Save the resolver bag into the main property bag
	//
	mainPropBag.Set( "RESOLVER_BAG", subBag );
}
Пример #8
0
nsresult
WSPProxy::VariantToArrayValue(uint8 aTypeTag,
                              nsXPTCMiniVariant* aResultSize,
                              nsXPTCMiniVariant* aResultArray,
                              nsIInterfaceInfo* aInterfaceInfo,
                              nsIVariant* aProperty)
{
  void* array;
  PRUint16 type;
  PRUint32 count;

  nsIID arrayIID;
  nsresult rv = aProperty->GetAsArray(&type, &arrayIID, &count, &array);
  if (NS_FAILED(rv)) {
    return rv;
  }

  aResultSize->val.u32 = count;

  switch (aTypeTag) {
    case nsXPTType::T_I8:
    case nsXPTType::T_U8:
    case nsXPTType::T_I16:
    case nsXPTType::T_U16:
    case nsXPTType::T_I32:
    case nsXPTType::T_U32:
    case nsXPTType::T_I64:
    case nsXPTType::T_U64:
    case nsXPTType::T_FLOAT:
    case nsXPTType::T_DOUBLE:
    case nsXPTType::T_BOOL:
    case nsXPTType::T_CHAR:
    case nsXPTType::T_WCHAR:
    case nsXPTType::T_CHAR_STR:
    case nsXPTType::T_WCHAR_STR:
      aResultArray->val.p = array;
      break;
    case nsXPTType::T_INTERFACE:
    case nsXPTType::T_INTERFACE_IS:
    {
      if (arrayIID.Equals(NS_GET_IID(nsIVariant))) {
        aResultArray->val.p = array;
      }
      else if (!arrayIID.Equals(NS_GET_IID(nsIPropertyBag))) {
        NS_ERROR("Array of complex types should be represented by property "
                 "bags");
        return NS_ERROR_FAILURE;
      }
      else {
        nsISupports** outptr =
          (nsISupports**)nsMemory::Alloc(count * sizeof(nsISupports*));
        if (!outptr) {
          return NS_ERROR_OUT_OF_MEMORY;
        }
        nsISupports** arraySup = (nsISupports**)array;
        const nsIID* iid;
        aInterfaceInfo->GetIIDShared(&iid);
        PRUint32 i;
        for (i = 0; i < count; i++) {
          nsCOMPtr<nsIPropertyBag> propBag(do_QueryInterface(arraySup[i]));
          if (!propBag) {
            *(outptr + i) = nsnull;
          }
          else {
            nsCOMPtr<nsISupports> wrapper;
            rv = WrapInComplexType(propBag, aInterfaceInfo,
                                   getter_AddRefs(wrapper));
            if (NS_FAILED(rv)) {
              NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(i, outptr);
              return rv;
            }
            rv = wrapper->QueryInterface(*iid, (void**)(outptr + i));
            if (NS_FAILED(rv)) {
              NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(i, outptr);
              return rv;
            }
          }
        }
        aResultArray->val.p = outptr;
      }
      break;
    }
    default:
      NS_ERROR("Conversion of illegal array type");
      return NS_ERROR_FAILURE;
  }

  return NS_OK;
}
Пример #9
0
NS_IMETHODIMP KDEWallet::ModifyLogin(nsILoginInfo *oldLogin,
                                     nsISupports *modLogin) {
    PR_LOG( gKDEWalletLog, PR_LOG_DEBUG, ( "KDEWallet::ModifyLogin() Called") );
    nsresult rv;
    nsCOMPtr<nsILoginInfo> newLogin( do_QueryInterface(modLogin, &rv) );
    if(rv != NS_OK) {
        /* Otherwise, it has to be an nsIPropertyBag.
          * Let's get the attributes from the old login, then append the ones
          * fetched from the property bag. Gracefully, if an attribute appears
          * twice in an attribut list, the last value is stored. */
        nsCOMPtr<nsILoginInfo> login;
        rv = oldLogin->Clone( getter_AddRefs(login) );
        NS_ENSURE_SUCCESS(rv, rv);

        newLogin = do_QueryInterface(login, &rv);
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIPropertyBag> propBag( do_QueryInterface(modLogin, &rv) );
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsISimpleEnumerator> enumerator;
        rv = propBag->GetEnumerator(getter_AddRefs(enumerator));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsISupports> sup;
        nsCOMPtr<nsIProperty> prop;
        nsAutoString propName;
        bool hasMoreElements;

        rv = enumerator->HasMoreElements(&hasMoreElements);
        NS_ENSURE_SUCCESS(rv, rv);

        while( hasMoreElements ) {
            rv = enumerator->GetNext(getter_AddRefs(sup));
            NS_ENSURE_SUCCESS(rv, rv);

            rv = enumerator->HasMoreElements(&hasMoreElements);
            NS_ENSURE_SUCCESS(rv, rv);

            prop = do_QueryInterface(sup, &rv);
            NS_ENSURE_SUCCESS(rv, rv);

            prop->GetName(propName);
            PR_LOG( gKDEWalletLog, PR_LOG_DEBUG, ( "KDEWallet::ModifyLogin() Modify property: %s", NS_ConvertUTF16toUTF8(propName).get() ) );

            nsCOMPtr<nsIVariant> val;
            prop->GetValue(getter_AddRefs(val));
            if (!val)
                return NS_ERROR_FAILURE;
            nsString valueString;

            rv = val->GetAsDOMString(valueString);
            NS_ENSURE_SUCCESS(rv, rv);

            if( propName.EqualsLiteral( kHostnameAttr ) )
                newLogin->SetHostname( valueString );
            if( propName.EqualsLiteral( kUsernameAttr ) )
                newLogin->SetUsername( valueString );
            if( propName.EqualsLiteral( kUsernameFieldAttr ) )
                newLogin->SetUsernameField( valueString );
            if( propName.EqualsLiteral( kPasswordAttr ) )
                newLogin->SetPassword( valueString );
            if( propName.EqualsLiteral( kPasswordFieldAttr ) )
                newLogin->SetPasswordField( valueString );
            if( propName.EqualsLiteral( kFormSubmitURLAttr ) )
                newLogin->SetFormSubmitURL( valueString );
            if( propName.EqualsLiteral( kHttpRealmAttr ) )
                newLogin->SetHttpRealm( valueString );

            if( propName.EqualsLiteral( kGuidAttr ) ) {
                nsCOMPtr<nsILoginMetaInfo> loginmeta( do_QueryInterface(newLogin, &rv) );
                NS_ENSURE_SUCCESS(rv, rv);
                nsAutoString aGUID ;
                rv = loginmeta->SetGuid( valueString );
                NS_ENSURE_SUCCESS(rv, rv);
            }
        }
    }
    rv = RemoveLogin(oldLogin);
    NS_ENSURE_SUCCESS(rv, rv);
    return AddLogin(newLogin);
}