Skip to content

Commit

Permalink
Allow for case-sensitibe attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo committed Jan 23, 2024
1 parent b5c4c16 commit a87f989
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Document/Obstacles/BaseObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface IBaseObject {

_uuid: string;
_objectType: string;
_caseSensitive: boolean;
_infoString: string;
_terminator: string;
children: Record<string, IBaseObject>;
Expand All @@ -31,6 +32,7 @@ export function newIBaseObject(
return {
_uuid: uuid,
_objectType: objectType,
_caseSensitive: false,
_infoString: '',
_terminator: 'end',
children: {},
Expand Down
1 change: 1 addition & 0 deletions src/Document/Obstacles/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export interface IOptions extends IBaseObject {
export function newIOptions(): IOptions {
return {
...newIBaseObject('options'),
_caseSensitive: true,
};
}

Expand Down
6 changes: 5 additions & 1 deletion src/Document/parseBZWDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ const ObjectBuilders: Record<string, ObjectBuilder> = {

function parseLine(line: string, object: IBaseObject, world: IWorld): void {
const spacePos = line.search(/[ ]|$/);
const attribute = line.substring(0, spacePos).toLowerCase();
const restOfLine = line.substr(spacePos + 1).trim();
let attribute = line.substring(0, spacePos);

if (!object._caseSensitive) {
attribute = attribute.toLowerCase();
}

const parser =
ObjectBuilders[object._objectType].parsers[attribute] ?? bzwString;
Expand Down

0 comments on commit a87f989

Please sign in to comment.