Skip to content

Commit

Permalink
optimize code, use attribute getter
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Höhn <mail@stefanhoehn.com>
  • Loading branch information
stefan-hoehn committed Dec 10, 2023
1 parent 0ba211b commit 0dc9ff1
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Blockly from 'blockly'
import { javascriptGenerator } from 'blockly/javascript'
import { blockGetCheckedInputType } from '@/assets/definitions/blockly/utils.js';
import { blockGetCheckedInputType } from '@/assets/definitions/blockly/utils.js'

export default function (f7, isGraalJs) {
/*
Expand Down Expand Up @@ -69,17 +69,13 @@ export default function (f7, isGraalJs) {
const inputType = blockGetCheckedInputType(block, 'item')
let attributeName = block.getFieldValue('attributeName')

if (!isGraalJs) {
attributeName = attributeName.charAt(0).toLowerCase() + attributeName.slice(1)
let code = (inputType === 'oh_item') ? `items.getItem(${theItem}).rawState.${attributeName}` : `${theItem}.rawState.${attributeName}`
return [code, 0]
let code = ''
if (isGraalJs) {
code = (inputType === 'oh_item') ? `items.getItem(${theItem}).rawState.get${attributeName}()` : `${theItem}.rawState.get${attributeName}()`
} else {
if (attributeName === 'Tags' || attributeName === 'GroupNames') {
return [`Java.from(${theItem}.getRawState().get${attributeName}())`, 0]
} else {
return [`${theItem}.getRawState().get${attributeName}()`, 0]
}
code = (inputType === 'oh_item') ? `itemRegistry.getItem(${theItem}).getRawState().get${attributeName}()` : `${theItem}.getRawState().get${attributeName}()`
}
return [code, 0]
}

/*
Expand Down

0 comments on commit 0dc9ff1

Please sign in to comment.