//
// Editor features to be added:
//
-// - [ ] Create new entity
+// - [x] Create new entity
// - [ ] Edit entity properties in UI
// - [ ] Serialize / Deserialize a scene
//
#local handle_placing_entities :: () {
if active_index < 0 do return;
+ mouse_pos := mouse_get_position_vector();
- if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) {
+ if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) && mouse_pos.x < ~~window_width - sidebar_width && mouse_pos.y > menubar_height {
entity_type := ^scene.entity_types.entries[active_index].value;
- printf("ADDING {}\n", entity_type);
- pos := mouse_get_position_vector();
- entity := entity_type.make(^scene); // scene->make(entity_type);
- entity.pos = pos;
+ entity := entity_type.create_default(^scene);
+ entity.pos = mouse_pos;
}
}
}
Entity_Info :: struct {
- make : (scene: ^Entity_Manager) -> ^Entity = null_proc;
+ create_default : (scene: ^Entity_Manager) -> ^Entity = null_proc;
update : (entity: ^Entity, dt: f32) -> void = null_proc;
draw : (entity: ^Entity) -> void = null_proc;
register :: entity_manager_register;
add :: entity_manager_add;
make :: entity_manager_make;
- make_old :: entity_manager_make_old;
update :: entity_manager_update;
draw :: entity_manager_draw;
get :: entity_manager_get;
info := Entity_Info.{};
- info.make = #solidify entity_manager_make { entity_type=entity_type };
+ info.create_default = #solidify entity_manager_create_default { entity_type=entity_type };
@CompilerFeatures // Maybe there should be data stored in the Type_Info_Struct about
// the functions/methods that are defined in the structs scope. I don't know if that
return entity.id;
}
-entity_manager_make :: (use this: ^Entity_Manager, $entity_type: type_expr) -> ^entity_type where IsEntity(^entity_type) {
+#local entity_manager_create_default :: (use this: ^Entity_Manager, $entity_type: type_expr) -> ^entity_type where IsEntity(^entity_type) {
entity := new(entity_type, allocator=entity_allocator);
entity_type.init(entity, entity_type.init_data.{});
this->add(entity);
return entity;
}
-entity_manager_make_old :: (use this: ^Entity_Manager, $entity_type: type_expr, data: entity_type.init_data = .{}) -> ^entity_type where IsEntity(^entity_type) {
+entity_manager_make :: (use this: ^Entity_Manager, $entity_type: type_expr, data: entity_type.init_data = .{}) -> ^entity_type where IsEntity(^entity_type) {
entity := new(entity_type, allocator=entity_allocator);
entity_type.init(entity, data);
this->add(entity);
#if DEBUG { debug_font = font_lookup(.{"./assets/fonts/calibri.ttf", 16}); }
scene = entity_manager_create();
- scene->make_old(Player, .{ pos = .{300, 300}, controls=player_1_controls });
- scene->make_old(Player, .{ pos = .{400, 300}, controls=player_2_controls, color=.{1,0,0} });
-
- scene->make_old(Wall, .{ .{100, 100}, .{400, 50} });
- // scene->make_old(Wall, .{ .{100, 100}, .{50, 400} });
- // scene->make_old(Wall, .{ .{450, 100}, .{50, 400} });
- // scene->make_old(Wall, .{ .{100, 450}, .{400, 50} });
-
- scene->make_old(Door, .{ .{150, 150}, .{50, 50} });
- scene->make_old(Door, .{ .{400, 150}, .{50, 50} });
- scene->make_old(Door, .{ .{400, 400}, .{50, 50} });
- scene->make_old(Door, .{ .{150, 400}, .{50, 50} });
-
- scene->make_old(Item, .{ pos=.{ 250, 250 }, color=.{1,0,0} });
- scene->make_old(Item, .{ pos=.{ 275, 250 }, color=.{0,1,0} });
- scene->make_old(Item, .{ pos=.{ 300, 250 }, color=.{0,0,1} });
+ scene->make(Player, .{ pos = .{300, 300}, controls=player_1_controls });
+ scene->make(Player, .{ pos = .{400, 300}, controls=player_2_controls, color=.{1,0,0} });
+
+ scene->make(Wall, .{ .{100, 100}, .{400, 50} });
+ // scene->make(Wall, .{ .{100, 100}, .{50, 400} });
+ // scene->make(Wall, .{ .{450, 100}, .{50, 400} });
+ // scene->make(Wall, .{ .{100, 450}, .{400, 50} });
+
+ scene->make(Door, .{ .{150, 150}, .{50, 50} });
+ scene->make(Door, .{ .{400, 150}, .{50, 50} });
+ scene->make(Door, .{ .{400, 400}, .{50, 50} });
+ scene->make(Door, .{ .{150, 400}, .{50, 50} });
+
+ scene->make(Item, .{ pos=.{ 250, 250 }, color=.{1,0,0} });
+ scene->make(Item, .{ pos=.{ 275, 250 }, color=.{0,1,0} });
+ scene->make(Item, .{ pos=.{ 300, 250 }, color=.{0,0,1} });
#if DEBUG {
println("Registered Entity types:");