effecient coding style question
Posted: 11 March 2013, 07:04
In order to support multiple board sizes with different artwork, I've had to replicate and rename
elements form the css, so for example I have "go_stnoe_19" "go_stone_13" "go_stone_9" Each of
these is a whole family of css elements, which isn't very elegant and also complicates the upstream
code because the names of the elements depend on their size even thought he logic is identical.
Q: is there a better coding style for this?
--
Slightly longer and more comlete example of what I mean, from the .css
Originally I had these, with embedded magic numbers corresponding to the
artwork files and sizes
.gmk_stone {
width: 30px;
height: 30px;
position: absolute;
background-image: url( '../../img/gomoku/stones.png');
}
.no_stone { background-position: -60px 0px; }
.stone_black { background-position: 0px 0px; }
.stone_white { background-position: -30px 0px; }
.clickable:hover { background-position: -90px 0px; }
Now, to support 3 sized os artwork I have
.go_intersection_19 {
width: 30px;
height: 30px;
position: relative;
background-image: url( '../../img/go/stones-19.png');
}
.go_stone_19 {
width: 30px;
height: 30px;
position: absolute;
background-image: url( '../../img/go/stones-19.png');
}
.no_stone_19 { background-position: -60px 0px; }
.stone_black_19 { background-position: 0px 0px; }
.stone_white_19 { background-position: -30px 0px; }
.clickable_19:hover { background-position: -90px 0px; }
.go_intersection_13 {
width: 42px;
height: 42px;
position: relative;
background-image: url( '../../img/go/stones-13.png');
}
.go_stone_13 {
width: 42px;
height: 42px;
position: absolute;
background-image: url( '../../img/go/stones-13.png');
}
.no_stone_13 { background-position: -84px 0px; }
.stone_black_13 { background-position: 0px 0px; }
.stone_white_13 { background-position: -42px 0px; }
.clickable_13:hover { background-position: -126px 0px; }
.go_intersection_9 {
width: 62px;
height: 62px;
position: relative;
background-image: url( '../../img/go/stones-9.png');
}
.go_stone_9 {
width: 62px;
height: 62px;
position: absolute;
background-image: url( '../../img/go/stones-9.png');
}
.no_stone_9 { background-position: -124px 0px; }
.stone_black_9 { background-position: 0px 0px; }
.stone_white_9 { background-position: -62px 0px; }
.clickable_9:hover { background-position: -186px 0px; }
elements form the css, so for example I have "go_stnoe_19" "go_stone_13" "go_stone_9" Each of
these is a whole family of css elements, which isn't very elegant and also complicates the upstream
code because the names of the elements depend on their size even thought he logic is identical.
Q: is there a better coding style for this?
--
Slightly longer and more comlete example of what I mean, from the .css
Originally I had these, with embedded magic numbers corresponding to the
artwork files and sizes
.gmk_stone {
width: 30px;
height: 30px;
position: absolute;
background-image: url( '../../img/gomoku/stones.png');
}
.no_stone { background-position: -60px 0px; }
.stone_black { background-position: 0px 0px; }
.stone_white { background-position: -30px 0px; }
.clickable:hover { background-position: -90px 0px; }
Now, to support 3 sized os artwork I have
.go_intersection_19 {
width: 30px;
height: 30px;
position: relative;
background-image: url( '../../img/go/stones-19.png');
}
.go_stone_19 {
width: 30px;
height: 30px;
position: absolute;
background-image: url( '../../img/go/stones-19.png');
}
.no_stone_19 { background-position: -60px 0px; }
.stone_black_19 { background-position: 0px 0px; }
.stone_white_19 { background-position: -30px 0px; }
.clickable_19:hover { background-position: -90px 0px; }
.go_intersection_13 {
width: 42px;
height: 42px;
position: relative;
background-image: url( '../../img/go/stones-13.png');
}
.go_stone_13 {
width: 42px;
height: 42px;
position: absolute;
background-image: url( '../../img/go/stones-13.png');
}
.no_stone_13 { background-position: -84px 0px; }
.stone_black_13 { background-position: 0px 0px; }
.stone_white_13 { background-position: -42px 0px; }
.clickable_13:hover { background-position: -126px 0px; }
.go_intersection_9 {
width: 62px;
height: 62px;
position: relative;
background-image: url( '../../img/go/stones-9.png');
}
.go_stone_9 {
width: 62px;
height: 62px;
position: absolute;
background-image: url( '../../img/go/stones-9.png');
}
.no_stone_9 { background-position: -124px 0px; }
.stone_black_9 { background-position: 0px 0px; }
.stone_white_9 { background-position: -62px 0px; }
.clickable_9:hover { background-position: -186px 0px; }