]> git.lizzy.rs Git - dragonblocks-bedrock.git/blob - src/node.cpp
Some structure Changes
[dragonblocks-bedrock.git] / src / node.cpp
1 #include <string>
2 #include <stdlib.h>
3 #include <iostream>
4 #include "node.h"
5 #include "game.h"
6 #include "texture.h"
7 using namespace std;
8
9 int Node::count = 0;
10 Node *Node::list[MAXNODES];
11
12 Node::Node(string n, string t, bool h, bool s, bool tr){
13         if (Node::count >= MAXNODES)
14                 Game::log("Too many registered Nodes", ERROR);
15         else{
16                 name = n;
17                 id = Node::count;
18                 hidden = h;
19                 stable = s;
20                 Node::list[id] = this;
21                 texture = new Texture(t,tr);
22                 Node::count++;
23         }
24 }
25 Node *Node::getNodeById(int id){
26         if(id < count && id > -1)
27                 return list[id];
28         return list[0]; 
29 }
30 Node *Node::getNodeByName(string name){
31         for(int i = 0; i < count; i++){
32                 if(list[i]->name == name ){
33                         return list[i];
34                 }
35         }
36         Game::log("Node "+name+" not found", WARNING);  
37         return list[0];         
38 }       
39 bool Node::operator==(Node *node){
40         return id == node->id;
41 }
42 bool Node::operator==(string n){
43         return name == n;
44 }