Skip to content

Commit

Permalink
Merge 8989df8 into ed373f4
Browse files Browse the repository at this point in the history
  • Loading branch information
cazala committed Jul 24, 2023
2 parents ed373f4 + 8989df8 commit 89940e4
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 34 deletions.
11 changes: 8 additions & 3 deletions src/Manifest/Manifest.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,21 @@ export class ManifestRouter extends Router {

async upsertManifest(req: AuthRequest) {
const id = server.extractFromReq(req, 'id')
const manifestJSON: any = server.extractFromReq(req, 'manifest')
const manifestJSONMaybe: any = server.extractFromReq(req, 'manifest')
const eth_address = req.auth.ethAddress

console.log('aca')
const validate = validator.compile(manifestSchema)
validate(manifestJSON)
console.log('saca')
validate(manifestJSONMaybe)
console.log('paca')
const manifestJSON: ManifestAttributes = manifestJSONMaybe

if (validate.errors) {
throw new HTTPError('Invalid schema', validate.errors)
}

console.log('taca')

const canUpsert = await new Ownable(Project).canUpsert(id, eth_address)
if (!canUpsert) {
throw new HTTPError(
Expand Down
72 changes: 43 additions & 29 deletions src/Manifest/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,56 @@ export function collectStatistics(
): ProjectStatisticsAttributes {
const { project, scene } = manifest

const result = Object.keys(scene.components).reduce(
(result, key) => {
const component = scene.components[key]
if (scene.sdk6) {
const result = Object.keys(scene.sdk6.components).reduce(
(result, key) => {
const component = scene.sdk6.components[key]

switch (component.type) {
case ComponentType.GLTFShape:
result.gltf_shapes += 1
break
case ComponentType.NFTShape:
result.nft_shapes += 1
break
case ComponentType.Script:
result.scripts += 1
break
case ComponentType.Transform:
result.transforms += 1
break
}
switch (component.type) {
case ComponentType.GLTFShape:
result.gltf_shapes += 1
break
case ComponentType.NFTShape:
result.nft_shapes += 1
break
case ComponentType.Script:
result.scripts += 1
break
case ComponentType.Transform:
result.transforms += 1
break
}

return result
},
{
return result
},
{
cols: project.cols,
rows: project.rows,
parcels: project.rows * project.cols,
entities:
Object.keys(scene.sdk6.entities).length - project.rows * project.cols,
transforms: 0,
scripts: 0,
gltf_shapes: 0,
nft_shapes: 0,
} as ProjectStatisticsAttributes
)

result.transforms = result.transforms - project.rows * project.cols
result.gltf_shapes -= 1

return result
} else {
return {
cols: project.cols,
rows: project.rows,
parcels: project.rows * project.cols,
entities:
Object.keys(scene.entities).length - project.rows * project.cols,
// TODO: gather metrics from SDK7
entities: 0,
transforms: 0,
scripts: 0,
gltf_shapes: 0,
nft_shapes: 0,
} as ProjectStatisticsAttributes
)

result.transforms = result.transforms - project.rows * project.cols
result.gltf_shapes -= 1

return result
}
}
}
54 changes: 52 additions & 2 deletions src/Scene/Scene.types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
export type SceneAttributes = {
export type SceneAttributes =
| {
sdk6: SceneSDK6Attributes
sdk7: null
}
| {
sdk6: null
sdk7: SceneSDK7Attributes
}

export type SceneSDK6Attributes = {
entities: Record<string, SceneEntityAttributes>
components: Record<string, SceneComponentAttribute>
}

export type SceneSDK7Attributes = {
composite: string
mappings: Record<string, string>
}

export type SceneEntityAttributes = {
id: string
name: string
Expand All @@ -22,7 +37,7 @@ export enum ComponentType {
Script = 'Script',
}

export const sceneSchema = {
export const sceneSchemaSdk6 = {
type: 'object',
properties: {
entities: {
Expand All @@ -37,3 +52,38 @@ export const sceneSchema = {
additionalProperties: true,
required: ['entities', 'components'],
}

export const sceneSchemaSdk7 = {
type: 'object',
properties: {
composite: {
type: 'string',
},
mappings: {
type: 'string',
},
},
additionalProperties: true,
required: ['composite', 'mappings'],
}

export const sceneSchema = {
anyOf: [
// TODO: eventually remove old schema
sceneSchemaSdk6,
{
type: 'object',
properties: {
sdk6: sceneSchemaSdk6,
sdk7: { type: 'null' },
},
},
{
type: 'object',
properties: {
sdk6: { type: 'null' },
sdk7: sceneSchemaSdk7,
},
},
],
}

0 comments on commit 89940e4

Please sign in to comment.