Localize block and param names
This commit is contained in:
parent
6045800d11
commit
e79c0dd6f7
|
@ -1,9 +1,11 @@
|
|||
package net.shadowfacts.asmr.program
|
||||
|
||||
import net.minecraft.util.Identifier
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
abstract class ExecutableBlock: ProgramBlock() {
|
||||
abstract class ExecutableBlock(identifier: Identifier): ProgramBlock(identifier) {
|
||||
|
||||
open val executionFlow = ExecutionFlow(this)
|
||||
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
package net.shadowfacts.asmr.program
|
||||
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.Language
|
||||
import net.shadowfacts.cacao.geometry.Point
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
abstract class ProgramBlock {
|
||||
abstract class ProgramBlock(val identifier: Identifier) {
|
||||
|
||||
var position: Point = Point.ORIGIN
|
||||
|
||||
abstract val inputs: Array<ProgramBlockInput<*>>
|
||||
abstract val outputs: Array<ProgramBlockOutput<*>>
|
||||
|
||||
fun translateName(): String {
|
||||
return Language.getInstance().translate("programblock.${identifier.namespace}.${identifier.path}")
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package net.shadowfacts.asmr.program
|
||||
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.Language
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
|
@ -26,4 +27,8 @@ class ProgramBlockInput<Type: Any>(
|
|||
source?.unlink(to = this)
|
||||
}
|
||||
|
||||
fun translateName(): String {
|
||||
return Language.getInstance().translate("programblock.param.${identifier.namespace}.${identifier.path}")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.shadowfacts.asmr.program
|
||||
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.Language
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
|
@ -26,4 +27,8 @@ class ProgramBlockOutput<Type: Any>(
|
|||
_destinations.remove(to)
|
||||
}
|
||||
|
||||
fun translateName(): String {
|
||||
return Language.getInstance().translate("programblock.param.${identifier.namespace}.${identifier.path}")
|
||||
}
|
||||
|
||||
}
|
|
@ -13,9 +13,11 @@ import net.shadowfacts.asmr.program.ProgramType
|
|||
class ConstantBlock<Type: Any>(
|
||||
val type: ProgramType<Type>,
|
||||
val value: Type
|
||||
): ProgramBlock() {
|
||||
): ProgramBlock(
|
||||
Identifier(ASMR.modid, "constant")
|
||||
) {
|
||||
|
||||
val output = ProgramBlockOutput(Identifier(ASMR.modid, "constant_output"), type, this).apply {
|
||||
val output = ProgramBlockOutput(Identifier(ASMR.modid, "constant.output"), type, this).apply {
|
||||
value = this@ConstantBlock.value
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,11 @@ import net.shadowfacts.cacao.geometry.Point
|
|||
*/
|
||||
class PrintBlock<Type: Any>(
|
||||
val type: ProgramType<Type>
|
||||
): ExecutableBlock() {
|
||||
): ExecutableBlock(
|
||||
Identifier(ASMR.modid, "print")
|
||||
) {
|
||||
|
||||
val input = ProgramBlockInput(Identifier(ASMR.modid, "print_input"), type, this)
|
||||
val input = ProgramBlockInput(Identifier(ASMR.modid, "print.input"), type, this)
|
||||
|
||||
override val inputs: Array<ProgramBlockInput<*>> = arrayOf(input)
|
||||
override val outputs: Array<ProgramBlockOutput<*>> = arrayOf()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.shadowfacts.asmr.program.blocks
|
||||
|
||||
import net.minecraft.util.Identifier
|
||||
import net.shadowfacts.asmr.ASMR
|
||||
import net.shadowfacts.asmr.program.ExecutableBlock
|
||||
import net.shadowfacts.asmr.program.ProgramBlockInput
|
||||
import net.shadowfacts.asmr.program.ProgramBlockOutput
|
||||
|
@ -7,7 +9,9 @@ import net.shadowfacts.asmr.program.ProgramBlockOutput
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class StartBlock: ExecutableBlock() {
|
||||
class StartBlock: ExecutableBlock(
|
||||
Identifier(ASMR.modid, "start")
|
||||
) {
|
||||
|
||||
override val inputs: Array<ProgramBlockInput<*>> = arrayOf()
|
||||
override val outputs: Array<ProgramBlockOutput<*>> = arrayOf()
|
||||
|
|
|
@ -14,7 +14,9 @@ import java.lang.RuntimeException
|
|||
class BinaryOperatorBlock<Type: Any>(
|
||||
val type: ProgramType<Type>,
|
||||
val operation: Operation
|
||||
): ExecutableBlock() {
|
||||
): ExecutableBlock(
|
||||
Identifier(ASMR.modid, "binary_operator")
|
||||
) {
|
||||
|
||||
init {
|
||||
if (type != ProgramType.INT && type != ProgramType.FLOAT) {
|
||||
|
@ -22,10 +24,10 @@ class BinaryOperatorBlock<Type: Any>(
|
|||
}
|
||||
}
|
||||
|
||||
val left = ProgramBlockInput(Identifier(ASMR.modid, "left_operand"), type, this)
|
||||
val right = ProgramBlockInput(Identifier(ASMR.modid, "right_operand"), type, this)
|
||||
val left = ProgramBlockInput(Identifier(ASMR.modid, "binary_operator.left_operand"), type, this)
|
||||
val right = ProgramBlockInput(Identifier(ASMR.modid, "binary_operator.right_operand"), type, this)
|
||||
|
||||
val output = ProgramBlockOutput(Identifier(ASMR.modid, "result"), type, this)
|
||||
val output = ProgramBlockOutput(Identifier(ASMR.modid, "binary_operator.result"), type, this)
|
||||
|
||||
override val inputs: Array<ProgramBlockInput<*>> = arrayOf(left, right)
|
||||
override val outputs: Array<ProgramBlockOutput<*>> = arrayOf(output)
|
||||
|
|
|
@ -48,7 +48,7 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
|
|||
zIndex = 10.0
|
||||
|
||||
val titleStack = addArrangedSubview(StackView(Axis.HORIZONTAL, Distribution.CENTER))
|
||||
val title = titleStack.addArrangedSubview(Label(block.javaClass.simpleName))
|
||||
val title = titleStack.addArrangedSubview(Label(block.translateName()))
|
||||
if (block is ExecutableBlock) {
|
||||
val incomingTexture = if (block.executionFlow.prev == null) emptyConnection else executionConnection
|
||||
incomingExecution = titleStack.addArrangedSubview(TextureView(incomingTexture), index = 0)
|
||||
|
@ -67,21 +67,16 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
|
|||
outgoingExeuction!!.widthAnchor equalTo outgoingExeuction!!.heightAnchor
|
||||
outgoingExeuction!!.widthAnchor equalTo 7
|
||||
}
|
||||
|
||||
|
||||
// for (paramView in inputViews.values) {
|
||||
// paramView.widthAnchor equalTo paramView.heightAnchor
|
||||
// paramView.widthAnchor equalTo 7
|
||||
// }
|
||||
}
|
||||
|
||||
for (i in 0 until max(block.inputs.size, block.outputs.size)) {
|
||||
val hStack = addArrangedSubview(StackView(Axis.HORIZONTAL, Distribution.CENTER))
|
||||
|
||||
block.inputs.getOrNull(i)?.let { input ->
|
||||
val inputView = hStack.addArrangedSubview(TextureView(if (input.source == null) emptyConnection else parameterConnection))
|
||||
val inputTexture = if (input.source == null) emptyConnection else parameterConnection
|
||||
val inputView = hStack.addArrangedSubview(TextureView(inputTexture))
|
||||
inputViews[input] = inputView
|
||||
val inputLabel = hStack.addArrangedSubview(Label(input.identifier.toString()))
|
||||
val inputLabel = hStack.addArrangedSubview(Label(input.translateName()))
|
||||
solver.dsl {
|
||||
hStack.heightAnchor equalTo inputLabel.heightAnchor
|
||||
|
||||
|
@ -96,8 +91,9 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
|
|||
}
|
||||
|
||||
block.outputs.getOrNull(i)?.let { output ->
|
||||
val outputLabel = hStack.addArrangedSubview(Label(output.identifier.toString(), textAlignment = Label.TextAlignment.RIGHT))
|
||||
val outputView = hStack.addArrangedSubview(TextureView(if (output.destinations.isEmpty()) emptyConnection else parameterConnection))
|
||||
val outputLabel = hStack.addArrangedSubview(Label(output.translateName(), textAlignment = Label.TextAlignment.RIGHT))
|
||||
val outputTexture = if (output.destinations.isEmpty()) emptyConnection else parameterConnection
|
||||
val outputView = hStack.addArrangedSubview(TextureView(outputTexture))
|
||||
outputViews[output] = outputView
|
||||
solver.dsl {
|
||||
hStack.heightAnchor equalTo outputLabel.heightAnchor
|
||||
|
@ -108,35 +104,6 @@ class ProgramBlockView(val block: ProgramBlock): StackView(Axis.VERTICAL, Distri
|
|||
}
|
||||
}
|
||||
|
||||
// val pairs = block.inputs.zip(block.outputs)
|
||||
// val remainingInputs = if (block.inputs.size > block.outputs.size) block.inputs.drop(block.outputs.size) else listOf()
|
||||
// val remainingOutputs = if (block.outputs.size > block.inputs.size) block.outputs.drop(block.inputs.size) else listOf()
|
||||
// for ((input, output) in pairs) {
|
||||
// val hStack = addArrangedSubview(StackView(Axis.HORIZONTAL, Distribution.CENTER))
|
||||
// val inputView = hStack.addArrangedSubview(TextureView(if (input.source == null) emptyConnection else parameterConnection))
|
||||
// inputViews[input] = inputView
|
||||
// val inputLabel = hStack.addArrangedSubview(Label(input.identifier.toString()))
|
||||
// val spacingView = hStack.addArrangedSubview(View())
|
||||
// hStack.addArrangedSubview(Label(output.identifier.toString()))
|
||||
//// outputViews[output] = hStack.addArrangedSubview(TextureView(if (output.destinations.isEmpty) emptyConnection else parameterConnection))
|
||||
//
|
||||
// solver.dsl {
|
||||
// hStack.heightAnchor equalTo inputLabel.heightAnchor
|
||||
//
|
||||
// inputView.widthAnchor equalTo inputView.heightAnchor
|
||||
// inputView.widthAnchor equalTo 7
|
||||
//
|
||||
// spacingView.widthAnchor equalTo 8
|
||||
// }
|
||||
// }
|
||||
|
||||
// for (input in remainingInputs) {
|
||||
// addArrangedSubview(Label(input.identifier.toString()))
|
||||
// }
|
||||
// for (output in remainingOutputs) {
|
||||
// addArrangedSubview(Label(output.identifier.toString(), textAlignment = Label.TextAlignment.RIGHT))
|
||||
// }
|
||||
|
||||
solver.dsl {
|
||||
for (view in arrangedSubviews.drop(1)) {
|
||||
widthAnchor.equalTo(view.widthAnchor, strength = STRONG)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"programblock.asmr.start": "Start",
|
||||
"programblock.asmr.constant": "Constant",
|
||||
"programblock.param.asmr.constant.output": "Output",
|
||||
"programblock.asmr.print": "Print",
|
||||
"programblock.param.asmr.print.input": "Print Value",
|
||||
"programblock.asmr.binary_operator": "Binary Math Operator",
|
||||
"programblock.param.asmr.binary_operator.left_operand": "Left Operand",
|
||||
"programblock.param.asmr.binary_operator.right_operand": "Right Operand",
|
||||
"programblock.param.asmr.binary_operator.result": "Result"
|
||||
}
|
Loading…
Reference in New Issue