NodeContainer *NodeReader::readNodes() {
	NodeContainer *retVal = new NodeContainer();

	// read definition of file
	FileRow defs = this->operator [](0);
	int total = defs.asInt(),
			customers = defs.asInt(),
			factories = defs.asInt(),
			crossroads = defs.asInt();

	int current = 1;

	current = readItems(current, customers, *retVal, Node::CUSTOMER);
	current = readItems(current, factories, *retVal, Node::FACTORY);
	readItems(current, crossroads, *retVal, Node::CROSSROAD);

	return retVal;
}
Exemple #2
0
customActionsDialog::customActionsDialog(MainWindow *parent)
{
    mainWindow = parent;

    mainLayout = new QVBoxLayout();

    treeWidget = new QTreeWidget();
    treeWidget->setAlternatingRowColors(true);
    treeWidget->setRootIsDecorated(false);
    treeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);

    connect(treeWidget,SIGNAL(itemDoubleClicked(QTreeWidgetItem *,int)),this,SLOT(getIcon(QTreeWidgetItem *,int)));

    QTreeWidgetItem *header = treeWidget->headerItem();
    header->setText(0,tr("Filetype"));
    header->setText(1,tr("Text"));
    header->setText(2,tr("Icon"));
    header->setText(3,tr("Command"));

    treeWidget->setColumnWidth(1,160);
    treeWidget->setColumnWidth(2,160);

    treeWidget->setDragDropMode(QAbstractItemView::InternalMove);

    mainLayout->addWidget(treeWidget);

    horizontalLayout = new QHBoxLayout();
    addButton = new QToolButton();
    delButton = new QToolButton();
    infoButton= new QToolButton();
    addButton->setIcon(QIcon::fromTheme("list-add"));
    delButton->setIcon(QIcon::fromTheme("list-remove"));
    infoButton->setIcon(QIcon::fromTheme("dialog-question",QIcon::fromTheme("help-browser")));
    connect(addButton,SIGNAL(clicked()),this,SLOT(addItem()));
    connect(delButton,SIGNAL(clicked()),this,SLOT(delItem()));
    connect(infoButton,SIGNAL(clicked()),this,SLOT(infoItem()));


    buttons = new QDialogButtonBox;
    buttons->setStandardButtons(QDialogButtonBox::Save|QDialogButtonBox::Cancel);
    connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));

    horizontalLayout->addWidget(infoButton);
    horizontalLayout->addWidget(addButton);
    horizontalLayout->addWidget(delButton);
    horizontalLayout->addWidget(buttons);

    mainLayout->addLayout(horizontalLayout);
    setLayout(mainLayout);

    readItems();

    resize(600,360);

    setWindowTitle(tr("Custom Actions"));
}
int readInputFiles(std::vector<ItemCategory> &categories,
                   std::vector<Conversion> &conversions)
{
	if (readCategories(categories) > 0)
		return 1;
	if (readItems(categories) > 0)
		return 2;
	if (readConversions(categories, conversions) > 0)
		return 3;

	return 0;
}
bool ArrayModelReaderXml::read(QIODevice &in)
{
    auto *model = dynamic_cast<ArrayModel*>(m_model);
    if(!model) {
        return false;
    }

    QXmlStreamReader stream(&in);

    stream.readNextStartElement();
    {
        readItems(model, stream);
    }

    return true;
}
TStatusDef *TStatusLine::readDefs( ipstream& is )
{
    TStatusDef *cur = 0;
    TStatusDef *first;
    TStatusDef **last = &first;
    int count;
    is >> count;
    while( count-- > 0 )
        {
        int min, max;
        is >> min >> max;
        cur = new TStatusDef( min, max, readItems( is ) );
        *last = cur;
        last = &(cur->next);
        }
    *last = 0;
    return first;
}
shared_ptr<SceneObject> ModelFactory::create()
{
    model = make_unique<Model>(moving);

    //readObjType();
    //Point3D pos = readPosition();
    //model->setPosition3D(pos);
    readItems();
    model->setMaterial(readMaterial());

    shared_ptr<Item> item = make_shared<Item>();
    model->setItem(item);
    model->composePolygonVert();

    //model->setId(IdCreator::getInstance().nextId());

    shared_ptr<Model> smodel = std::move(model);
    return smodel;
}
Exemple #7
0
Resources::Resources() {
	m_GLOBAL_FIELD_CELL_REAL_SIZE_ground.push_back(std::unique_ptr < QImage > {new QImage{ ":/grass.png" }});
	m_GLOBAL_FIELD_CELL_REAL_SIZE_ground.push_back(std::unique_ptr < QImage > {new QImage{ ":/water.png" }});
	m_GLOBAL_FIELD_CELL_REAL_SIZE_ground.push_back(std::unique_ptr < QImage > {new QImage{ ":/sand.png" }});
	m_GLOBAL_FIELD_CELL_REAL_SIZE_ground.push_back(std::unique_ptr < QImage > {new QImage{ ":/dirt.png" }});
	m_GLOBAL_FIELD_CELL_REAL_SIZE_ground.push_back(std::unique_ptr < QImage > {new QImage{ ":/forest.png" }});
	m_GLOBAL_FIELD_CELL_REAL_SIZE_ground.push_back(std::unique_ptr < QImage > {new QImage{ ":/rocks.png" }});
	m_squad_image.reset(new QImage{ ":/ranger.png" });
	m_city_image.reset(new QImage{ ":/city.png" });

	m_models.resize((int)ModelType::End);
	m_models[(int)ModelType::City].reset(new QImage{ ":/city.png" });
	m_models[(int)ModelType::Squad].reset(new QImage{ ":/ranger.png" });
	m_models[(int)ModelType::Warrior].reset(new QImage{ ":/warrior.png" });
	m_models[(int)ModelType::Worker].reset(new QImage{ ":/worker.png" });
	m_models[(int)ModelType::SawMill].reset(new QImage{ ":/sawmill.png" });
	m_models[(int)ModelType::Construction].reset(new QImage{ ":/construction.png" });

	readItems();
}
Exemple #8
0
void GameDatas::read(QString path){
    readVariablesSwitches(path);
    m_commonEventsDatas->read(path);
    readSystem(path);
    readItems(path);
    readSkills(path);
    readBattleSystem(path);
    readWeapons(path);
    readArmors(path);
    readHeroes(path);
    readMonsters(path);
    readTroops(path);
    readClasses(path);
    readTilesets(path);
    readAnimations(path);
    readStatus(path);
    readTitleScreenGameOver(path);

    m_isDatasRead = true;
}
Exemple #9
0
HashGraph* readGraphGDFFormat(
		FILE* f,	//input file in GDF format
		string gname, //the input graph name
		Ortholog& orth,	//ortholog name to ortholog id mapping
		OrthologInfoList& orthinfolist	//return value, the orthology info
		)
{
	if(feof(f)) return NULL;
	orthinfolist.clear();
	HashGraph* retG=new HashGraph();
	AttributeValue attrval;
	attrval.type='s';
	attrval.value=gname;
	
	//set graph attributes
	Attributes* gattrs=new Attributes;
	gattrs->insert(Attributes::value_type("name", attrval));
	retG->setGraphAttrs(gattrs);
	debug(31, "set graph attribute\n");
	
	string str;
	bool readnode=true;
	int orthIndex=-1;
	vector<string> attrnames;
	vector<char> attrtypes;
	vector<string> defvalues;
	
	hash_map<string, int, strhash, eqstr> nodemap;
	
	string attrname, defvalue;
	char attrtype;
	char buff[50];
	while(readOneLine(f, str))
	{
		debug(31, str<<endl);
		//now parse the string
		if(str.substr(4, 4)=="def>")
		{
			debug(31, "readnode = "<<readnode<<endl);
			if(str.substr(0, 8)=="nodedef>")
				readnode=true;
			else
				readnode=false;
			debug(31, "readnode = "<<readnode<<endl);
			attrnames.clear();
			attrtypes.clear();
			defvalues.clear();
			int start=8;
			string seg;
			
			do{
				start=getOneSegment(str, start, ',', seg);
				debug(31, "start="<<start<<endl);
				debug(31, "string::npos="<<string::npos<<endl);
				parseGDFAttribute(seg, attrname, attrtype, defvalue);
				if(attrname=="orthologies")
					orthIndex=attrnames.size();
				attrnames.push_back(attrname);
				attrtypes.push_back(attrtype);
				defvalues.push_back(defvalue);
			}while(start!=string::npos);
	
		}else
		{
			debug(31, "read values"<<endl);
			debug(31, "orthIndex: "<<orthIndex<<endl);
			if(readnode)
			{
				assert(attrnames[0]=="name");
				int start=0;
				string seg;
				int i=0;
				Attributes* nattrs=new Attributes;
				OrthologInfo orthinfo;
				
				do{
					start=getOneSegment(str, start, ',', seg);
					if(i==0)
						nodemap[seg]=orthinfolist.size();
					debug(31, "getOneSegment: "<<seg<<endl);
					if(i==orthIndex)//if the attribute name is orthologies
					{
						debug(31, "orthologies\n");
						string orthlabel;
						int p=0;
						do{
							p=getOneSegment(seg, p, ':', orthlabel);
							debug(31, "orth label: "<<orthlabel);
							uint32_t orthid=orth.getOrthologID(orthlabel);
							orthinfo.push_back(orthid);
							attrval.type='i';
							sprintf(buff, "%u", orthid);
							attrval.value=string(buff);
							nattrs->insert(Attributes::value_type("orthology", attrval));
						}while(p!=string::npos);
					}else
					{
						attrval.type=attrtypes[i];
						if(seg.empty())
						{
							attrval.value=defvalues[i];
							nattrs->insert(Attributes::value_type(attrnames[i], attrval));
						}
						else
						{
							vector<string> items;
							readItems(seg, ':', items);
							for(unsigned int ii=0; ii<items.size(); ii++)
							{
								attrval.value=items[ii];
								nattrs->insert(Attributes::value_type(attrnames[i], attrval));
							}
						}
					}
					
					i++;
				}while(start!=string::npos);
				
				if(orthIndex<0)
				{
					attrval.type='i';
					attrval.value="0";
					nattrs->insert(Attributes::value_type("orthology", attrval));
					orthinfo.push_back(0);
				}
				
				retG->addNode(nattrs);
				orthinfolist.push_back(orthinfo);
				
			}else
			{
				assert(attrnames[0]=="node1" && attrnames[1]=="node2");
				int start=0;
				string seg;
				int i=0;
				Attributes* eattrs=new Attributes;
				int n1, n2;
				
				do{
					start=getOneSegment(str, start, ',', seg);
					if(i==0)
					{
						n1=nodemap[seg];
					}
					else if(i==1)
					{
						n2=nodemap[seg];
					}else
					{
						attrval.type=attrtypes[i];
						if(seg.empty())
						{
							attrval.value=defvalues[i];
							eattrs->insert(Attributes::value_type(attrnames[i], attrval));
						}
						else
						{
							vector<string> items;
							readItems(seg, ':', items);
							for(unsigned int ii=0; ii<items.size(); ii++)
							{
								attrval.value=items[ii];
								eattrs->insert(Attributes::value_type(attrnames[i], attrval));
							}
						}
					}
					i++;
				}while(start!=string::npos);
				retG->setEdge(n1, n2, eattrs);
			}
		}
	}
	return retG;
}
Exemple #10
0
 void JsonSchema::readArray(cJSON *childProperties,  PropertiesPtr property)
 {
     cJSON *itemValues = cJSON_GetObjectItem(childProperties, "items");
     if (itemValues)
     {
         if (itemValues->type == 5)
         {
             int item_size = cJSON_GetArraySize(itemValues);
             int item_index = 0;
             do
             {
                 cJSON *item = cJSON_GetArrayItem(itemValues, item_index);
                 property->setItem(readItems(item));
             }
             while ( ++item_index < item_size);
         }
         else
         {
             property->setItem(readItems(itemValues));
         }
     }
     cJSON *itemsMax = cJSON_GetObjectItem(childProperties, "maxItems");
     if (itemsMax)
     {
         cJSON *exclusiveMax = cJSON_GetObjectItem(childProperties, "exclusiveMaximum");
         if (exclusiveMax)
         {
             if (exclusiveMax->type == cJSON_True)
                 property->setMax( --(itemsMax->valueint));
             else
                 property->setMax(itemsMax->valueint);
         }
         else
             property->setMax(itemsMax->valueint);
     }
     cJSON *itemsMin = cJSON_GetObjectItem(childProperties, "minLength");
     if (itemsMin)
     {
         cJSON *exclusiveMin = cJSON_GetObjectItem(childProperties, "exclusiveMinimum");
         if (exclusiveMin)
         {
             if (exclusiveMin->type == cJSON_True)
                 property->setMin( ++(itemsMin->valueint));
             else
                 property->setMin(itemsMin->valueint);
         }
         else
             property->setMin(itemsMin->valueint);
     }
     cJSON *uniqueItems = cJSON_GetObjectItem(childProperties, "uniqueItems");
     if (uniqueItems)
     {
         property->setUnique(uniqueItems->type);
     }
     else
     {
         property->setUnique(cJSON_True);
     }
     cJSON *additionalItems = cJSON_GetObjectItem(childProperties, "additionalItems");
     if (additionalItems)
     {
         property->setAdditionalItems(additionalItems->type);
     }
     else
     {
         property->setAdditionalItems(cJSON_True);
     }
 }
Exemple #11
0
    void JsonSchema::readJson()
    {
        if (! m_cjson)
            return;

        cJSON *jsonId = cJSON_GetObjectItem(m_cjson, "id");
        if (jsonId)
        {
            m_id = jsonId->valuestring;
        }
        cJSON *jsonSchema = cJSON_GetObjectItem(m_cjson, "$schema");
        if (jsonSchema)
        {
            m_schema = jsonSchema->valuestring;
        }
        cJSON *jsonTitle = cJSON_GetObjectItem(m_cjson, "title");
        if (jsonTitle)
        {
            m_title = jsonTitle->valuestring;
        }
        cJSON *jsonType = cJSON_GetObjectItem(m_cjson, "type");
        if (jsonType)
        {
            m_type = jsonType->valuestring;
        }
        cJSON *jsonDescription = cJSON_GetObjectItem(m_cjson, "description");
        if (jsonDescription)
        {
            m_description = jsonDescription->valuestring;
        }
        cJSON *jsonDefinitions = cJSON_GetObjectItem(m_cjson, "definitions");
        if (jsonDefinitions)
        {
            cJSON *childDefinitions = jsonDefinitions->child;
            while (childDefinitions)
            {
                std::string defName = childDefinitions->string;
                addDefinition(defName, readDef(childDefinitions, defName));
                childDefinitions = childDefinitions->next;
            }
        }
        cJSON *jsonProperties = cJSON_GetObjectItem(m_cjson, "properties");
        if (jsonProperties)
        {
            cJSON *childProperties = jsonProperties->child;
            while (childProperties)
            {
                std::string attName = childProperties->string;
                addProperty(attName, readProp(childProperties, attName));
                childProperties = childProperties->next;
            }
        }
        if (m_type == "array")
        {
            cJSON *jsonItems = cJSON_GetObjectItem(m_cjson, "items");
            if (jsonItems)
            {
                if (jsonItems->type == 5)
                {
                    int item_size = cJSON_GetArraySize(jsonItems);
                    int item_index = 0;
                    do
                    {
                        cJSON *item = cJSON_GetArrayItem(jsonItems, item_index);
                        setItem(readItems(item));
                    }
                    while ( ++item_index < item_size);
                }
                else
                {
                    setItem(readItems(jsonItems));
                }
            }
        }
        cJSON *jsonAdditionalProperties = cJSON_GetObjectItem(m_cjson, "additionalProperties");
        if (jsonAdditionalProperties)
            m_additionalProperties = jsonAdditionalProperties->type;
        else
            m_additionalProperties = cJSON_True;

        cJSON *jsonReference = cJSON_GetObjectItem(m_cjson, "$ref");
        if (jsonReference)
        {
            readJsonRef(jsonReference);
        }
        cJSON *jsonAllOf = cJSON_GetObjectItem(m_cjson, "allOf");
        if (jsonAllOf)
        {
            readAllOf(jsonAllOf);
        }
        cJSON *jsonRequiredValues = cJSON_GetObjectItem(m_cjson, "required");
        if (jsonRequiredValues)
        {
            int size = cJSON_GetArraySize(jsonRequiredValues);
            int index = 0;
            do
            {
                setRequiredValue(cJSON_GetArrayItem(jsonRequiredValues, index)->valuestring);
            }
            while ( ++index < size);
        }
    }