From 82ca516b93c5170eeec2b95498a9f6dddae0b1a2 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Tue, 26 Apr 2022 16:24:37 -0400 Subject: [PATCH] adding the class --- Taskfile.yml | 17 +++++++--- samples/verg.yml | 3 ++ schemas-json/character.json | 6 +++- schemas-json/classes.json | 66 +++++++++++++++++++++++++++++++++++++ schemas-yaml/character.yml | 2 ++ schemas-yaml/classes.pl | 17 ++++++++++ schemas-yaml/classes.yml | 12 +++++++ 7 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 schemas-json/classes.json create mode 100644 schemas-yaml/classes.pl create mode 100644 schemas-yaml/classes.yml diff --git a/Taskfile.yml b/Taskfile.yml index acc2368..31ba9b7 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -3,16 +3,22 @@ version: "3" tasks: - schemas: fd -e yml -p ./schemas-yaml -x task schema SCHEMA='{}' + schemas: + sources: [ 'schemas-yaml/*' ] + generates: [ 'schemas-json/*' ] + cmds: + - fd -e yml -p ./schemas-yaml -x task schema SCHEMA='{}' schema: vars: + TRANSFORM: + sh: | + echo {{.SCHEMA}} | \ + perl -lnE's/yml$/pl/; s/^/.\//; say if -f $_' DEST: sh: echo {{.SCHEMA}} | perl -pe's/ya?ml/json/g' - sources: ["{{.SCHEMA}}"] - generates: ["{{.DEST}}"] cmds: - - transerialize {{.SCHEMA}} {{.DEST}} + - transerialize {{.SCHEMA}} {{.TRANSFORM}} {{.DEST}} validate: silent: true @@ -23,7 +29,8 @@ tasks: --errors=json \ --verbose \ -c ajv-keywords \ - -s schemas-yaml/character.yml \ + -r schemas-json/classes.json \ + -s schemas-json/character.json \ -d {{.CLI_ARGS}} test: deps: [ schemas ] diff --git a/samples/verg.yml b/samples/verg.yml index 97ed937..1000903 100644 --- a/samples/verg.yml +++ b/samples/verg.yml @@ -1,5 +1,8 @@ name: Verg-La player: Yanick +class: + generic: magician + subclass: cryomancer statistics: strength: 11 dexterity: 13 diff --git a/schemas-json/character.json b/schemas-json/character.json index f97c88f..f4d0d1a 100644 --- a/schemas-json/character.json +++ b/schemas-json/character.json @@ -9,6 +9,9 @@ "$id" : "https://hyperboria.babyl.ca/character.json", "additionalProperties" : false, "properties" : { + "class" : { + "$ref" : "/classes.json" + }, "name" : { "type" : "string" }, @@ -43,7 +46,8 @@ "required" : [ "name", "player", - "statistics" + "statistics", + "class" ], "title" : "Hyperboria character sheet", "type" : "object" diff --git a/schemas-json/classes.json b/schemas-json/classes.json new file mode 100644 index 0000000..b725a0a --- /dev/null +++ b/schemas-json/classes.json @@ -0,0 +1,66 @@ +{ + "$defs" : { + "fighter" : [ + "barbarian", + "berserker", + "cataphract", + "hunstman", + "paladin", + "ranger", + "warlock" + ], + "magician" : [ + "cryomancer", + "illusionist", + "necromancer", + "pyromancer", + "witch" + ] + }, + "$id" : "https://hyperboria.babyl.ca/classes.json", + "oneOf" : [ + { + "enum" : [ + "fighter", + "magician" + ] + }, + { + "properties" : { + "generic" : { + "const" : "fighter" + }, + "subclass" : { + "enum" : [ + "barbarian", + "berserker", + "cataphract", + "hunstman", + "paladin", + "ranger", + "warlock" + ] + } + }, + "type" : "object" + }, + { + "properties" : { + "generic" : { + "const" : "magician" + }, + "subclass" : { + "enum" : [ + "cryomancer", + "illusionist", + "necromancer", + "pyromancer", + "witch" + ] + } + }, + "type" : "object" + } + ], + "title" : "Classes of characters for Hyperborea" +} diff --git a/schemas-yaml/character.yml b/schemas-yaml/character.yml index 204c87d..e0b0957 100644 --- a/schemas-yaml/character.yml +++ b/schemas-yaml/character.yml @@ -6,10 +6,12 @@ required: - name - player - statistics + - class properties: name: &string type: string player: *string + class: { $ref: '/classes.json' } statistics: type: object allRequired: true diff --git a/schemas-yaml/classes.pl b/schemas-yaml/classes.pl new file mode 100644 index 0000000..2f1b3fe --- /dev/null +++ b/schemas-yaml/classes.pl @@ -0,0 +1,17 @@ +sub { + my $schema = $_->{oneOf} = []; + + push @$schema, { enum => [ keys $_->{'$defs'}->%* ] }; + + for my $generic ( keys $_->{'$defs'}->%* ) { + push @$schema, { + type => 'object', + properties => { + generic => { const => $generic }, + subclass => { enum => $_->{'$defs'}{$generic} } + } + } + } + + return $_; +} diff --git a/schemas-yaml/classes.yml b/schemas-yaml/classes.yml new file mode 100644 index 0000000..6a4336d --- /dev/null +++ b/schemas-yaml/classes.yml @@ -0,0 +1,12 @@ +$id: https://hyperboria.babyl.ca/classes.json +title: Classes of characters for Hyperborea +$defs: + fighter: + - barbarian + - berserker + - cataphract + - hunstman + - paladin + - ranger + - warlock + magician: [cryomancer, illusionist, necromancer, pyromancer, witch]