Exemple #1
0
        private void dict_New(object sender, EventArgs e)
        {
            blockDetails.Columns.Clear();
            blockDetails.Rows.Clear();

            AddDefaultColumns();

            mDictionary = new BlockDictionary();
            mFilename = null;
        }
Exemple #2
0
        public editor_Form()
        {
            InitializeComponent();

            mDictionary = new BlockDictionary();
            mFilename = null;

            String filter = "Block Dictionaries (*.dict)|*.dict|All Files|*";
            dialog_Open.Filter = filter;
            dialog_Save.Filter = filter;
        }
Exemple #3
0
        private void Update()
        {
            Camera camera = Camera.main;

            if (!camera)
            {
                return;
            }

            Vector3Int pos = camera.transform.position.ToIntVec();

            if (BlockDictionary.Get(World.Get.GetBlock(pos.x, pos.y, pos.z)).Order == MeshOrder.Fluid)
            {
                waterProfile.enabled  = true;
                normalProfile.enabled = false;
            }
            else
            {
                waterProfile.enabled  = false;
                normalProfile.enabled = true;
            }
        }
Exemple #4
0
    //! Called by MachineManager update coroutine.
    public override void UpdateMachine()
    {
        base.UpdateMachine();
        if (stateManager.initMachines == true && init == false)
        {
            BlockDictionary blockDictionary = playerController.GetComponent <BuildController>().blockDictionary;
            if (blockDictionary != null)
            {
                if (blockDictionary.meshDictionary.ContainsKey(machineName) && GetComponent <MeshFilter>() != null)
                {
                    GetComponent <MeshFilter>().mesh = blockDictionary.meshDictionary[machineName];
                }
            }
            gameManager.meshManager.SetMaterial(gameObject, machineName);
            modSoundCoroutine = StartCoroutine(GetAudioFile(this, GetComponent <AudioSource>(), machineName));
            init = true;
        }

        if (recipes == null)
        {
            recipes = GameObject.Find("Player").GetComponent <BuildController>().blockDictionary.GetMachineRecipes(machineName);
        }
    }
Exemple #5
0
        private void dict_Open(object sender, EventArgs e)
        {
            if (dialog_Open.ShowDialog() == DialogResult.OK)
            {
                String filename = dialog_Open.FileName;

                try
                {
                    blockDetails.Columns.Clear();
                    blockDetails.Rows.Clear();

                    mDictionary = BlockDictionary.FromFile(filename);

                    List<String> columns = mDictionary.GetAttributes();
                    foreach ( String col in columns )
                    {
                        blockDetails.Columns.Add(col, col);
                    }

                    Dictionary<int, BlockTemplate>.Enumerator templateEnum = mDictionary.GetEnumerator();
                    while ( templateEnum.MoveNext() )
                    {
                        int rowID = blockDetails.Rows.Add();

                        Dictionary<String, object>.Enumerator attrEnum = templateEnum.Current.Value.GetEnumerator();
                        while ( attrEnum.MoveNext() )
                        {
                            blockDetails.Rows[rowID].Cells[attrEnum.Current.Key].Value = attrEnum.Current.Value;
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Error loading dictionary:\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public static bool AnyCollision()
        {
            foreach (var player in GameManager.Get.Players.Values)
            {
                Vector3 min = player.transform.position - dim / 2;
                Vector3 max = player.transform.position + dim / 2;

                for (int x = (int)min.x; x <= (int)max.x; x++)
                {
                    for (int y = (int)(min.y - 0.3f); y <= (int)max.y; y++)
                    {
                        for (int z = (int)min.z; z <= (int)max.z; z++)
                        {
                            if (BlockDictionary.Get(World.Get.GetBlock(x, y, z)).Solid)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemple #7
0
        /// <summary>
        /// Recursive function to populate the tree.
        /// </summary>
        /// <param name="tv">The treeView control</param>
        /// <param name="entList">The entity list</param>
        /// <param name="blocks">The block collection</param>
        /// <param name="parentNode">The parent node. Can be null for root level nodes.</param>
        public static void PopulateTree(TreeView tv, List <Entity> entList, BlockDictionary blocks, TreeNode parentNode = null)
        {
            TreeNodeCollection nodes;

            if (parentNode == null)
            {
                tv.Nodes.Clear();
                nodes = tv.Nodes;
            }
            else
            {
                nodes = parentNode.Nodes;
            }

            for (int i = 0; i < entList.Count; i++)
            {
                IfcEntity ifcEntity = (IfcEntity)entList[i];

                string keyWord, name;

                ifcEntity.Identification.TryGetValue("KeyWord", out keyWord);

                ifcEntity.Identification.TryGetValue("Name", out name);

                TreeNode keyWordNode = null;

                foreach (TreeNode node in nodes)
                {
                    if (node.Text.Equals(keyWord))
                    {
                        keyWordNode = node;
                        break;
                    }
                }
                if (keyWordNode == null)
                {
                    keyWordNode                    = new TreeNode(keyWord);
                    keyWordNode.ImageIndex         = 1;
                    keyWordNode.SelectedImageIndex = 1;
                    nodes.Add(keyWordNode);
                }
                TreeNode nameNode = new TreeNode(name);

                nameNode.Tag = entList[i];

                nameNode.ImageIndex = 1;

                nameNode.SelectedImageIndex = 1;

                keyWordNode.Nodes.Add(nameNode);

                //if (ent is BlockReference)
                //{
                //    Block child;
                //    string blockName = ((BlockReference)ent).BlockName;

                //    if (blocks.TryGetValue(blockName, out child))
                //    {
                //        TreeNode parentTn = new TreeNode(GetNodeName(blockName, i));
                //        parentTn.Tag = ent;
                //        parentTn.ImageIndex = 0;
                //        parentTn.SelectedImageIndex = 0;

                //        nodes.Add(parentTn);
                //        PopulateTree(tv, child.Entities, blocks, parentTn);
                //    }
                //}
                //else
            }
        }
Exemple #8
0
 public Vector2[] GetUVs(Direction dir) => BlockDictionary.GetBlockUVs(Type, dir);
Exemple #9
0
 public virtual Vector3[] GetVertices(Direction dir, Block neighbour)
 {
     return(BlockDictionary.GetDefaultVertices(dir));
 }
Exemple #10
0
 private void Awake()
 {
     instance = this;
     DontDestroyOnLoad(gameObject);
 }
    //! Called once per frame by unity engine.
    public void Update()
    {
        if (addedModBlocks == false)
        {
            if (ReadyToLoadModBlocks())
            {
                BlockDictionary blockDictionary = GetComponent <BuildController>().blockDictionary;
                blockDictionary.AddModBlocks(blockDictionary.blockDictionary);
                blockDictionary.AddModMachines(blockDictionary.machineDictionary);
                blockDictionary.AddModMeshes(blockDictionary.meshDictionary);
                addedModBlocks = true;
            }
        }

        // Get a refrence to the camera.
        if (mCam == null)
        {
            mCam = Camera.main;

            if (PlayerPrefs.GetFloat("FOV") != 0)
            {
                mCam.fieldOfView = PlayerPrefs.GetFloat("FOV");
            }

            if (PlayerPrefs.GetFloat("drawDistance") != 0)
            {
                mCam.farClipPlane = PlayerPrefs.GetFloat("drawDistance");
            }
        }
        else
        {
            // Disable mouse look during main menu sequence.
            gameObject.GetComponent <MSCameraController>().enabled &= gameStarted != false;

            // Get the spawn location, for respawning the player character.
            if (gotPosition == false)
            {
                originalPosition = transform.position;
                gotPosition      = true;
            }

            // The state manager has finished loading the world.
            if (stateManager.worldLoaded == true)
            {
                gameStarted = true;

                if (FileBasedPrefs.GetBool(stateManager.worldName + "oldWorld") == false)
                {
                    OpenTabletOnFirstLoad();
                }
                else if (movedPlayer == false)
                {
                    MovePlayerToSavedLocation();
                }

                if (ShouldShowTabletIntro())
                {
                    ShowTabletIntro();
                }

                if (checkedForCreativeMode == false && stateManager.worldLoaded == true)
                {
                    creativeMode = FileBasedPrefs.GetBool(stateManager.worldName + "creativeMode");
                    if (creativeMode == true)
                    {
                        Debug.Log("World [" + stateManager.worldName + "] running in creative mode.");
                    }
                    else
                    {
                        Debug.Log("World [" + stateManager.worldName + "] running in standard mode.");
                    }
                    checkedForCreativeMode = true;
                }

                // Destruction messages.
                if (destructionMessageActive == true)
                {
                    if (destructionMessageCount > 10)
                    {
                        currentTabletMessage    = "";
                        destructionMessageCount = 0;
                    }
                    if (destructionMessageReceived == false)
                    {
                        tablet.GetComponent <AudioSource>().Play();
                        destructionMessageReceived = true;
                    }
                }
                else
                {
                    destructionMessageCount    = 0;
                    destructionMessageReceived = false;
                }

                // Pirate attack warnings.
                if (pirateAttackWarningActive == true)
                {
                    currentTabletMessage = "Warning! Warning! Warning! Warning! Warning!\n\nIncoming pirate attack!";
                    if (pirateAttackWarningReceived == false)
                    {
                        tablet.GetComponent <AudioSource>().Play();
                        pirateAttackWarningReceived = true;
                    }
                }
                else
                {
                    pirateAttackWarningReceived = false;
                }

                // Meteor shower warnings.
                if (meteorShowerWarningActive == true)
                {
                    currentTabletMessage = "Warning! Warning! Warning! Warning! Warning!\n\nIncoming meteor shower!";
                    if (meteorShowerWarningReceived == false)
                    {
                        tablet.GetComponent <AudioSource>().Play();
                        meteorShowerWarningReceived = true;
                    }
                }
                else
                {
                    meteorShowerWarningReceived = false;
                }

                if (timeToDeliver == true)
                {
                    DisplayDeliveryWarning();
                }
                else
                {
                    timeToDeliverWarningRecieved = false;
                }

                if (destroying == true)
                {
                    ModifyCombinedMeshes();
                }

                if (requestedBuildingStop == true)
                {
                    HandleBuildingStopRequest();
                }

                // The player controller is notified that the game manager finished combining meshes.
                if (stoppingBuildCoRoutine == true && gameManager.working == false)
                {
                    stoppingBuildCoRoutine = false;
                }

                if (requestedChunkLoad == true)
                {
                    HandleChunkLoadRequest();
                }

                // Locking or unlocking the mouse cursor for GUI interaction.
                if (GuiOpen())
                {
                    Cursor.visible   = true;
                    Cursor.lockState = CursorLockMode.None;
                    gameObject.GetComponent <MSCameraController>().enabled = false;
                }
                else
                {
                    Cursor.visible   = false;
                    Cursor.lockState = CursorLockMode.Locked;
                    gameObject.GetComponent <MSCameraController>().enabled = true;
                }

                if (requestedSave == true)
                {
                    HandleSaveRequest();
                }

                if (storageInventory != null && storageGUIopen == true)
                {
                    CheckStorageDistance();
                }

                if (stateManager.saving == false)
                {
                    inputManager.HandleInput();
                    EnforceWorldLimits();
                }

                if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                {
                    networkController.NetworkFrame();

                    if (networkController.networkWorldUpdateCoroutineBusy == false)
                    {
                        networkWorldUpdateCoroutine = StartCoroutine(networkController.NetWorkWorldUpdate());
                    }
                }
            }
        }
    }
Exemple #12
0
    private IEnumerator PaintMesh(GameObject[] holders, string name)
    {
        playerController.machineGUIopen = false;
        BlockDictionary blockDictionary = new BlockDictionary(playerController);
        Color           color           = new Color(playerController.paintRed, playerController.paintGreen, playerController.paintBlue);

        foreach (GameObject holder in holders)
        {
            holder.GetComponent <Renderer>().material.color = color;
            FileBasedPrefs.SetBool(playerController.stateManager.worldName + name + holder.GetComponent <MeshPainter>().ID + "painted", true);
            yield return(null);
        }
        int interval = 0;

        if (name == "glassHolder")
        {
            Glass[] allGlassBlocks = Object.FindObjectsOfType <Glass>();
            foreach (Glass block in allGlassBlocks)
            {
                block.GetComponent <Renderer>().material.color = color;
                interval++;
                if (interval >= 500)
                {
                    interval = 0;
                    yield return(null);
                }
            }
        }
        if (name == "brickHolder")
        {
            Transform[] allBuiltObjects = playerController.gameManager.builtObjects.GetComponentsInChildren <Transform>(true);
            foreach (Transform block in allBuiltObjects)
            {
                if (block.GetComponent <Brick>() != null)
                {
                    block.GetComponent <Renderer>().material.color = color;
                    interval++;
                    if (interval >= 500)
                    {
                        interval = 0;
                        yield return(null);
                    }
                }
            }
        }
        if (name == "ironHolder")
        {
            Transform[] allBuiltObjects = playerController.gameManager.builtObjects.GetComponentsInChildren <Transform>(true);
            foreach (Transform block in allBuiltObjects)
            {
                if (block.GetComponent <IronBlock>() != null)
                {
                    block.GetComponent <Renderer>().material.color = color;
                    interval++;
                    if (interval >= 500)
                    {
                        interval = 0;
                        yield return(null);
                    }
                }
            }
        }
        if (name == "steelHolder")
        {
            Transform[] allBuiltObjects = playerController.gameManager.builtObjects.GetComponentsInChildren <Transform>(true);
            foreach (Transform block in allBuiltObjects)
            {
                if (block.GetComponent <Steel>() != null)
                {
                    block.GetComponent <Renderer>().material.color = color;
                    interval++;
                    if (interval >= 500)
                    {
                        interval = 0;
                        yield return(null);
                    }
                }
            }
        }
    }