Skip to content

Commit

Permalink
added units
Browse files Browse the repository at this point in the history
  • Loading branch information
PodeCaradox committed Dec 3, 2023
1 parent cd90f2d commit 5b8fc28
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 80 deletions.
4 changes: 2 additions & 2 deletions src/assets/brushes/unit_brushes.data
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"Units_Test": {
"unit_test": {
"BrushEntities": [
{
"Name": "Castlekeep_gatecenter",
"RandomFactor": 1
}
],
"BrushType": "DynamicObjectBrush"
"BrushType": "EntitiesBrush"
}
}
69 changes: 69 additions & 0 deletions src/assets/game_ui/game_menu.interface
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@
"width": 48,
"height": 48
}
}, {
"EventType": "OpenSubMenu",
"EventName": "UnitsSubMenu",
"CollisionObject": {
"type": "CustomRectangle",
"Rectangle": {
"x": 0,
"y": 0,
"width": 48,
"height": 48
}
},
"Position": {
"x": -350,
"y": 2
},
"ImageSource": {
"x": 1148,
"y": 48,
"width": 48,
"height": 48
}
}
]
},
Expand Down Expand Up @@ -1056,6 +1078,53 @@
}
]
},
"UnitsSubMenu": {
"Alignment": "RightTop",
"MenuItems": [{
"CollisionObject": {
"type": "CustomRectangle",
"Rectangle": {
"x": 0,
"y": 0,
"width": 404,
"height": 90
}
},
"Position": {
"x": -404,
"y": 54
},
"ImageSource": {
"x": 1601,
"y": 54,
"width": 404,
"height": 90
}
}, {
"EventType": "SelectBrush",
"EventName": "unit_test",
"CollisionObject": {
"type": "CustomRectangle",
"Rectangle": {
"x": 0,
"y": 0,
"width": 32,
"height": 32
}
},
"Position": {
"x": -397,
"y": 56
},
"ImageSource": {
"x": 1196,
"y": 64,
"width": 32,
"height": 32
}
}
]
},
"FarmingSubMenu": {
"Alignment": "CenterBottom",
"Scale": {
Expand Down
64 changes: 50 additions & 14 deletions src/assets/images/images.data
Original file line number Diff line number Diff line change
@@ -1,42 +1,78 @@
{
"land":{
"Path":"images\\world\\terrain"
"Path":"images\\world\\terrain",
"DataType":"png",
"CsType":"environment"
},
"water":{
"Path":"images\\world\\terrain"
"Path":"images\\world\\terrain",
"DataType":"png",
"CsType":"environment"
},
"wall":{
"Path":"images\\world\\terrain"
"Path":"images\\world\\terrain",
"DataType":"png",
"CsType":"environment"
},
"land_elevation":{
"Path":"images\\world\\elevation"
"Path":"images\\world\\elevation",
"DataType":"png",
"CsType":"environment"
},
"wall_elevation":{
"Path":"images\\world\\elevation"
"Path":"images\\world\\elevation",
"DataType":"png",
"CsType":"environment"
},
"water_elevation":{
"Path":"images\\world\\elevation"
"Path":"images\\world\\elevation",
"DataType":"png",
"CsType":"environment"
},
"debug_tiles":{
"Path":"images\\world\\debugging"
"Path":"images\\world\\debugging",
"DataType":"png",
"CsType":"environment"
},
"tree":{
"Path":"images\\world\\objects\\trees"
"Path":"images\\world\\objects\\trees",
"DataType":"png",
"CsType":"environment"
},
"decorativ":{
"Path":"images\\world\\objects\\decorative"
"Path":"images\\world\\objects\\decorative",
"DataType":"png",
"CsType":"environment"
},
"objects_on_top":{
"Path":"images\\world\\buildings\\objects_on_top"
"Path":"images\\world\\buildings\\objects_on_top",
"DataType":"png",
"CsType":"environment"
},
"objects_tiled":{
"Path":"images\\world\\buildings\\objects_tiled"
"Path":"images\\world\\buildings\\objects_tiled",
"DataType":"png",
"CsType":"environment"
},
"arrow":{
"Path":"images\\units"
"Path":"images\\units",
"DataType":"png",
"CsType":"environment"
},
"world_effects":{
"Path":"images\\world\\effects"
}
"Path":"images\\world\\effects",
"DataType":"png",
"CsType":"environment"
},
"color_table_1":{
"Path":"images\\units",
"DataType":"png",
"CsType":"color_table"
},
"unit1":{
"Path":"images\\units",
"DataType":"positions",
"CsType":"position_table"
}
}

Binary file modified src/assets/images/ui/game_interface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/units/color_table_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/units/unit1.positions
Binary file not shown.
18 changes: 9 additions & 9 deletions src/assets/shaders/brush_world.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const ZStep : f32 = 0.0000001;
//4*4 = 16
struct SingleInstance
{
ImageIndex: u32,//image Index
image_index: u32,//image Index
Animation: u32,// 1 for Activated // 7 bits for animation length // 12 bits for when update animation // 12 pausing frames TODO
AtlasCoordPos: u32, //x/y for column/row z/w for image index
AtlasCoordSize: u32,
atlas_coord_size: u32,
};

//4 * 4 = 16 bytes
Expand All @@ -32,7 +32,7 @@ struct TileRotationData
struct InstancingObject
{
Position: vec3<f32>,
ImageIndex: u32,
image_index: u32,
UvCoordPos: vec2<f32>,
UvCoordSize: u32,
Color: u32,
Expand Down Expand Up @@ -183,7 +183,7 @@ fn is_in_map_bounds(map_position: vec2<i32>) -> i32 {

fn WorldPosToDepth(world_pos: vec2<i32>) -> f32{
let size: f32 = f32(params.map_size.x * params.map_size.y);
return 1.0f - f32(world_pos.y * params.map_size.x + world_pos.x) / size - ZStep;
return 1.0f - f32(world_pos.y * params.map_size.x + world_pos.x) / size;
}

fn WorldToScreenPos(world_pos: vec2<i32>) -> vec2<f32>{
Expand All @@ -196,7 +196,7 @@ fn WorldToScreenPos(world_pos: vec2<i32>) -> vec2<f32>{
fn initInstancingObject() -> InstancingObject {
var obj: InstancingObject;
obj.Position = vec3<f32>(0.0, 0.0, -10.0);
obj.ImageIndex = 0u;
obj.image_index = 0u;
obj.UvCoordPos = vec2<f32>(0.0, 0.0);
obj.UvCoordSize = 0u;
obj.Color = 0u;
Expand Down Expand Up @@ -229,7 +229,7 @@ fn CaclAnimationFrame(instance: SingleInstance, animation_enabled: u32, tick: u3
let reiteration = u32((instance.Animation >> 7u) & 0x0000001fu);
let pausing_frames = u32(instance.Animation & 0x0000007fu) * 2u;
let update_tick = u32((instance.Animation >> 12u) & 0x00000fffu);
let uv_size = vec2<u32>(instance.AtlasCoordSize & 0x0000ffffu, instance.AtlasCoordSize >> 16u);
let uv_size = vec2<u32>(instance.atlas_coord_size & 0x0000ffffu, instance.atlas_coord_size >> 16u);
let is_update_time = animation_tick / update_tick;
let animation_length_wih_reiterattions = animation_length + animation_length * reiteration;
let img_coord = is_update_time % (animation_length_wih_reiterattions + pausing_frames);
Expand All @@ -250,12 +250,12 @@ fn CreateObjectInstance(tile_id: u32, map_pos: vec2<i32>, position: vec3<f32>, a
var instance = tile_properties.properties[tile_id];
var newInstance: InstancingObject;
newInstance.Position = position;
newInstance.ImageIndex = instance.ImageIndex;
newInstance.image_index = instance.image_index;

var atlas_pos = CaclAnimationFrame(instance, animation_enabled, animation_tick, map_pos);

newInstance.UvCoordPos = vec2<f32>(f32(atlas_pos & 0x0000ffffu),f32(atlas_pos >> 16u)) / ImageSize;
newInstance.UvCoordSize = instance.AtlasCoordSize;
newInstance.UvCoordSize = instance.atlas_coord_size;
newInstance.Color = color;
return newInstance;
}
Expand Down Expand Up @@ -378,9 +378,9 @@ if (global_id.x >= brush_params.instances_to_draw) {

visble_tiles_cp.tiles[visible_index] = CreateSpecificInstance(brush_tile_rotation.SingleInstances[0u], index, elevation, animation_enabled, 0u, brush_tile_data.Color);
visble_tiles_cp.tiles[visible_index + 1u] = CreateSpecificInstance(brush_tile_rotation.SingleInstances[1u], index, elevation, animation_enabled, 0u, brush_tile_data.Color);
visble_tiles_cp.tiles[visible_index + 1u].Position.z -= ZStep * 2.0;
visble_tiles_cp.tiles[visible_index + 2u] = CreateBuildingInstance(brush_tile_rotation.SingleInstances[2u], index, elevation, animation_enabled, 0u, brush_tile_data.Color, offset_object_y);
visble_tiles_cp.tiles[visible_index + 3u] = CreateElevationInstance(brush_tile_rotation.SingleInstances[3u], index, elevation, animation_enabled, 0u, brush_tile_data.Color, offset_elevation_x);
visble_tiles_cp.tiles[visible_index + 3u].Position.z -= ZStep;

return;
}
Expand Down
Loading

0 comments on commit 5b8fc28

Please sign in to comment.