Skip to content

Commit

Permalink
Merge pull request #77 from TheMrZZ/develop
Browse files Browse the repository at this point in the history
Fixed a bunch of bugs
  • Loading branch information
TheMrZZ authored Apr 5, 2021
2 parents e4e1680 + 29e9da6 commit df6ef4d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sandstone",
"description": "Sandstone, a Typescript library for Minecraft datapacks.",
"version": "0.10.1",
"version": "0.10.2",
"author": "TheMrZZ - Florian ERNST",
"bugs": {
"url": "https://github.com/TheMrZZ/sandstone/issues"
Expand Down
11 changes: 6 additions & 5 deletions src/arguments/jsonTextComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type { VectorClass } from '@variables/Coordinates'
import type { LiteralUnion } from '../generalTypes'
import type { BASIC_COLORS } from './basics'
import type { MultipleEntitiesArgument, SelectorArgument } from './selector'

// To be valid, a chat component must contain one content tag: text, translate, score, selector, keybind, or nbt.
type ContentTag = {
type ContentTag = ({
/** A string containing plain text to display directly. Can also be a number or boolean that is displayed directly. */
text: string | number | boolean
} | {
Expand Down Expand Up @@ -78,12 +79,13 @@ type ContentTag = {
block: string | VectorClass<[string, string, string]>
} | {
/** The target selector for the entity or entities from which the NBT value is obtained. */
entity: string
entity: MultipleEntitiesArgument
} | {
/** The namespaced ID of the command storage from which the NBT value is obtained */
storage: string
})
)
)

type ChildrenTags = {
/**
Expand All @@ -92,7 +94,7 @@ type ChildrenTags = {
* Child text components inherit all formatting and interactivity from the parent component,
* unless they explicitly override them.
*/
with?: TextComponentObject[]
extra?: TextComponentObject[]
}

type FormattingTags = {
Expand Down Expand Up @@ -224,8 +226,7 @@ type InteractivityTags = {
* A JSON text component object.
*/
export type TextComponentObject = (
// eslint-disable-next-line @typescript-eslint/ban-types
(ContentTag | {}) & ChildrenTags & FormattingTags & InteractivityTags
ContentTag & ChildrenTags & FormattingTags & InteractivityTags
)

/**
Expand Down
4 changes: 2 additions & 2 deletions src/datapack/BasePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type BasePathOptions<N extends (undefined | string), D extends (undefined
directory?: D
}

export type BasePathInstance<N extends (undefined | string), D extends (undefined | string)> = (
export type BasePathInstance<N extends (undefined | string) = (undefined | string), D extends (undefined | string) = (undefined | string)> = (
HideFunctionProperties<BasePathClass<N, D>['getResourceName'] & BasePathClass<N, D>>
)

Expand All @@ -36,7 +36,7 @@ function pathToArray(path?: string): string[] {
}

/** Changes the base namespace & directory of nested resources. */
export class BasePathClass<N extends (undefined | string), D extends (undefined | string)> {
export class BasePathClass<N extends (undefined | string) = (undefined | string), D extends (undefined | string) = (undefined | string)> {
protected datapack: Datapack

namespace: N
Expand Down
27 changes: 17 additions & 10 deletions src/flow/Flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,19 +577,26 @@ export class Flow {
return undefined as any
}

const promise = this.flowStatementAsync(callback, {
callbackName: type,
initialCondition: type === 'while',
loopCondition: true,
condition,
})
const { currentFunction: parentFunction } = this.datapack

return {
then: (onfulfilled: () => void) => {
promise.then(() => {
this.datapack.createEnterChildFunction(ASYNC_CALLBACK_NAME)
onfulfilled?.()
then: async (onfulfilled: () => void) => {
// In theory, we are already in the parent function so we shouldn't need to go back in it.

// Run the previous code
await this.flowStatementAsync(callback, {
callbackName: type,
initialCondition: type === 'while',
loopCondition: true,
condition,
})

// Go back in the parent function, because we don't know where the last code ended up.
this.datapack.currentFunction = parentFunction

// Finally enter the callback function
this.datapack.createEnterChildFunction(ASYNC_CALLBACK_NAME)
return onfulfilled?.()
},
} as PromiseLike<void> as any
}
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { dataPack } from './init'

// CORE
export { SandstoneConfig } from './datapack/Datapack'

export const {
save: savePack, BasePath, sleep,
} = dataPack
Expand Down Expand Up @@ -37,8 +35,8 @@ export const {

// TYPES
export * from './arguments'
export type { BasePathClass, BasePathOptions } from './datapack/BasePath'
export type { MCFunctionInstance } from './datapack/Datapack'
export * from './datapack/BasePath'
export * from './datapack/Datapack'
export type { LiteralUnion } from './generalTypes'
export type {
AdvancementInstance, LootTableInstance, MCFunctionOptions, PredicateInstance, RecipeInstance, ResourceInstance, TagInstance,
Expand Down

0 comments on commit df6ef4d

Please sign in to comment.