From 2e70d8a0844514e2307debda36b01a62e4768822 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Tue, 26 May 2015 18:19:41 +0200 Subject: [PATCH] - VCMI will now read templates from mods - Added partial schema for RMG template --- .../Content/config/defaultTemplates}/rmg.json | 0 Mods/vcmi/Mods/defaultTemplates/mod.json | 12 ++++ config/schemas/template.json | 63 +++++++++++++++++++ lib/CModHandler.cpp | 1 + lib/GameConstants.h | 2 + lib/VCMI_Lib.cpp | 4 +- 6 files changed, 80 insertions(+), 2 deletions(-) rename {config => Mods/vcmi/Mods/defaultTemplates/Content/config/defaultTemplates}/rmg.json (100%) create mode 100644 Mods/vcmi/Mods/defaultTemplates/mod.json create mode 100644 config/schemas/template.json diff --git a/config/rmg.json b/Mods/vcmi/Mods/defaultTemplates/Content/config/defaultTemplates/rmg.json similarity index 100% rename from config/rmg.json rename to Mods/vcmi/Mods/defaultTemplates/Content/config/defaultTemplates/rmg.json diff --git a/Mods/vcmi/Mods/defaultTemplates/mod.json b/Mods/vcmi/Mods/defaultTemplates/mod.json new file mode 100644 index 000000000..0107692db --- /dev/null +++ b/Mods/vcmi/Mods/defaultTemplates/mod.json @@ -0,0 +1,12 @@ +{ + "name" : "Default templates", + "description" : "A set of random map templates for VCMI", + + "version" : "0.99", + "author" : "VCMI Team", + "contact" : "http://forum.vcmi.eu/index.php", + "modType" : "Templates", + "templates" : [ + "config/defaultTemplates/rmg" + ], +} diff --git a/config/schemas/template.json b/config/schemas/template.json new file mode 100644 index 000000000..2dcbb29ba --- /dev/null +++ b/config/schemas/template.json @@ -0,0 +1,63 @@ +{ + + "type":"object", + "$schema": "", + + "title" : "VCMI random map template format", + "description" : "Format used to define random map templates in VCMI", + + + "definitions" : + { + "zone":{ + "type": "object", + "required" : ["type", "monsters", "size", "level"], + "properties":{ + "type":{"$ref" : "#/definitions/type"}, + "size":{"$ref" : "#/definitions/size"}, + "playerTowns":{"$ref" : "#/definitions/playerTowns"}, + "neuralTowns":{"$ref" : "#/definitions/neuralTowns"}, + "townsAreSameType":{"$ref" : "#/definitions/townsAreSameType"}, + "monsters":{"$ref" : "#/definitions/monsters"}, + "mines":{"$ref" : "#/definitions/mines"}, + "treasure":{ + "type":"array", + "items":{ + "type": "object", + "properties":{ + "min": {"type":"number", "minimum" : 0}, + "max": {"type":"number", "minimum" : 0}, + "density": {"type":"number", "minimum" : 1} + }, + "additionalProperties" : false + } + } + } + }, + "type" :{ + "type" : "object", + "enum": ["playerStart", "treasure", "junction"] + "additionalProperties" : false + "type":"string" + }, + "size":{ + "type": "number", + "minimum": 1, + "additionalProperties" : false, + } + }, + + "properties": + { + "zones":{ + "type": "array", + "items":{"$ref" : "#/definitions/zone" } + }, + "connections":{ + "type": "array", + "items":{"$ref" : "#/definitions/connection"} + } + "required" : ["zones", "connections"], + "additionalProperties" : false + } +} diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index fa54ce9a4..31a953292 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -385,6 +385,7 @@ CContentHandler::CContentHandler() handlers.insert(std::make_pair("objects", ContentTypeHandler(VLC->objtypeh, "object"))); handlers.insert(std::make_pair("heroes", ContentTypeHandler(VLC->heroh, "hero"))); handlers.insert(std::make_pair("spells", ContentTypeHandler(VLC->spellh, "spell"))); + handlers.insert(std::make_pair("templates", ContentTypeHandler((IHandlerBase *)VLC->tplh, "template"))); //TODO: any other types of moddables? } diff --git a/lib/GameConstants.h b/lib/GameConstants.h index eb8e33973..8cb5dcd57 100644 --- a/lib/GameConstants.h +++ b/lib/GameConstants.h @@ -942,6 +942,8 @@ enum class ESpellSchool: ui8 EARTH = 3 }; +ID_LIKE_OPERATORS_DECLS(SpellID, SpellID::ESpellID) + // Typedef declarations typedef ui8 TFaction; typedef si64 TExpType; diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index 35a699f8b..8aaae68c9 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -115,12 +115,12 @@ void LibClasses::init() createHandler(terviewh, "Terrain view pattern", pomtime); + createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?) + logGlobal->infoStream()<<"\tInitializing handlers: "<< totalTime.getDiff(); modh->load(); - createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?) - modh->afterLoad(); //FIXME: make sure that everything is ok after game restart