Skip to content

Commit

Permalink
Renamed all schema files to use the .schema.yaml file extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
flemming-n-larsen committed Sep 2, 2024
1 parent 8b4f1c3 commit cc07bc2
Show file tree
Hide file tree
Showing 56 changed files with 201 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Fleck;
using Newtonsoft.Json;
using Robocode.TankRoyale.BotApi.Util;
using Robocode.TankRoyale.Schema;
using Robocode.TankRoyale.Schema.Game;

namespace Robocode.TankRoyale.BotApi.Tests.Test_utils;

Expand Down Expand Up @@ -285,7 +285,7 @@ private static void SendGameStartedForBot(IWebSocketConnection conn)
Type = EnumUtil.GetEnumMemberAttrValue(MessageType.GameStartedEventForBot),
MyId = MyId
};
var gameSetup = new Schema.GameSetup
var gameSetup = new Schema.Game.GameSetup
{
GameType = GameType,
ArenaWidth = ArenaWidth,
Expand Down Expand Up @@ -331,7 +331,7 @@ private void SendTickEventForBot(IWebSocketConnection conn, int turnNumber)
radarTurnRate = _botIntent.RadarTurnRate ?? BotRadarTurnRate;
}

var state = new Schema.BotState
var state = new Schema.Game.BotState
{
Energy = _energy,
X = BotX,
Expand All @@ -350,7 +350,7 @@ private void SendTickEventForBot(IWebSocketConnection conn, int turnNumber)

var bulletState1 = CreateBulletState(1);
var bulletState2 = CreateBulletState(2);
tickEvent.BulletStates = new HashSet<Schema.BulletState>
tickEvent.BulletStates = new HashSet<Schema.Game.BulletState>
{
bulletState1, bulletState2
};
Expand All @@ -377,9 +377,9 @@ private static void Send(IWebSocketConnection conn, Object obj)
conn.Send(JsonConvert.SerializeObject(obj));
}

private static Schema.BulletState CreateBulletState(int id)
private static Schema.Game.BulletState CreateBulletState(int id)
{
var bulletState = new Schema.BulletState()
var bulletState = new Schema.Game.BulletState()
{
BulletId = id,
X = 0,
Expand Down
28 changes: 18 additions & 10 deletions schema/dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using NJsonSchema;
using NJsonSchema.CodeGeneration.CSharp;
using NJsonSchema.Yaml;
Expand Down Expand Up @@ -33,7 +34,7 @@ Generates C# source files from the Robocode Tank Royale JSON schema files.

var srcDir = args[0]; // source path for the location of the JSON Schema files
var destDir = args[1]; // destination path for storing the generated source files
var _namespace = args[2]; // namespace, e.g. "Robocode.TankRoyale.Schema.Game"
var namespaceName = args[2]; // namespace, e.g. "Robocode.TankRoyale.Schema.Game"

// Loop through all JSON Schema files in YAML format
foreach (var filename in Directory.GetFiles(srcDir))
Expand All @@ -59,7 +60,7 @@ Generates C# source files from the Robocode Tank Royale JSON schema files.
var typeResolver = new CustomizedCSharpTypeResolver(settings);

var generator = new CSharpGenerator(schema, settings, typeResolver);
settings.Namespace = _namespace;
settings.Namespace = namespaceName;

// Generate and output source file
var text = generator.GenerateFile();
Expand Down Expand Up @@ -87,16 +88,19 @@ Generates C# source files from the Robocode Tank Royale JSON schema files.
// Add extension class to the class replacement string, if the schema contains an "extends" attribute
try
{
var extends = (IDictionary<string, object>)schema.ExtensionData["extends"];
var refPath = (string)extends["$ref"];
replacement += " : " + ToClassName(refPath);
if (schema.ExtensionData != null)
{
var extends = (IDictionary<string, object>)schema.ExtensionData["extends"];
var refPath = (string)extends["$ref"];
replacement += " : " + ToClassName(refPath);
}
}
catch (KeyNotFoundException)
{
}

// Replace the "public partial class Yaml" with our replacement string
// (correct class name + extension, if is was missing)
// (correct class name + extension, if it was missing)
text = text.Replace("public partial class Yaml", replacement);

// Replace the "YamlType" with <class mame>Type
Expand All @@ -116,14 +120,18 @@ Generates C# source files from the Robocode Tank Royale JSON schema files.

/// <summary>
/// Method using for converting a file name for a schema file into a C# class name.
/// E.g. converts the file name D:\..\robocode-tankroyale-schema\bot-death-event.yaml into BotDeathEvent
/// E.g. converts the file name D:\..\robocode-tankroyale-schema\bot-death-event.schema.yaml into BotDeathEvent
/// </summary>
/// <param name="filename">Is the filename of the JSON Schema to convert into a C# class name</param>
/// <param name="filePath">Is the filename of the JSON Schema to convert into a C# class name</param>
/// <returns>A string containing a C# class name</returns>
private static string ToClassName(string filename)
private static string ToClassName(string filePath)
{
// Split the name based on dashes
var strList = Path.GetFileNameWithoutExtension(filename).Split('-');

var filename = Path.GetFileName(filePath);
var fileNameWithoutExtensions = Regex.Replace(filename, "(\\.[^.]+)+$", "");

var strList = fileNameWithoutExtensions.Split('-');

// The starting letter and letters after a dash must be converted to upper case, and the dashes must be removed
var sb = new StringBuilder();
Expand Down
4 changes: 3 additions & 1 deletion schema/jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ jsonSchema2Pojo {
setSource(singletonList(File("$projectDir/../schemas")))
setAnnotationStyle(AnnotationStyle.GSON.toString())
targetPackage = schemaPackage
}

setFileExtensions("schema.yaml", "schema.json")
}
78 changes: 39 additions & 39 deletions schema/schemas/game/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,80 +313,80 @@ Here are the events that a bot receives during a game:

[TPS]: ../../../docs/articles/tps.html "TPS (Turns Per Second)"

[server-handshake]: server-handshake.yaml
[server-handshake]: server-handshake.schema.yaml

[bot-handshake]: bot-handshake.yaml
[bot-handshake]: bot-handshake.schema.yaml

[observer-handshake]: observer-handshake.yaml
[observer-handshake]: observer-handshake.schema.yaml

[controller-handshake]: controller-handshake.yaml
[controller-handshake]: controller-handshake.schema.yaml

[bot-list-update]: bot-list-update.yaml
[bot-list-update]: bot-list-update.schema.yaml

[start-game]: start-game.yaml
[start-game]: start-game.schema.yaml

[game-started-event-for-bot]: game-started-event-for-bot.yaml
[game-started-event-for-bot]: game-started-event-for-bot.schema.yaml

[bot-ready]: bot-ready.yaml
[bot-ready]: bot-ready.schema.yaml

[round-started-event]: round-started-event.yaml
[round-started-event]: round-started-event.schema.yaml

[round-ended-event-for-bot]: round-ended-event-for-bot.yaml
[round-ended-event-for-bot]: round-ended-event-for-bot.schema.yaml

[tick-event-for-bot]: tick-event-for-bot.yaml
[tick-event-for-bot]: tick-event-for-bot.schema.yaml

[tick-event-for-observer]: tick-event-for-observer.yaml
[tick-event-for-observer]: tick-event-for-observer.schema.yaml

[bot-intent]: bot-intent.yaml
[bot-intent]: bot-intent.schema.yaml

[skipped-turn-event]: skipped-turn-event.yaml
[skipped-turn-event]: skipped-turn-event.schema.yaml

[game-ended-event-for-bot]: game-ended-event-for-bot.yaml
[game-ended-event-for-bot]: game-ended-event-for-bot.schema.yaml

[game-ended-event-for-observer]: game-ended-event-for-observer.yaml
[game-ended-event-for-observer]: game-ended-event-for-observer.schema.yaml

[won-round-event]: won-round-event.yaml
[won-round-event]: won-round-event.schema.yaml

[stop-game]: stop-game.yaml
[stop-game]: stop-game.schema.yaml

[game-aborted-event]: game-aborted-event.yaml
[game-aborted-event]: game-aborted-event.schema.yaml

[pause-game]: pause-game.yaml
[pause-game]: pause-game.schema.yaml

[next-turn]: next-turn.yaml
[next-turn]: next-turn.schema.yaml

[game-paused-event-for-observer]: game-paused-event-for-observer.yaml
[game-paused-event-for-observer]: game-paused-event-for-observer.schema.yaml

[resume-game]: resume-game.yaml
[resume-game]: resume-game.schema.yaml

[game-resumed-event-for-observer]: game-resumed-event-for-observer.yaml
[game-resumed-event-for-observer]: game-resumed-event-for-observer.schema.yaml

[change-tps]: change-tps.yaml
[change-tps]: change-tps.schema.yaml

[tps-changed-event]: tps-changed-event.yaml
[tps-changed-event]: tps-changed-event.schema.yaml

[bot-death-event]: bot-death-event.yaml
[bot-death-event]: bot-death-event.schema.yaml

[bot-hit-bot-event]: bot-hit-bot-event.yaml
[bot-hit-bot-event]: bot-hit-bot-event.schema.yaml

[bot-hit-wall-event]: bot-hit-wall-event.yaml
[bot-hit-wall-event]: bot-hit-wall-event.schema.yaml

[bullet-fired-event]: bullet-fired-event.yaml
[bullet-fired-event]: bullet-fired-event.schema.yaml

[bullet-hit-bot-event]: bullet-hit-bot-event.yaml
[bullet-hit-bot-event]: bullet-hit-bot-event.schema.yaml

[bullet-hit-bullet-event]: bullet-hit-bullet-event.yaml
[bullet-hit-bullet-event]: bullet-hit-bullet-event.schema.yaml

[bullet-hit-wall-event]: bullet-hit-wall-event.yaml
[bullet-hit-wall-event]: bullet-hit-wall-event.schema.yaml

[hit-by-bullet-event]: hit-by-bullet-event.yaml
[hit-by-bullet-event]: hit-by-bullet-event.schema.yaml

[scanned-bot-event]: scanned-bot-event.yaml
[scanned-bot-event]: scanned-bot-event.schema.yaml

[skipped-turn-event]: skipped-turn-event.yaml
[skipped-turn-event]: skipped-turn-event.schema.yaml

[tick-event-for-bot]: tick-event-for-bot.yaml
[tick-event-for-bot]: tick-event-for-bot.schema.yaml

[won-round-event]: won-round-event.yaml
[won-round-event]: won-round-event.schema.yaml

[team-message-event]: team-message-event.yaml
[team-message-event]: team-message-event.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$id: bot-address.yaml
$id: bot-address.schema.yaml
$schema: https://json-schema.org/draft/2020-12/schema
description: Bot address
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$id: bot-death-event.yaml
$id: bot-death-event.schema.yaml
$schema: https://json-schema.org/draft/2020-12/schema
description: Event occurring when a bot has died
extends:
$ref: event.yaml
$ref: event.schema.yaml
properties:
victimId:
description: id of the bot that has died
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$id: bot-handshake.yaml
$id: bot-handshake.schema.yaml
$schema: https://json-schema.org/draft/2020-12/schema
description: Bot handshake
extends:
$ref: message.yaml
$ref: message.schema.yaml
properties:
sessionId:
description: Unique session id that must match the session id received from the server handshake
Expand Down Expand Up @@ -56,7 +56,7 @@ properties:
maxLength: 30
initialPosition:
description: Initial start position of the bot used for debugging
$ref: initial-position.yaml
$ref: initial-position.schema.yaml
teamId:
description: Id of the team that this bot is a member of
type: integer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$id: bot-hit-bot-event.yaml
$id: bot-hit-bot-event.schema.yaml
$schema": https://json-schema.org/draft/2020-12/schema
description: Event occurring when a bot has collided with another bot
extends:
$ref: event.yaml
$ref: event.schema.yaml
properties:
victimId:
description: id of the victim bot that got hit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$id: bot-hit-wall-event.yaml
$id: bot-hit-wall-event.schema.yaml
$schema: https://json-schema.org/draft/2020-12/schema
description: Event occurring when a bot has hit a wall
extends:
$ref: event.yaml
$ref: event.schema.yaml
properties:
victimId:
description: id of the victim bot that hit the wall
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$id: bot-info.yaml
$id: bot-info.schema.yaml
$schema: https://json-schema.org/draft/2020-12/schema
description: Bot info
extends:
$ref: bot-handshake.yaml
$ref: bot-handshake.schema.yaml
properties:
host:
description: Host name or IP address
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
$id: bot-intent.yaml
$id: bot-intent.schema.yaml
$schema: https://json-schema.org/draft/2020-12/schema
description: |
The intent (request) sent from a bot each turn for controlling the bot and provide the server with data.
A field only needs to be set, if the value must be changed. Otherwise the server will use the field value from the
last time the field was set.
extends:
$ref: message.yaml
$ref: message.schema.yaml
properties:
turnRate:
description: Turn rate of the body in degrees per turn (can be positive and negative)
Expand Down Expand Up @@ -42,25 +42,25 @@ properties:
type: boolean
bodyColor:
description: New color of the body
$ref: color.yaml
$ref: color.schema.yaml
turretColor:
description: New color of the cannon turret
$ref: color.yaml
$ref: color.schema.yaml
radarColor:
description: New color of the radar
$ref: color.yaml
$ref: color.schema.yaml
bulletColor:
description: New color of the bullet. Note. This will be the color of a bullet when it is fired
$ref: color.yaml
$ref: color.schema.yaml
scanColor:
description: New color of the scan arc
$ref: color.yaml
$ref: color.schema.yaml
tracksColor:
description: New color of the tracks
$ref: color.yaml
$ref: color.schema.yaml
gunColor:
description: New color of the gun
$ref: color.yaml
$ref: color.schema.yaml
stdOut:
description: New text received from standard output (stdout)
type: string
Expand All @@ -72,4 +72,4 @@ properties:
type: array
maxItems: 4
items:
$ref: team-message.yaml
$ref: team-message.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
$id: bot-list-update.yaml
$id: bot-list-update.schema.yaml
$schema: https://json-schema.org/draft/2020-12/schema
description: Bot list update
extends:
$ref: message.yaml
$ref: message.schema.yaml
properties:
bots:
description: List of bots
type: array
items:
description: Bot info
$ref: bot-info.yaml
$ref: bot-info.schema.yaml
required:
- bots
Loading

0 comments on commit cc07bc2

Please sign in to comment.