Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parametros andando - Proceds blockly parte 1 #1

Merged
merged 9 commits into from
Jul 17, 2024

Conversation

dlopezalvas
Copy link
Contributor

@dlopezalvas dlopezalvas commented Jul 10, 2024

Related Program-AR/pilas-bloques-app#248

Por ahora solo andan los parámetros (crear y eliminar) pero pense en ir tirando ya un PR con esto para que no sea una cosa enorme para hacer review mas adelante.

Grabación de pantalla desde 10-07-24 16_20_53(1)

Se puede probar en la branch proceds-blockly de pilas.

Falta:

  • Hay un bug que deja que tengas dos procedimientos de igual nombre, todavía no lo logre resolver, quedaron algunas funciones auxiliares en este PR que era para tratar de ver eso.
  • Las manitos (tanto del procedimiento como de los parámetros) no andan, todavía no logro entender del todo qué es lo que se está haciedo para que ande:(
  • Las demás funciones además del makeProcedureInit que se pisan al definir los procedimientos nuestros.
  • Que aparezcan en el toolbox los procedimienos al crearlos.

@dlopezalvas dlopezalvas requested review from a team and danielferro69 July 10, 2024 18:58
/**
* Plugin description.
*/
export class Plugin {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se tomo la decisión de ir por un objeto en lugar de una clase porque habían conflictos con las definiciones de this por como estaban definidas ciertas cosas.
Con @rgonzalezt habíamos intentado hacerlo andar pero fallaba, podemos darle otra vuelta si consideran necesario.

Comment on lines +20 to +22
updateParams_: () => { },
/* customContextMenu: makeProcedureCustomMenu(),
domToMutation: makeProcedureDomToMutation(), */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El updateParams estaba así en https://github.com/Program-AR/proceds-blockly, las otras dos son las que faltan.

Comment on lines +27 to +36
export const allProcedures = (workspace) => workspace.getAllBlocks().filter(isProcedure)

const getName = (procedureBlock) => procedureBlock.getFieldValue('NAME')

const isProcedure = (block) => block.type === 'Procedimiento'

export const allProcedureNames = (workspace) => allProcedures(workspace).map(getName)

//TODO no anda
const findLegalName = (name, block, index) => allProcedureNames(block.workspace).includes(name) ? findLegalName(name + " " + index, block, index + 1) : name
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El findLegalName que viene con Blockly no está funcionando, yo asumo que puede ser porque al momento de chequear, los procedimientos tienen la definición de Procedimiento y no de procedure_defnoreturn, pero no lo sé. Intenté hacer un propio findLegalName, pero no anduvo, lo voy a revisar en el proximo PR.

Comment on lines +54 to +60
var addParameterButton = new Blockly.FieldImage(
PLUS,
16,
16,
Blockly.Msg.PROCEDURES_ADD_PARAMETER,
() => addParameter(block, Blockly, undefined)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este es el botón del +.

Proceds Blockly tocaba la definicion de FieldImage para solucionar algo pero como anda bien el click no lo agregué, si es necesario lo agregamos. Puede que sea algo que la nueva versión de blockly ya tenga solucionada

Comment on lines +62 to +67
var input = block.appendDummyInput()
.appendField(title)
.appendField(nameField, 'NAME')
.appendField('', 'PARAMS')

block.appendStatementInput("STACK").setCheck(null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto crea la estructura visible, agrega los fields que uno ve en el parámetro.

Comment on lines +96 to 99
const getAvailableName = (block, name) => {
const isTaken = block.arguments_.some(arg => arg === name);
return isTaken ? getAvailableName(block, name + "_") : name
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo cambie un poco a como estaba pero por cuestión de gusto personal jeje

Comment on lines +110 to +114
const callers = Blockly.Procedures.getCallers(self.getFieldValue('NAME'), self.workspace);
callers.forEach(caller => {
caller.arguments_.push(name);
caller.updateShape_()
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto teoricamente (falta probarlo) toma los bloques que son callers del procedimiento para agregarles el parámetro nuevo

Comment on lines +124 to +130
const removeParameterButton = new Blockly.FieldImage(
MINUS,
16,
16,
Blockly.Msg.PROCEDURES_REMOVE_PARAMETER,
() => removeParameter(self, argsAmount, Blockly)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Botón para quitar un parámetro, se le da el argsAmount como identificador del parámetro (que al agregarlo siempre es el último, o sea la cantidad de argumentos), para que luego sepa cual quitar.

Comment on lines +132 to +144
const nameField = new Blockly.FieldTextInput(name, function (newName) {
const oldName = self.arguments_[argsAmount];

if (oldName !== newName)
newName = getAvailableName(self, newName);

self.arguments_[argsAmount] = newName;

callers.forEach(caller => {
caller.arguments_ = caller.arguments_.map(argName => argName === oldName ? newName : argName)
caller.updateShape_()
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esta función se ejecuta cuando se cambia el text field de un parámetro, es decir el nombre. Si el nombre existe se le agrega un _ al final.

Cambia también el nombre en los callers del procedimiento.

Comment on lines +146 to +153
TODO: this changes the argument blocks when the name of the argument changes
const varBlocks = self.workspace.getAllBlocks().filter(block.type === "variables_get" && block.$parent === self.id)
varBlocks.forEach(varBlock => {
var varField = varBlock.getField("VAR");
if (varField.getValue() === oldName) {
varField.setValue(newName);
}
}) */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto no andaba, pero como no logré generar los bloques de los parámetros tampoco se puede probar mucho.

Comment on lines +158 to +165
self
.appendDummyInput(id)
.appendField(Blockly.Msg.PROCEDURES_BEFORE_PARAMS)
.appendField(nameField, 'ARG' + argsAmount)
.appendField(createCallButton)
.appendField(removeParameterButton);

self.moveInputBefore(id, 'STACK');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crea la estructura de los parámetros y los mueve antes del stack (el espacio abierto donde van los bloques hijos).

Comment on lines +169 to +175
const removeParameter = (self, argsAmount, Blockly) => {
let arguments_ = self.arguments_
self.arguments_.forEach((_, i) => self.removeInput("INPUTARG" + i))
self.arguments_ = []
arguments_.splice(argsAmount, 1)

arguments_.forEach(arg => addParameter(self, Blockly, arg))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto también lo cambie un poco, como traía problemas sacar uno del medio directamente hice que se borraran todos y se agregaran nuevamente todos excepto al que se quito. La estrategia de proceds-blockly era similar pero me mareaba un poco más.

Comment on lines +186 to +192
const createCall = (self, Blockly) => {
console.log("create call")
}

const createParameterCaller = (procedureBlock, name) => {
console.log("create parameter call")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faltan

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quizá la accion de la manito (el createCall) del procedimiento (o de los parametros) pueda resolverse rapidamente con algo asi como

 Blockly.serialization.blocks.append({
                    'type': self.type,
                }, self.workspace)

aunque esto duplica el bloque, en relidad lo siguiente:

  Blockly.serialization.blocks.append({
    'type': "procedures_callnoreturn",
    'fields': { 'NAME' :getName(self) }
}, self.workspace)

logra que genere el bloque del procedimiento a usar.

vokoscreenNG-2024-07-15_10-30-33.mp4

Hay que ver cómo sumarlo al toolbox

Copy link

@danielferro69 danielferro69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo esta funcional. hay un error en

 const createCallButton = new Blockly.FieldImage(
    HAND,
    16,
    16,
    Blockly.Msg.VARIABLES_SET_CREATE_GET.replace('%1', name),
    () => createParameterCaller(self, self.getVars()[argsAmount])()
  )

que la funcion getVars() no existe. Como para lograr generar los bloques de los parametros.
Vamos bien !!!

Comment on lines +186 to +192
const createCall = (self, Blockly) => {
console.log("create call")
}

const createParameterCaller = (procedureBlock, name) => {
console.log("create parameter call")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quizá la accion de la manito (el createCall) del procedimiento (o de los parametros) pueda resolverse rapidamente con algo asi como

 Blockly.serialization.blocks.append({
                    'type': self.type,
                }, self.workspace)

aunque esto duplica el bloque, en relidad lo siguiente:

  Blockly.serialization.blocks.append({
    'type': "procedures_callnoreturn",
    'fields': { 'NAME' :getName(self) }
}, self.workspace)

logra que genere el bloque del procedimiento a usar.

vokoscreenNG-2024-07-15_10-30-33.mp4

Hay que ver cómo sumarlo al toolbox

@dlopezalvas dlopezalvas merged commit dc25ee4 into main Jul 17, 2024
@dlopezalvas dlopezalvas deleted the copy-proceds-blockly branch July 17, 2024 13:58
@dlopezalvas dlopezalvas mentioned this pull request Jul 17, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants