Skip to content

Commit

Permalink
v2.4.1 (#737)
Browse files Browse the repository at this point in the history
## Features:
- Ability to configure folder indentation (#730)
- Inline color picker for JSON files (#614)

## Fixes:
- Fixed transformFiles compilation step overwriting files in rare cases (bridge-core/dash-compiler@8178e1d)
- Fixed "molang" plugin no longer transforming Molang statements (#732)
- Fixed custom item components using the player API (#489)
- Dash now creates a default hooks map upon loading cache file (bridge-core/dash-compiler@4741b92)
- Fixed generator scripts generating files to wrong output location (#735) 
- "useTemplate" within generator scripts now works reliably (bridge-core/dash-compiler@7a26aff)
  • Loading branch information
solvedDev authored Nov 20, 2022
1 parent 8cba120 commit b81f543
Show file tree
Hide file tree
Showing 19 changed files with 772 additions and 32 deletions.
47 changes: 25 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bridge",
"version": "2.4.0",
"version": "2.4.1",
"private": true,
"scripts": {
"dev": "vite",
Expand All @@ -16,20 +16,20 @@
"@types/lz-string": "^1.3.34",
"bridge-common-utils": "^0.3.3",
"bridge-iframe-api": "^0.4.11",
"bridge-js-runtime": "^0.3.6",
"bridge-js-runtime": "^0.4.1",
"bridge-model-viewer": "^0.7.7",
"buffer": "^6.0.3",
"color-convert": "^2.0.1",
"comlink": "^4.3.0",
"compare-versions": "^3.6.0",
"core-js": "^3.6.5",
"dash-compiler": "^0.10.7",
"dash-compiler": "^0.10.8",
"escape-string-regexp": "^5.0.0",
"fflate": "^0.6.7",
"idb-keyval": "^5.1.3",
"is-glob": "^4.0.1",
"json5": "^2.1.3",
"jsonc-parser": "^3.0.0",
"jsonc-parser": "^3.2.0",
"lodash-es": "^4.17.20",
"lz-string": "^1.4.4",
"mc-project-core": "^0.3.22",
Expand Down
3 changes: 1 addition & 2 deletions src/components/Extensions/Scripts/JsRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export class JsRuntime extends Runtime {
const app = await App.getApp()

const file = await app.fileSystem.readFile(filePath)
const fileContent = await file.text()

return fileContent
return file
}

run(filePath: string, env: any = {}, fileContent?: string) {
Expand Down
81 changes: 81 additions & 0 deletions src/components/Languages/Json/ColorPicker/Color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type { languages } from 'monaco-editor'
import { toTwoDigitHex } from './parse/hex'

export class Color {
constructor(public colorInfo: languages.IColor) {}

/**
* Formats the color as #RRGGBB
*/
toHex() {
return `#${toTwoDigitHex(this.colorInfo.red * 255)}${toTwoDigitHex(
this.colorInfo.green * 255
)}${toTwoDigitHex(this.colorInfo.blue * 255)}`
}

/**
* Formats the color as #RRGGBBAA
*/
toHexA() {
return `#${toTwoDigitHex(this.colorInfo.red * 255)}${toTwoDigitHex(
this.colorInfo.green * 255
)}${toTwoDigitHex(this.colorInfo.blue * 255)}${toTwoDigitHex(
Math.round(this.colorInfo.alpha * 255)
)}`
}

/**
* Formats the color as #AARRGGBB
*/
toAHex() {
return `#${toTwoDigitHex(
Math.round(this.colorInfo.alpha * 255)
)}${toTwoDigitHex(this.colorInfo.red * 255)}${toTwoDigitHex(
this.colorInfo.green * 255
)}${toTwoDigitHex(this.colorInfo.blue * 255)}`
}

/**
* Formats the color as [r, g, b], 0-1
*/
toDecRgbArray() {
return [
+this.colorInfo.red.toFixed(5),
+this.colorInfo.green.toFixed(5),
+this.colorInfo.blue.toFixed(5),
]
}
/**
* Formats the color as [r, g, b], 0-255
*/
toRgbArray() {
return [
Math.round(this.colorInfo.red * 255),
Math.round(this.colorInfo.green * 255),
Math.round(this.colorInfo.blue * 255),
]
}

/**
* Formats the color as [r, g, b, a] 0-1
*/
toDecRgbaArray() {
return [
+this.colorInfo.red.toFixed(5),
+this.colorInfo.green.toFixed(5),
+this.colorInfo.blue.toFixed(5),
this.colorInfo.alpha,
]
}
/**
* Formats the color as [r, g, b, a], 0-255
*/
toRgbaArray() {
return [
Math.round(this.colorInfo.red * 255),
Math.round(this.colorInfo.green * 255),
Math.round(this.colorInfo.blue * 255),
Math.round(this.colorInfo.alpha * 255),
]
}
}
146 changes: 146 additions & 0 deletions src/components/Languages/Json/ColorPicker/ColorPicker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { useMonaco } from '/@/utils/libs/useMonaco'
import type { editor, CancellationToken, languages } from 'monaco-editor'
import { Color } from './Color'
import { findColors } from './findColors'
import { parseColor } from './parse/main'

export async function registerColorPicker() {
const { languages, Position, Range } = await useMonaco()

languages.registerColorProvider('json', {
provideDocumentColors: async (
model: editor.ITextModel,
token: CancellationToken
) => {
return await findColors(model)
},
provideColorPresentations: async (
model: editor.ITextModel,
colorInfo: languages.IColorInformation,
token: CancellationToken
) => {
const newColor = new Color(colorInfo.color)
const value = model.getValueInRange(colorInfo.range)
const position = new Position(
colorInfo.range.startLineNumber,
colorInfo.range.startColumn + 2
)

// We need to decide which format this color is supposed to be in by doing 2 things:
// 1. Parse the value to find the format
// 2. Check the json path against valid locations to confirm the format, if necessary

/**
* Takes an array as a string and inserts values into the array while preserving whitespace
*/
const insertToStringArray = (arr: string, newValues: any[]) => {
const valueTest = /(\d+(?:\.\d*)?)/gim
const split = arr.split(',')
let newArr = ''
// If the number of values to replace != the number of values available replace just return the orignal value
if (split.length !== newValues.length) return arr
for (const [i, value] of newValues.entries()) {
// Get the first value to replace
const toReplace = split[i].match(valueTest)
// If there is something to replace, replace it
if (toReplace && toReplace[0])
newArr += `${split[i].replace(toReplace[0], value)}${
i + 1 === newValues.length ? '' : ',' // Comma after value if not last element
}`
}
return newArr
}

const { format } = await parseColor(value, {
model,
position,
})

switch (format) {
case 'hex':
return [
{
label: `"${newColor.toHex().toUpperCase()}"`,
},
]
case 'hexa':
return [
{
label: `"${newColor.toHexA().toUpperCase()}"`,
},
]
case 'ahex':
return [
{
label: `"${newColor.toAHex().toUpperCase()}"`,
},
]

case 'rgbDec':
return [
{
label: `[${newColor.toDecRgbArray().join(', ')}]`,
textEdit: {
range: colorInfo.range,
text: insertToStringArray(
value,
newColor.toDecRgbArray()
),
},
},
]
case 'rgb':
return [
{
label: `[${newColor.toRgbArray().join(', ')}]`,
textEdit: {
range: colorInfo.range,
text: insertToStringArray(
value,
newColor.toRgbArray()
),
},
},
]
case 'rgbaDec':
return [
{
label: `[${newColor.toDecRgbaArray().join(', ')}]`,
textEdit: {
range: colorInfo.range,
text: insertToStringArray(
value,
newColor.toDecRgbaArray()
),
},
},
]
case 'rgba':
return [
{
label: `[${newColor.toRgbaArray().join(', ')}]`,
textEdit: {
range: colorInfo.range,
text: insertToStringArray(
value,
newColor.toRgbaArray()
),
},
},
]

default:
// If all fails, don't do anything to be safe
return [
{
label: '',
textEdit: {
range: new Range(0, 0, 0, 0),
text: '',
},
},
]
}
},
})
}
Loading

0 comments on commit b81f543

Please sign in to comment.