Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Commit

Permalink
hex-tree: use Entity#render() when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
city41 committed Jun 15, 2021
1 parent 44785c4 commit 2a45837
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 48 deletions.
37 changes: 6 additions & 31 deletions src/components/hex-tree/HexTreePage/RenderLevel/LevelObject.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import clsx from 'clsx';
import { TILE_SIZE } from '../../../../tiles/constants';
import { LevelTreeObject } from '../../types';
import { ObjectIcon } from '../entityIcons';
Expand All @@ -10,7 +9,6 @@ import {
} from '../util';
import { Entity } from '../../../../entities/types';
import { EntityType } from '../../../../entities/entityMap';
import { HiddenBlock } from '../../../../entities/HiddenBlock';

type LevelObjectProps = {
object: LevelTreeObject;
Expand Down Expand Up @@ -79,36 +77,13 @@ function LevelObject({ object, scale, objectSet }: LevelObjectProps) {
backgroundSize: TILE_SIZE,
};

if (entityDefViaPayload) {
const payloadType = getPayloadType(
entityDefViaPayload.payloadToObjectId!,
object.id
);

const payloadStyle = {
position: 'absolute',
backgroundSize: 'cover',
bottom: 0,
right: 0,
width: scale * TILE_SIZE * 0.75,
height: scale * TILE_SIZE * 0.75,
} as const;
if (entityDef && entityDef.editorType === 'entity') {
const payload =
(entityDefViaPayload &&
getPayloadType(entityDefViaPayload.payloadToObjectId!, object.id)) ||
null;

return (
<div
className={clsx('relative cursor-pointer', {
'border-2 border-dashed border-green-300': entityDef === HiddenBlock,
})}
style={style}
>
<ObjectIcon
className="absolute top-0 left-0"
entityType={entityType}
style={style}
/>
<div style={payloadStyle} className={`${payloadType}-bg`} />
</div>
);
return entityDef.render(false, { payload }, () => {});
} else {
return (
<ObjectIcon
Expand Down
38 changes: 22 additions & 16 deletions src/components/hex-tree/HexTreePage/RenderLevel/LevelSprite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,28 @@ function LevelSprite({ sprite, scale }: LevelSpriteProps) {
const width = tileWidth * TILE_SIZE * scale;
const height = tileHeight * TILE_SIZE * scale;

const style = {
width,
height,
backgroundSize: 'cover',
// TODO: sprites should be positioning themselves so they can account for
// the fact that y is based on their bottom, not top. For now, a lil
// hack with negative margin...
marginTop: -((height - TILE_SIZE) * scale),
};
return (
<SpriteIcon
className="cursor-pointer"
entityType={spriteType}
style={style}
/>
);
const body = spriteDef?.render(false, {}, () => {});

if (body) {
return body;
} else {
const style = {
width,
height,
backgroundSize: 'cover',
// TODO: sprites should be positioning themselves so they can account for
// the fact that y is based on their bottom, not top. For now, a lil
// hack with negative margin...
marginTop: -((height - TILE_SIZE) * scale),
};
return (
<SpriteIcon
className="cursor-pointer"
entityType={spriteType}
style={style}
/>
);
}
}

export { LevelSprite };
6 changes: 5 additions & 1 deletion src/components/hex-tree/HexTreePage/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export function getEntityDefFromId(
return false;
}

return ed.objectId === obj.id && obj.bank === ed.emptyBank;
return (
(ed.objectId === obj.id ||
(ed.alternateObjectIds ?? []).includes(obj.id)) &&
obj.bank === ed.emptyBank
);
}) ?? null
);
}
Expand Down

1 comment on commit 2a45837

@vercel
Copy link

@vercel vercel bot commented on 2a45837 Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.