aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.cpp')
-rw-r--r--src/world.cpp37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/world.cpp b/src/world.cpp
index 9e289ea..dc9f75b 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -2,7 +2,6 @@
* @file world.cpp
*
* Copyright (C) 2019 Belle-Isle, Andrew <drumsetmonkey@gmail.com>
- * Author: Belle-Isle, Andrew <drumsetmonkey@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,30 +22,37 @@
/*****************
* WORLD CLASS *
*****************/
-World::World(sol::object ref)
+World::World(sol::object param)
{
- if (ref.get_type() == sol::type::table) {
- sol::table tab = ref;
+ if (param.get_type() == sol::type::table) {
+ sol::table tab = param;
+
if (tab["Seed"] == sol::type::number) {
seed = tab["Seed"];
}
if (tab["Layers"] == sol::type::number) {
layers = tab["Layers"];
}
+ if (tab["Register"] == sol::type::function) {
+ registerMat = tab["Register"];
+ }
if (tab["Generate"] == sol::type::function) {
generate = tab["Generate"];
}
+
} else {
// TODO better logging
std::cerr << "World paramaters must be stored in a table" << std::endl;
}
+
+ registerMat(this);
generate(this);
}
void World::setData(unsigned int x,
unsigned int y,
unsigned int z,
- unsigned int d)
+ std::string d)
{
(void)x;
(void)y;
@@ -56,6 +62,27 @@ void World::setData(unsigned int x,
// TODO actually do stuff here
}
+void World::registerMaterial(std::string name, sol::object data)
+{
+ if (data.get_type() == sol::type::table) {
+ sol::table tab = data;
+
+ // Make sure this material has not been registered before
+ auto it = string_registry.find(name);
+ if (it == string_registry.end()) {
+ string_registry.emplace(name, registry.size());
+ registry.push_back(WorldMaterial(tab));
+ } else {
+ std::cerr << "Material: " << name
+ << " was already registered" << std::endl;
+ }
+
+ } else {
+ // TODO better logging
+ std::cerr << "Material registration must have a table" << std::endl;
+ }
+}
+
/******************
* WORLD SYSTEM *