Esempio n. 1
0
    protected IEnumerator Say(Expression e, float time)
    {
        // TODO: figure this stuff out
        // var eWithoutParameters = new Container<Expression>(null);
        // Agent.MentalState.StartCoroutine(Agent.MentalState.ReplaceParameters(e, eWithoutParameters));

        // while (eWithoutParameters.Item == null) {
        //     yield return null;
        // }

        // GameObject eContainer = ArgumentContainer.From(eWithoutParameters.Item);

        var eContainer = ArgumentContainer.From(e);
        ArgumentContainer eContainerScript = eContainer.GetComponent <ArgumentContainer>();

        eContainerScript.GenerateVisual();

        var display = Agent.gameObject.transform.Find("Display");

        eContainer.transform.position    = display.position;
        eContainer.transform.rotation    = display.rotation;
        eContainer.transform.localScale *= 0.5f;
        eContainer.transform.SetParent(display);

        yield return(new WaitForSeconds(time));

        Destroy(eContainer);
        yield break;
    }
Esempio n. 2
0
    GameObject SpawnArgumentContainer(Expression e, Vector3 pos, Quaternion rot)
    {
        var argContainer = ArgumentContainer.From(e);

        argContainer.GetComponent <ArgumentContainer>().GenerateVisual();
        argContainer.transform.position = pos;
        argContainer.transform.rotation = rot;

        return(argContainer);
    }
Esempio n. 3
0
    public GameObject SpawnExpression(Expression expression)
    {
        GameObject wordContainer = ArgumentContainer.From(expression);

        ArgumentContainer wordContainerScript =
            wordContainer.GetComponent <ArgumentContainer>();

        wordContainerScript.GenerateVisual();

        wordContainer.transform.SetParent(Workspace.transform);
        wordContainer.transform.localRotation = Quaternion.identity;

        int width  = wordContainerScript.Width;
        int height = wordContainerScript.Height;

        wordContainer.transform.localScale =
            new Vector3(0.125f * 0.875f * width, 0.125f * 0.875f * height, 1);

        // find the next available slot that
        // can accommodate the expression
        for (int i = 0; i < slotsY; i++)
        {
            for (int j = 0; j < slotsX; j++)
            {
                bool empty = true;
                for (int h = 0; h < height; h++)
                {
                    if (!empty)
                    {
                        break;
                    }
                    if (i + h >= slotsY)
                    {
                        empty = false;
                        break;
                    }
                    for (int w = 0; w < width; w++)
                    {
                        if (j + w >= slotsX)
                        {
                            empty = false;
                            break;
                        }
                        if (slots[i + h, j + w] != null)
                        {
                            empty = false;
                        }
                    }
                }

                // we've found a rectangular region
                // that can fit this new container
                if (empty)
                {
                    // here, we add the open arguments in this expression
                    // to a map which will be used when expressions of the
                    // right type are selected.
                    if (wordContainerScript.Argument is Expression)
                    {
                        List <Argument> arguments = new List <Argument>();
                        Expression      e         = (Expression)wordContainerScript.Argument;

                        int index = 0;
                        foreach (Transform child in wordContainer.transform)
                        {
                            var script = child.gameObject.GetComponent <ArgumentContainer>();
                            if (script == null)
                            {
                                continue;
                            }
                            if (script.Argument is Empty)
                            {
                                var newArguments = new List <Argument>();
                                foreach (Argument arg in newArguments)
                                {
                                    newArguments.Add(new Empty(arg.Type));
                                }
                                arguments.Add(script.Argument);
                                openArgumentSlots[i + 1, j + index] = new OpenArgumentInfo(j, i, script.gameObject, wordContainer, arguments);
                            }
                            index += script.Width;
                        }
                    }

                    // here, we set the container's position to the first available grid position.
                    wordContainer.transform.localPosition =
                        new Vector3(0.95f * (-0.5f + width / 16.0f + 0.125f * j),
                                    0.95f * ((0.5f - height / 16.0f) - 0.125f * i), -0.01f);

                    // if no pointer is active on the workspace, we set the pointer active
                    // to this expression.
                    if (!Pointer.active)
                    {
                        Pointer.active = true;
                        Pointer.transform.localPosition =
                            new Vector3(wordContainer.transform.localPosition.x,
                                        wordContainer.transform.localPosition.y + (3.0f * height / 32.0f),
                                        -0.01f);
                    }

                    // fill the slots in the grid with the ID
                    // of this container.
                    for (int h = 0; h < height; h++)
                    {
                        for (int w = 0; w < width; w++)
                        {
                            slots[i + h, j + w] = wordContainer;
                        }
                    }
                    return(wordContainer);
                }
            }
        }
        Destroy(wordContainer);
        return(null);

        // @NOTE the workspace should expand when there's
        // no room for another word.
        // Need to implement scroll and zoom.
        Debug.Log("no more room :'(");
    }